app/testpmd: add VXLAN encap/decap
[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_PMD_SOFTNIC
73 #include <rte_eth_softnic.h>
74 #endif
75 #ifdef RTE_LIBRTE_BNXT_PMD
76 #include <rte_pmd_bnxt.h>
77 #endif
78 #include "testpmd.h"
79 #include "cmdline_mtr.h"
80 #include "cmdline_tm.h"
81 #include "bpf_cmd.h"
82
83 static struct cmdline *testpmd_cl;
84
85 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
86
87 /* *** Help command with introduction. *** */
88 struct cmd_help_brief_result {
89         cmdline_fixed_string_t help;
90 };
91
92 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
93                                   struct cmdline *cl,
94                                   __attribute__((unused)) void *data)
95 {
96         cmdline_printf(
97                 cl,
98                 "\n"
99                 "Help is available for the following sections:\n\n"
100                 "    help control    : Start and stop forwarding.\n"
101                 "    help display    : Displaying port, stats and config "
102                 "information.\n"
103                 "    help config     : Configuration information.\n"
104                 "    help ports      : Configuring ports.\n"
105                 "    help registers  : Reading and setting port registers.\n"
106                 "    help filters    : Filters configuration help.\n"
107                 "    help all        : All of the above sections.\n\n"
108         );
109
110 }
111
112 cmdline_parse_token_string_t cmd_help_brief_help =
113         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
114
115 cmdline_parse_inst_t cmd_help_brief = {
116         .f = cmd_help_brief_parsed,
117         .data = NULL,
118         .help_str = "help: Show help",
119         .tokens = {
120                 (void *)&cmd_help_brief_help,
121                 NULL,
122         },
123 };
124
125 /* *** Help command with help sections. *** */
126 struct cmd_help_long_result {
127         cmdline_fixed_string_t help;
128         cmdline_fixed_string_t section;
129 };
130
131 static void cmd_help_long_parsed(void *parsed_result,
132                                  struct cmdline *cl,
133                                  __attribute__((unused)) void *data)
134 {
135         int show_all = 0;
136         struct cmd_help_long_result *res = parsed_result;
137
138         if (!strcmp(res->section, "all"))
139                 show_all = 1;
140
141         if (show_all || !strcmp(res->section, "control")) {
142
143                 cmdline_printf(
144                         cl,
145                         "\n"
146                         "Control forwarding:\n"
147                         "-------------------\n\n"
148
149                         "start\n"
150                         "    Start packet forwarding with current configuration.\n\n"
151
152                         "start tx_first\n"
153                         "    Start packet forwarding with current config"
154                         " after sending one burst of packets.\n\n"
155
156                         "stop\n"
157                         "    Stop packet forwarding, and display accumulated"
158                         " statistics.\n\n"
159
160                         "quit\n"
161                         "    Quit to prompt.\n\n"
162                 );
163         }
164
165         if (show_all || !strcmp(res->section, "display")) {
166
167                 cmdline_printf(
168                         cl,
169                         "\n"
170                         "Display:\n"
171                         "--------\n\n"
172
173                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
174                         "    Display information for port_id, or all.\n\n"
175
176                         "show port X rss reta (size) (mask0,mask1,...)\n"
177                         "    Display the rss redirection table entry indicated"
178                         " by masks on port X. size is used to indicate the"
179                         " hardware supported reta size\n\n"
180
181                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
182                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
183                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
184                         "    Display the RSS hash functions and RSS hash key"
185                         " of port X\n\n"
186
187                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
188                         "    Clear information for port_id, or all.\n\n"
189
190                         "show (rxq|txq) info (port_id) (queue_id)\n"
191                         "    Display information for configured RX/TX queue.\n\n"
192
193                         "show config (rxtx|cores|fwd|txpkts)\n"
194                         "    Display the given configuration.\n\n"
195
196                         "read rxd (port_id) (queue_id) (rxd_id)\n"
197                         "    Display an RX descriptor of a port RX queue.\n\n"
198
199                         "read txd (port_id) (queue_id) (txd_id)\n"
200                         "    Display a TX descriptor of a port TX queue.\n\n"
201
202                         "ddp get list (port_id)\n"
203                         "    Get ddp profile info list\n\n"
204
205                         "ddp get info (profile_path)\n"
206                         "    Get ddp profile information.\n\n"
207
208                         "show vf stats (port_id) (vf_id)\n"
209                         "    Display a VF's statistics.\n\n"
210
211                         "clear vf stats (port_id) (vf_id)\n"
212                         "    Reset a VF's statistics.\n\n"
213
214                         "show port (port_id) pctype mapping\n"
215                         "    Get flow ptype to pctype mapping on a port\n\n"
216
217                         "show port meter stats (port_id) (meter_id) (clear)\n"
218                         "    Get meter stats on a port\n\n"
219                         "show port tm cap (port_id)\n"
220                         "       Display the port TM capability.\n\n"
221
222                         "show port tm level cap (port_id) (level_id)\n"
223                         "       Display the port TM hierarchical level capability.\n\n"
224
225                         "show port tm node cap (port_id) (node_id)\n"
226                         "       Display the port TM node capability.\n\n"
227
228                         "show port tm node type (port_id) (node_id)\n"
229                         "       Display the port TM node type.\n\n"
230
231                         "show port tm node stats (port_id) (node_id) (clear)\n"
232                         "       Display the port TM node stats.\n\n"
233
234                 );
235         }
236
237         if (show_all || !strcmp(res->section, "config")) {
238                 cmdline_printf(
239                         cl,
240                         "\n"
241                         "Configuration:\n"
242                         "--------------\n"
243                         "Configuration changes only become active when"
244                         " forwarding is started/restarted.\n\n"
245
246                         "set default\n"
247                         "    Reset forwarding to the default configuration.\n\n"
248
249                         "set verbose (level)\n"
250                         "    Set the debug verbosity level X.\n\n"
251
252                         "set log global|(type) (level)\n"
253                         "    Set the log level.\n\n"
254
255                         "set nbport (num)\n"
256                         "    Set number of ports.\n\n"
257
258                         "set nbcore (num)\n"
259                         "    Set number of cores.\n\n"
260
261                         "set coremask (mask)\n"
262                         "    Set the forwarding cores hexadecimal mask.\n\n"
263
264                         "set portmask (mask)\n"
265                         "    Set the forwarding ports hexadecimal mask.\n\n"
266
267                         "set burst (num)\n"
268                         "    Set number of packets per burst.\n\n"
269
270                         "set burst tx delay (microseconds) retry (num)\n"
271                         "    Set the transmit delay time and number of retries,"
272                         " effective when retry is enabled.\n\n"
273
274                         "set txpkts (x[,y]*)\n"
275                         "    Set the length of each segment of TXONLY"
276                         " and optionally CSUM packets.\n\n"
277
278                         "set txsplit (off|on|rand)\n"
279                         "    Set the split policy for the TX packets."
280                         " Right now only applicable for CSUM and TXONLY"
281                         " modes\n\n"
282
283                         "set corelist (x[,y]*)\n"
284                         "    Set the list of forwarding cores.\n\n"
285
286                         "set portlist (x[,y]*)\n"
287                         "    Set the list of forwarding ports.\n\n"
288
289                         "set tx loopback (port_id) (on|off)\n"
290                         "    Enable or disable tx loopback.\n\n"
291
292                         "set all queues drop (port_id) (on|off)\n"
293                         "    Set drop enable bit for all queues.\n\n"
294
295                         "set vf split drop (port_id) (vf_id) (on|off)\n"
296                         "    Set split drop enable bit for a VF from the PF.\n\n"
297
298                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299                         "    Set MAC antispoof for a VF from the PF.\n\n"
300
301                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302                         "    Enable MACsec offload.\n\n"
303
304                         "set macsec offload (port_id) off\n"
305                         "    Disable MACsec offload.\n\n"
306
307                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308                         "    Configure MACsec secure connection (SC).\n\n"
309
310                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311                         "    Configure MACsec secure association (SA).\n\n"
312
313                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
314                         "    Set VF broadcast for a VF from the PF.\n\n"
315
316                         "vlan set strip (on|off) (port_id)\n"
317                         "    Set the VLAN strip on a port.\n\n"
318
319                         "vlan set stripq (on|off) (port_id,queue_id)\n"
320                         "    Set the VLAN strip for a queue on a port.\n\n"
321
322                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324
325                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326                         "    Set VLAN insert for a VF from the PF.\n\n"
327
328                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329                         "    Set VLAN antispoof for a VF from the PF.\n\n"
330
331                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
332                         "    Set VLAN tag for a VF from the PF.\n\n"
333
334                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335                         "    Set a VF's max bandwidth(Mbps).\n\n"
336
337                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339
340                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342
343                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
344                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
345
346                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348
349                         "vlan set filter (on|off) (port_id)\n"
350                         "    Set the VLAN filter on a port.\n\n"
351
352                         "vlan set qinq (on|off) (port_id)\n"
353                         "    Set the VLAN QinQ (extended queue in queue)"
354                         " on a port.\n\n"
355
356                         "vlan set (inner|outer) tpid (value) (port_id)\n"
357                         "    Set the VLAN TPID for Packet Filtering on"
358                         " a port\n\n"
359
360                         "rx_vlan add (vlan_id|all) (port_id)\n"
361                         "    Add a vlan_id, or all identifiers, to the set"
362                         " of VLAN identifiers filtered by port_id.\n\n"
363
364                         "rx_vlan rm (vlan_id|all) (port_id)\n"
365                         "    Remove a vlan_id, or all identifiers, from the set"
366                         " of VLAN identifiers filtered by port_id.\n\n"
367
368                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369                         "    Add a vlan_id, to the set of VLAN identifiers"
370                         "filtered for VF(s) from port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373                         "    Remove a vlan_id, to the set of VLAN identifiers"
374                         "filtered for VF(s) from port_id.\n\n"
375
376                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379                         "   add a tunnel filter of a port.\n\n"
380
381                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384                         "   remove a tunnel filter of a port.\n\n"
385
386                         "rx_vxlan_port add (udp_port) (port_id)\n"
387                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
388
389                         "rx_vxlan_port rm (udp_port) (port_id)\n"
390                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
391
392                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
394                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395
396                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
397                         "    Set port based TX VLAN insertion.\n\n"
398
399                         "tx_vlan reset (port_id)\n"
400                         "    Disable hardware insertion of a VLAN header in"
401                         " packets sent on a port.\n\n"
402
403                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404                         "    Select hardware or software calculation of the"
405                         " checksum when transmitting a packet using the"
406                         " csum forward engine.\n"
407                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
408                         "    outer-ip concerns the outer IP layer in"
409                         " case the packet is recognized as a tunnel packet by"
410                         " the forward engine (vxlan, gre and ipip are supported)\n"
411                         "    Please check the NIC datasheet for HW limits.\n\n"
412
413                         "csum parse-tunnel (on|off) (tx_port_id)\n"
414                         "    If disabled, treat tunnel packets as non-tunneled"
415                         " packets (treat inner headers as payload). The port\n"
416                         "    argument is the port used for TX in csum forward"
417                         " engine.\n\n"
418
419                         "csum show (port_id)\n"
420                         "    Display tx checksum offload configuration\n\n"
421
422                         "tso set (segsize) (portid)\n"
423                         "    Enable TCP Segmentation Offload in csum forward"
424                         " engine.\n"
425                         "    Please check the NIC datasheet for HW limits.\n\n"
426
427                         "tso show (portid)"
428                         "    Display the status of TCP Segmentation Offload.\n\n"
429
430                         "set port (port_id) gro on|off\n"
431                         "    Enable or disable Generic Receive Offload in"
432                         " csum forwarding engine.\n\n"
433
434                         "show port (port_id) gro\n"
435                         "    Display GRO configuration.\n\n"
436
437                         "set gro flush (cycles)\n"
438                         "    Set the cycle to flush GROed packets from"
439                         " reassembly tables.\n\n"
440
441                         "set port (port_id) gso (on|off)"
442                         "    Enable or disable Generic Segmentation Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "set gso segsz (length)\n"
446                         "    Set max packet length for output GSO segments,"
447                         " including packet header and payload.\n\n"
448
449                         "show port (port_id) gso\n"
450                         "    Show GSO configuration.\n\n"
451
452                         "set fwd (%s)\n"
453                         "    Set packet forwarding mode.\n\n"
454
455                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456                         "    Add a MAC address on port_id.\n\n"
457
458                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459                         "    Remove a MAC address from port_id.\n\n"
460
461                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462                         "    Set the default MAC address for port_id.\n\n"
463
464                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465                         "    Add a MAC address for a VF on the port.\n\n"
466
467                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Set the MAC address for a VF from the PF.\n\n"
469
470                         "set eth-peer (port_id) (peer_addr)\n"
471                         "    set the peer address for certain port.\n\n"
472
473                         "set port (port_id) uta (mac_address|all) (on|off)\n"
474                         "    Add/Remove a or all unicast hash filter(s)"
475                         "from port X.\n\n"
476
477                         "set promisc (port_id|all) (on|off)\n"
478                         "    Set the promiscuous mode on port_id, or all.\n\n"
479
480                         "set allmulti (port_id|all) (on|off)\n"
481                         "    Set the allmulti mode on port_id, or all.\n\n"
482
483                         "set vf promisc (port_id) (vf_id) (on|off)\n"
484                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
485
486                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
487                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
488
489                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
490                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
491                         " (on|off) autoneg (on|off) (port_id)\n"
492                         "set flow_ctrl rx (on|off) (portid)\n"
493                         "set flow_ctrl tx (on|off) (portid)\n"
494                         "set flow_ctrl high_water (high_water) (portid)\n"
495                         "set flow_ctrl low_water (low_water) (portid)\n"
496                         "set flow_ctrl pause_time (pause_time) (portid)\n"
497                         "set flow_ctrl send_xon (send_xon) (portid)\n"
498                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
499                         "set flow_ctrl autoneg (on|off) (port_id)\n"
500                         "    Set the link flow control parameter on a port.\n\n"
501
502                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
503                         " (low_water) (pause_time) (priority) (port_id)\n"
504                         "    Set the priority flow control parameter on a"
505                         " port.\n\n"
506
507                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
508                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
509                         " queue on port.\n"
510                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
511                         " on port 0 to mapping 5.\n\n"
512
513                         "set xstats-hide-zero on|off\n"
514                         "    Set the option to hide the zero values"
515                         " for xstats display.\n"
516
517                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
518                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
519
520                         "set port (port_id) vf (vf_id) (mac_addr)"
521                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
522                         "   Add/Remove unicast or multicast MAC addr filter"
523                         " for a VF.\n\n"
524
525                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
526                         "|MPE) (on|off)\n"
527                         "    AUPE:accepts untagged VLAN;"
528                         "ROPE:accept unicast hash\n\n"
529                         "    BAM:accepts broadcast packets;"
530                         "MPE:accepts all multicast packets\n\n"
531                         "    Enable/Disable a VF receive mode of a port\n\n"
532
533                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
534                         "    Set rate limit for a queue of a port\n\n"
535
536                         "set port (port_id) vf (vf_id) rate (rate_num) "
537                         "queue_mask (queue_mask_value)\n"
538                         "    Set rate limit for queues in VF of a port\n\n"
539
540                         "set port (port_id) mirror-rule (rule_id)"
541                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
542                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
543                         "   Set pool or vlan type mirror rule on a port.\n"
544                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
545                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
546                         " to pool 0.\n\n"
547
548                         "set port (port_id) mirror-rule (rule_id)"
549                         " (uplink-mirror|downlink-mirror) dst-pool"
550                         " (pool_id) (on|off)\n"
551                         "   Set uplink or downlink type mirror rule on a port.\n"
552                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
553                         " 0 on' enable mirror income traffic to pool 0.\n\n"
554
555                         "reset port (port_id) mirror-rule (rule_id)\n"
556                         "   Reset a mirror rule.\n\n"
557
558                         "set flush_rx (on|off)\n"
559                         "   Flush (default) or don't flush RX streams before"
560                         " forwarding. Mainly used with PCAP drivers.\n\n"
561
562                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
563                         "   Set the bypass mode for the lowest port on bypass enabled"
564                         " NIC.\n\n"
565
566                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
567                         "mode (normal|bypass|isolate) (port_id)\n"
568                         "   Set the event required to initiate specified bypass mode for"
569                         " the lowest port on a bypass enabled NIC where:\n"
570                         "       timeout   = enable bypass after watchdog timeout.\n"
571                         "       os_on     = enable bypass when OS/board is powered on.\n"
572                         "       os_off    = enable bypass when OS/board is powered off.\n"
573                         "       power_on  = enable bypass when power supply is turned on.\n"
574                         "       power_off = enable bypass when power supply is turned off."
575                         "\n\n"
576
577                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
578                         "   Set the bypass watchdog timeout to 'n' seconds"
579                         " where 0 = instant.\n\n"
580
581                         "show bypass config (port_id)\n"
582                         "   Show the bypass configuration for a bypass enabled NIC"
583                         " using the lowest port on the NIC.\n\n"
584
585 #ifdef RTE_LIBRTE_PMD_BOND
586                         "create bonded device (mode) (socket)\n"
587                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
588
589                         "add bonding slave (slave_id) (port_id)\n"
590                         "       Add a slave device to a bonded device.\n\n"
591
592                         "remove bonding slave (slave_id) (port_id)\n"
593                         "       Remove a slave device from a bonded device.\n\n"
594
595                         "set bonding mode (value) (port_id)\n"
596                         "       Set the bonding mode on a bonded device.\n\n"
597
598                         "set bonding primary (slave_id) (port_id)\n"
599                         "       Set the primary slave for a bonded device.\n\n"
600
601                         "show bonding config (port_id)\n"
602                         "       Show the bonding config for port_id.\n\n"
603
604                         "set bonding mac_addr (port_id) (address)\n"
605                         "       Set the MAC address of a bonded device.\n\n"
606
607                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
608                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
609
610                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
611                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
612
613                         "set bonding mon_period (port_id) (value)\n"
614                         "       Set the bonding link status monitoring polling period in ms.\n\n"
615
616                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
617                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
618
619 #endif
620                         "set link-up port (port_id)\n"
621                         "       Set link up for a port.\n\n"
622
623                         "set link-down port (port_id)\n"
624                         "       Set link down for a port.\n\n"
625
626                         "E-tag set insertion on port-tag-id (value)"
627                         " port (port_id) vf (vf_id)\n"
628                         "    Enable E-tag insertion for a VF on a port\n\n"
629
630                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
631                         "    Disable E-tag insertion for a VF on a port\n\n"
632
633                         "E-tag set stripping (on|off) port (port_id)\n"
634                         "    Enable/disable E-tag stripping on a port\n\n"
635
636                         "E-tag set forwarding (on|off) port (port_id)\n"
637                         "    Enable/disable E-tag based forwarding"
638                         " on a port\n\n"
639
640                         "E-tag set filter add e-tag-id (value) dst-pool"
641                         " (pool_id) port (port_id)\n"
642                         "    Add an E-tag forwarding filter on a port\n\n"
643
644                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
645                         "    Delete an E-tag forwarding filter on a port\n\n"
646
647 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
648                         "set port tm hierarchy default (port_id)\n"
649                         "       Set default traffic Management hierarchy on a port\n\n"
650
651 #endif
652                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
653                         "    Load a profile package on a port\n\n"
654
655                         "ddp del (port_id) (backup_profile_path)\n"
656                         "    Delete a profile package from a port\n\n"
657
658                         "ptype mapping get (port_id) (valid_only)\n"
659                         "    Get ptype mapping on a port\n\n"
660
661                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
662                         "    Replace target with the pkt_type in ptype mapping\n\n"
663
664                         "ptype mapping reset (port_id)\n"
665                         "    Reset ptype mapping on a port\n\n"
666
667                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
668                         "    Update a ptype mapping item on a port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "queue_start_index (value) queue_num (value)\n"
672                         "    Set a queue region on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "flowtype (value)\n"
676                         "    Set a flowtype region index on a port\n\n"
677
678                         "set port (port_id) queue-region UP (value) region_id (value)\n"
679                         "    Set the mapping of User Priority to "
680                         "queue region on a port\n\n"
681
682                         "set port (port_id) queue-region flush (on|off)\n"
683                         "    flush all queue region related configuration\n\n"
684
685                         "show port meter cap (port_id)\n"
686                         "    Show port meter capability information\n\n"
687
688                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
689                         "    meter profile add - srtcm rfc 2697\n\n"
690
691                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
692                         "    meter profile add - trtcm rfc 2698\n\n"
693
694                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
695                         "    meter profile add - trtcm rfc 4115\n\n"
696
697                         "del port meter profile (port_id) (profile_id)\n"
698                         "    meter profile delete\n\n"
699
700                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
701                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
702                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
703                         "(dscp_tbl_entry63)]\n"
704                         "    meter create\n\n"
705
706                         "enable port meter (port_id) (mtr_id)\n"
707                         "    meter enable\n\n"
708
709                         "disable port meter (port_id) (mtr_id)\n"
710                         "    meter disable\n\n"
711
712                         "del port meter (port_id) (mtr_id)\n"
713                         "    meter delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
719                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
720                         "    update meter dscp table entries\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
723                         "(action0) [(action1) (action2)]\n"
724                         "    meter update policer action\n\n"
725
726                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
727                         "    meter update stats\n\n"
728
729                         "show port (port_id) queue-region\n"
730                         "    show all queue region related configuration info\n\n"
731
732                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
733                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
734                         "       Add port tm node private shaper profile.\n\n"
735
736                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
737                         "       Delete port tm node private shaper profile.\n\n"
738
739                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
740                         " (shaper_profile_id)\n"
741                         "       Add/update port tm node shared shaper.\n\n"
742
743                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
744                         "       Delete port tm node shared shaper.\n\n"
745
746                         "set port tm node shaper profile (port_id) (node_id)"
747                         " (shaper_profile_id)\n"
748                         "       Set port tm node shaper profile.\n\n"
749
750                         "add port tm node wred profile (port_id) (wred_profile_id)"
751                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
752                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
753                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
754                         "       Add port tm node wred profile.\n\n"
755
756                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
757                         "       Delete port tm node wred profile.\n\n"
758
759                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
760                         " (priority) (weight) (level_id) (shaper_profile_id)"
761                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
762                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
763                         "       Add port tm nonleaf node.\n\n"
764
765                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
766                         " (priority) (weight) (level_id) (shaper_profile_id)"
767                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
768                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
769                         "       Add port tm leaf node.\n\n"
770
771                         "del port tm node (port_id) (node_id)\n"
772                         "       Delete port tm node.\n\n"
773
774                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
775                         " (priority) (weight)\n"
776                         "       Set port tm node parent.\n\n"
777
778                         "suspend port tm node (port_id) (node_id)"
779                         "       Suspend tm node.\n\n"
780
781                         "resume port tm node (port_id) (node_id)"
782                         "       Resume tm node.\n\n"
783
784                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
785                         "       Commit tm hierarchy.\n\n"
786
787                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
788                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
789                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
790                         "       Configure the VXLAN encapsulation for flows.\n\n"
791
792                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
793                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
794                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
795                         " eth-dst (eth-dst)\n"
796                         "       Configure the VXLAN encapsulation for flows.\n\n"
797
798                         , list_pkt_forwarding_modes()
799                 );
800         }
801
802         if (show_all || !strcmp(res->section, "ports")) {
803
804                 cmdline_printf(
805                         cl,
806                         "\n"
807                         "Port Operations:\n"
808                         "----------------\n\n"
809
810                         "port start (port_id|all)\n"
811                         "    Start all ports or port_id.\n\n"
812
813                         "port stop (port_id|all)\n"
814                         "    Stop all ports or port_id.\n\n"
815
816                         "port close (port_id|all)\n"
817                         "    Close all ports or port_id.\n\n"
818
819                         "port attach (ident)\n"
820                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
821
822                         "port detach (port_id)\n"
823                         "    Detach physical or virtual dev by port_id\n\n"
824
825                         "port config (port_id|all)"
826                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
827                         " duplex (half|full|auto)\n"
828                         "    Set speed and duplex for all ports or port_id\n\n"
829
830                         "port config (port_id|all) loopback (mode)\n"
831                         "    Set loopback mode for all ports or port_id\n\n"
832
833                         "port config all (rxq|txq|rxd|txd) (value)\n"
834                         "    Set number for rxq/txq/rxd/txd.\n\n"
835
836                         "port config all max-pkt-len (value)\n"
837                         "    Set the max packet length.\n\n"
838
839                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
840                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
841                         " (on|off)\n"
842                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
843                         " for ports.\n\n"
844
845                         "port config all rss (all|default|ip|tcp|udp|sctp|"
846                         "ether|port|vxlan|geneve|nvgre|none|<flowtype_id>)\n"
847                         "    Set the RSS mode.\n\n"
848
849                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
850                         "    Set the RSS redirection table.\n\n"
851
852                         "port config (port_id) dcb vt (on|off) (traffic_class)"
853                         " pfc (on|off)\n"
854                         "    Set the DCB mode.\n\n"
855
856                         "port config all burst (value)\n"
857                         "    Set the number of packets per burst.\n\n"
858
859                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
860                         " (value)\n"
861                         "    Set the ring prefetch/host/writeback threshold"
862                         " for tx/rx queue.\n\n"
863
864                         "port config all (txfreet|txrst|rxfreet) (value)\n"
865                         "    Set free threshold for rx/tx, or set"
866                         " tx rs bit threshold.\n\n"
867                         "port config mtu X value\n"
868                         "    Set the MTU of port X to a given value\n\n"
869
870                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
871                         "    Set a rx/tx queue's ring size configuration, the new"
872                         " value will take effect after command that (re-)start the port"
873                         " or command that setup the specific queue\n\n"
874
875                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
876                         "    Start/stop a rx/tx queue of port X. Only take effect"
877                         " when port X is started\n\n"
878
879                         "port (port_id) (rxq|txq) (queue_id) setup\n"
880                         "    Setup a rx/tx queue of port X.\n\n"
881
882                         "port config (port_id|all) l2-tunnel E-tag ether-type"
883                         " (value)\n"
884                         "    Set the value of E-tag ether-type.\n\n"
885
886                         "port config (port_id|all) l2-tunnel E-tag"
887                         " (enable|disable)\n"
888                         "    Enable/disable the E-tag support.\n\n"
889
890                         "port config (port_id) pctype mapping reset\n"
891                         "    Reset flow type to pctype mapping on a port\n\n"
892
893                         "port config (port_id) pctype mapping update"
894                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
895                         "    Update a flow type to pctype mapping item on a port\n\n"
896
897                         "port config (port_id) pctype (pctype_id) hash_inset|"
898                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
899                         " (field_idx)\n"
900                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
901
902                         "port config (port_id) pctype (pctype_id) hash_inset|"
903                         "fdir_inset|fdir_flx_inset clear all"
904                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
905
906                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
907                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
908                 );
909         }
910
911         if (show_all || !strcmp(res->section, "registers")) {
912
913                 cmdline_printf(
914                         cl,
915                         "\n"
916                         "Registers:\n"
917                         "----------\n\n"
918
919                         "read reg (port_id) (address)\n"
920                         "    Display value of a port register.\n\n"
921
922                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
923                         "    Display a port register bit field.\n\n"
924
925                         "read regbit (port_id) (address) (bit_x)\n"
926                         "    Display a single port register bit.\n\n"
927
928                         "write reg (port_id) (address) (value)\n"
929                         "    Set value of a port register.\n\n"
930
931                         "write regfield (port_id) (address) (bit_x) (bit_y)"
932                         " (value)\n"
933                         "    Set bit field of a port register.\n\n"
934
935                         "write regbit (port_id) (address) (bit_x) (value)\n"
936                         "    Set single bit value of a port register.\n\n"
937                 );
938         }
939         if (show_all || !strcmp(res->section, "filters")) {
940
941                 cmdline_printf(
942                         cl,
943                         "\n"
944                         "filters:\n"
945                         "--------\n\n"
946
947                         "ethertype_filter (port_id) (add|del)"
948                         " (mac_addr|mac_ignr) (mac_address) ethertype"
949                         " (ether_type) (drop|fwd) queue (queue_id)\n"
950                         "    Add/Del an ethertype filter.\n\n"
951
952                         "2tuple_filter (port_id) (add|del)"
953                         " dst_port (dst_port_value) protocol (protocol_value)"
954                         " mask (mask_value) tcp_flags (tcp_flags_value)"
955                         " priority (prio_value) queue (queue_id)\n"
956                         "    Add/Del a 2tuple filter.\n\n"
957
958                         "5tuple_filter (port_id) (add|del)"
959                         " dst_ip (dst_address) src_ip (src_address)"
960                         " dst_port (dst_port_value) src_port (src_port_value)"
961                         " protocol (protocol_value)"
962                         " mask (mask_value) tcp_flags (tcp_flags_value)"
963                         " priority (prio_value) queue (queue_id)\n"
964                         "    Add/Del a 5tuple filter.\n\n"
965
966                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
967                         "    Add/Del syn filter.\n\n"
968
969                         "flex_filter (port_id) (add|del) len (len_value)"
970                         " bytes (bytes_value) mask (mask_value)"
971                         " priority (prio_value) queue (queue_id)\n"
972                         "    Add/Del a flex filter.\n\n"
973
974                         "flow_director_filter (port_id) mode IP (add|del|update)"
975                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
976                         " src (src_ip_address) dst (dst_ip_address)"
977                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
978                         " vlan (vlan_value) flexbytes (flexbytes_value)"
979                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
980                         " fd_id (fd_id_value)\n"
981                         "    Add/Del an IP type flow director filter.\n\n"
982
983                         "flow_director_filter (port_id) mode IP (add|del|update)"
984                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
985                         " src (src_ip_address) (src_port)"
986                         " dst (dst_ip_address) (dst_port)"
987                         " tos (tos_value) ttl (ttl_value)"
988                         " vlan (vlan_value) flexbytes (flexbytes_value)"
989                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
990                         " fd_id (fd_id_value)\n"
991                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
992
993                         "flow_director_filter (port_id) mode IP (add|del|update)"
994                         " flow (ipv4-sctp|ipv6-sctp)"
995                         " src (src_ip_address) (src_port)"
996                         " dst (dst_ip_address) (dst_port)"
997                         " tag (verification_tag) "
998                         " tos (tos_value) ttl (ttl_value)"
999                         " vlan (vlan_value)"
1000                         " flexbytes (flexbytes_value) (drop|fwd)"
1001                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1002                         "    Add/Del a SCTP type flow director filter.\n\n"
1003
1004                         "flow_director_filter (port_id) mode IP (add|del|update)"
1005                         " flow l2_payload ether (ethertype)"
1006                         " flexbytes (flexbytes_value) (drop|fwd)"
1007                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1008                         "    Add/Del a l2 payload type flow director filter.\n\n"
1009
1010                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1011                         " mac (mac_address) vlan (vlan_value)"
1012                         " flexbytes (flexbytes_value) (drop|fwd)"
1013                         " queue (queue_id) fd_id (fd_id_value)\n"
1014                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1015
1016                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1017                         " mac (mac_address) vlan (vlan_value)"
1018                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1019                         " flexbytes (flexbytes_value) (drop|fwd)"
1020                         " queue (queue_id) fd_id (fd_id_value)\n"
1021                         "    Add/Del a Tunnel flow director filter.\n\n"
1022
1023                         "flow_director_filter (port_id) mode raw (add|del|update)"
1024                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1025                         " fd_id (fd_id_value) packet (packet file name)\n"
1026                         "    Add/Del a raw type flow director filter.\n\n"
1027
1028                         "flush_flow_director (port_id)\n"
1029                         "    Flush all flow director entries of a device.\n\n"
1030
1031                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1032                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1033                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1034                         "    Set flow director IP mask.\n\n"
1035
1036                         "flow_director_mask (port_id) mode MAC-VLAN"
1037                         " vlan (vlan_value)\n"
1038                         "    Set flow director MAC-VLAN mask.\n\n"
1039
1040                         "flow_director_mask (port_id) mode Tunnel"
1041                         " vlan (vlan_value) mac (mac_value)"
1042                         " tunnel-type (tunnel_type_value)"
1043                         " tunnel-id (tunnel_id_value)\n"
1044                         "    Set flow director Tunnel mask.\n\n"
1045
1046                         "flow_director_flex_mask (port_id)"
1047                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1048                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1049                         " (mask)\n"
1050                         "    Configure mask of flex payload.\n\n"
1051
1052                         "flow_director_flex_payload (port_id)"
1053                         " (raw|l2|l3|l4) (config)\n"
1054                         "    Configure flex payload selection.\n\n"
1055
1056                         "get_sym_hash_ena_per_port (port_id)\n"
1057                         "    get symmetric hash enable configuration per port.\n\n"
1058
1059                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1060                         "    set symmetric hash enable configuration per port"
1061                         " to enable or disable.\n\n"
1062
1063                         "get_hash_global_config (port_id)\n"
1064                         "    Get the global configurations of hash filters.\n\n"
1065
1066                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1067                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1068                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1069                         " (enable|disable)\n"
1070                         "    Set the global configurations of hash filters.\n\n"
1071
1072                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1073                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1074                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1075                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1076                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1077                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1078                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1079                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1080                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1081                         "fld-8th|none) (select|add)\n"
1082                         "    Set the input set for hash.\n\n"
1083
1084                         "set_fdir_input_set (port_id) "
1085                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1086                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1087                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1088                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1089                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1090                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1091                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1092                         " (select|add)\n"
1093                         "    Set the input set for FDir.\n\n"
1094
1095                         "flow validate {port_id}"
1096                         " [group {group_id}] [priority {level}]"
1097                         " [ingress] [egress]"
1098                         " pattern {item} [/ {item} [...]] / end"
1099                         " actions {action} [/ {action} [...]] / end\n"
1100                         "    Check whether a flow rule can be created.\n\n"
1101
1102                         "flow create {port_id}"
1103                         " [group {group_id}] [priority {level}]"
1104                         " [ingress] [egress]"
1105                         " pattern {item} [/ {item} [...]] / end"
1106                         " actions {action} [/ {action} [...]] / end\n"
1107                         "    Create a flow rule.\n\n"
1108
1109                         "flow destroy {port_id} rule {rule_id} [...]\n"
1110                         "    Destroy specific flow rules.\n\n"
1111
1112                         "flow flush {port_id}\n"
1113                         "    Destroy all flow rules.\n\n"
1114
1115                         "flow query {port_id} {rule_id} {action}\n"
1116                         "    Query an existing flow rule.\n\n"
1117
1118                         "flow list {port_id} [group {group_id}] [...]\n"
1119                         "    List existing flow rules sorted by priority,"
1120                         " filtered by group identifiers.\n\n"
1121
1122                         "flow isolate {port_id} {boolean}\n"
1123                         "    Restrict ingress traffic to the defined"
1124                         " flow rules\n\n"
1125                 );
1126         }
1127 }
1128
1129 cmdline_parse_token_string_t cmd_help_long_help =
1130         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1131
1132 cmdline_parse_token_string_t cmd_help_long_section =
1133         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1134                         "all#control#display#config#"
1135                         "ports#registers#filters");
1136
1137 cmdline_parse_inst_t cmd_help_long = {
1138         .f = cmd_help_long_parsed,
1139         .data = NULL,
1140         .help_str = "help all|control|display|config|ports|register|filters: "
1141                 "Show help",
1142         .tokens = {
1143                 (void *)&cmd_help_long_help,
1144                 (void *)&cmd_help_long_section,
1145                 NULL,
1146         },
1147 };
1148
1149
1150 /* *** start/stop/close all ports *** */
1151 struct cmd_operate_port_result {
1152         cmdline_fixed_string_t keyword;
1153         cmdline_fixed_string_t name;
1154         cmdline_fixed_string_t value;
1155 };
1156
1157 static void cmd_operate_port_parsed(void *parsed_result,
1158                                 __attribute__((unused)) struct cmdline *cl,
1159                                 __attribute__((unused)) void *data)
1160 {
1161         struct cmd_operate_port_result *res = parsed_result;
1162
1163         if (!strcmp(res->name, "start"))
1164                 start_port(RTE_PORT_ALL);
1165         else if (!strcmp(res->name, "stop"))
1166                 stop_port(RTE_PORT_ALL);
1167         else if (!strcmp(res->name, "close"))
1168                 close_port(RTE_PORT_ALL);
1169         else if (!strcmp(res->name, "reset"))
1170                 reset_port(RTE_PORT_ALL);
1171         else
1172                 printf("Unknown parameter\n");
1173 }
1174
1175 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1176         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1177                                                                 "port");
1178 cmdline_parse_token_string_t cmd_operate_port_all_port =
1179         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1180                                                 "start#stop#close#reset");
1181 cmdline_parse_token_string_t cmd_operate_port_all_all =
1182         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1183
1184 cmdline_parse_inst_t cmd_operate_port = {
1185         .f = cmd_operate_port_parsed,
1186         .data = NULL,
1187         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1188         .tokens = {
1189                 (void *)&cmd_operate_port_all_cmd,
1190                 (void *)&cmd_operate_port_all_port,
1191                 (void *)&cmd_operate_port_all_all,
1192                 NULL,
1193         },
1194 };
1195
1196 /* *** start/stop/close specific port *** */
1197 struct cmd_operate_specific_port_result {
1198         cmdline_fixed_string_t keyword;
1199         cmdline_fixed_string_t name;
1200         uint8_t value;
1201 };
1202
1203 static void cmd_operate_specific_port_parsed(void *parsed_result,
1204                         __attribute__((unused)) struct cmdline *cl,
1205                                 __attribute__((unused)) void *data)
1206 {
1207         struct cmd_operate_specific_port_result *res = parsed_result;
1208
1209         if (!strcmp(res->name, "start"))
1210                 start_port(res->value);
1211         else if (!strcmp(res->name, "stop"))
1212                 stop_port(res->value);
1213         else if (!strcmp(res->name, "close"))
1214                 close_port(res->value);
1215         else if (!strcmp(res->name, "reset"))
1216                 reset_port(res->value);
1217         else
1218                 printf("Unknown parameter\n");
1219 }
1220
1221 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1222         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1223                                                         keyword, "port");
1224 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1225         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1226                                                 name, "start#stop#close#reset");
1227 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1228         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1229                                                         value, UINT8);
1230
1231 cmdline_parse_inst_t cmd_operate_specific_port = {
1232         .f = cmd_operate_specific_port_parsed,
1233         .data = NULL,
1234         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1235         .tokens = {
1236                 (void *)&cmd_operate_specific_port_cmd,
1237                 (void *)&cmd_operate_specific_port_port,
1238                 (void *)&cmd_operate_specific_port_id,
1239                 NULL,
1240         },
1241 };
1242
1243 /* *** attach a specified port *** */
1244 struct cmd_operate_attach_port_result {
1245         cmdline_fixed_string_t port;
1246         cmdline_fixed_string_t keyword;
1247         cmdline_fixed_string_t identifier;
1248 };
1249
1250 static void cmd_operate_attach_port_parsed(void *parsed_result,
1251                                 __attribute__((unused)) struct cmdline *cl,
1252                                 __attribute__((unused)) void *data)
1253 {
1254         struct cmd_operate_attach_port_result *res = parsed_result;
1255
1256         if (!strcmp(res->keyword, "attach"))
1257                 attach_port(res->identifier);
1258         else
1259                 printf("Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1264                         port, "port");
1265 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1267                         keyword, "attach");
1268 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1269         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1270                         identifier, NULL);
1271
1272 cmdline_parse_inst_t cmd_operate_attach_port = {
1273         .f = cmd_operate_attach_port_parsed,
1274         .data = NULL,
1275         .help_str = "port attach <identifier>: "
1276                 "(identifier: pci address or virtual dev name)",
1277         .tokens = {
1278                 (void *)&cmd_operate_attach_port_port,
1279                 (void *)&cmd_operate_attach_port_keyword,
1280                 (void *)&cmd_operate_attach_port_identifier,
1281                 NULL,
1282         },
1283 };
1284
1285 /* *** detach a specified port *** */
1286 struct cmd_operate_detach_port_result {
1287         cmdline_fixed_string_t port;
1288         cmdline_fixed_string_t keyword;
1289         portid_t port_id;
1290 };
1291
1292 static void cmd_operate_detach_port_parsed(void *parsed_result,
1293                                 __attribute__((unused)) struct cmdline *cl,
1294                                 __attribute__((unused)) void *data)
1295 {
1296         struct cmd_operate_detach_port_result *res = parsed_result;
1297
1298         if (!strcmp(res->keyword, "detach"))
1299                 detach_port(res->port_id);
1300         else
1301                 printf("Unknown parameter\n");
1302 }
1303
1304 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1305         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1306                         port, "port");
1307 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1308         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1309                         keyword, "detach");
1310 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1311         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1312                         port_id, UINT16);
1313
1314 cmdline_parse_inst_t cmd_operate_detach_port = {
1315         .f = cmd_operate_detach_port_parsed,
1316         .data = NULL,
1317         .help_str = "port detach <port_id>",
1318         .tokens = {
1319                 (void *)&cmd_operate_detach_port_port,
1320                 (void *)&cmd_operate_detach_port_keyword,
1321                 (void *)&cmd_operate_detach_port_port_id,
1322                 NULL,
1323         },
1324 };
1325
1326 /* *** configure speed for all ports *** */
1327 struct cmd_config_speed_all {
1328         cmdline_fixed_string_t port;
1329         cmdline_fixed_string_t keyword;
1330         cmdline_fixed_string_t all;
1331         cmdline_fixed_string_t item1;
1332         cmdline_fixed_string_t item2;
1333         cmdline_fixed_string_t value1;
1334         cmdline_fixed_string_t value2;
1335 };
1336
1337 static int
1338 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1339 {
1340
1341         int duplex;
1342
1343         if (!strcmp(duplexstr, "half")) {
1344                 duplex = ETH_LINK_HALF_DUPLEX;
1345         } else if (!strcmp(duplexstr, "full")) {
1346                 duplex = ETH_LINK_FULL_DUPLEX;
1347         } else if (!strcmp(duplexstr, "auto")) {
1348                 duplex = ETH_LINK_FULL_DUPLEX;
1349         } else {
1350                 printf("Unknown duplex parameter\n");
1351                 return -1;
1352         }
1353
1354         if (!strcmp(speedstr, "10")) {
1355                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1356                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1357         } else if (!strcmp(speedstr, "100")) {
1358                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1359                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1360         } else {
1361                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1362                         printf("Invalid speed/duplex parameters\n");
1363                         return -1;
1364                 }
1365                 if (!strcmp(speedstr, "1000")) {
1366                         *speed = ETH_LINK_SPEED_1G;
1367                 } else if (!strcmp(speedstr, "10000")) {
1368                         *speed = ETH_LINK_SPEED_10G;
1369                 } else if (!strcmp(speedstr, "25000")) {
1370                         *speed = ETH_LINK_SPEED_25G;
1371                 } else if (!strcmp(speedstr, "40000")) {
1372                         *speed = ETH_LINK_SPEED_40G;
1373                 } else if (!strcmp(speedstr, "50000")) {
1374                         *speed = ETH_LINK_SPEED_50G;
1375                 } else if (!strcmp(speedstr, "100000")) {
1376                         *speed = ETH_LINK_SPEED_100G;
1377                 } else if (!strcmp(speedstr, "auto")) {
1378                         *speed = ETH_LINK_SPEED_AUTONEG;
1379                 } else {
1380                         printf("Unknown speed parameter\n");
1381                         return -1;
1382                 }
1383         }
1384
1385         return 0;
1386 }
1387
1388 static void
1389 cmd_config_speed_all_parsed(void *parsed_result,
1390                         __attribute__((unused)) struct cmdline *cl,
1391                         __attribute__((unused)) void *data)
1392 {
1393         struct cmd_config_speed_all *res = parsed_result;
1394         uint32_t link_speed;
1395         portid_t pid;
1396
1397         if (!all_ports_stopped()) {
1398                 printf("Please stop all ports first\n");
1399                 return;
1400         }
1401
1402         if (parse_and_check_speed_duplex(res->value1, res->value2,
1403                         &link_speed) < 0)
1404                 return;
1405
1406         RTE_ETH_FOREACH_DEV(pid) {
1407                 ports[pid].dev_conf.link_speeds = link_speed;
1408         }
1409
1410         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1411 }
1412
1413 cmdline_parse_token_string_t cmd_config_speed_all_port =
1414         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1415 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1416         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1417                                                         "config");
1418 cmdline_parse_token_string_t cmd_config_speed_all_all =
1419         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1420 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1421         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1422 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1423         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1424                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1425 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1426         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1427 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1428         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1429                                                 "half#full#auto");
1430
1431 cmdline_parse_inst_t cmd_config_speed_all = {
1432         .f = cmd_config_speed_all_parsed,
1433         .data = NULL,
1434         .help_str = "port config all speed "
1435                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1436                                                         "half|full|auto",
1437         .tokens = {
1438                 (void *)&cmd_config_speed_all_port,
1439                 (void *)&cmd_config_speed_all_keyword,
1440                 (void *)&cmd_config_speed_all_all,
1441                 (void *)&cmd_config_speed_all_item1,
1442                 (void *)&cmd_config_speed_all_value1,
1443                 (void *)&cmd_config_speed_all_item2,
1444                 (void *)&cmd_config_speed_all_value2,
1445                 NULL,
1446         },
1447 };
1448
1449 /* *** configure speed for specific port *** */
1450 struct cmd_config_speed_specific {
1451         cmdline_fixed_string_t port;
1452         cmdline_fixed_string_t keyword;
1453         portid_t id;
1454         cmdline_fixed_string_t item1;
1455         cmdline_fixed_string_t item2;
1456         cmdline_fixed_string_t value1;
1457         cmdline_fixed_string_t value2;
1458 };
1459
1460 static void
1461 cmd_config_speed_specific_parsed(void *parsed_result,
1462                                 __attribute__((unused)) struct cmdline *cl,
1463                                 __attribute__((unused)) void *data)
1464 {
1465         struct cmd_config_speed_specific *res = parsed_result;
1466         uint32_t link_speed;
1467
1468         if (!all_ports_stopped()) {
1469                 printf("Please stop all ports first\n");
1470                 return;
1471         }
1472
1473         if (port_id_is_invalid(res->id, ENABLED_WARN))
1474                 return;
1475
1476         if (parse_and_check_speed_duplex(res->value1, res->value2,
1477                         &link_speed) < 0)
1478                 return;
1479
1480         ports[res->id].dev_conf.link_speeds = link_speed;
1481
1482         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1483 }
1484
1485
1486 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1487         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1488                                                                 "port");
1489 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1490         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1491                                                                 "config");
1492 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1493         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1494 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1495         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1496                                                                 "speed");
1497 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1498         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1499                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1500 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1501         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1502                                                                 "duplex");
1503 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1504         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1505                                                         "half#full#auto");
1506
1507 cmdline_parse_inst_t cmd_config_speed_specific = {
1508         .f = cmd_config_speed_specific_parsed,
1509         .data = NULL,
1510         .help_str = "port config <port_id> speed "
1511                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1512                                                         "half|full|auto",
1513         .tokens = {
1514                 (void *)&cmd_config_speed_specific_port,
1515                 (void *)&cmd_config_speed_specific_keyword,
1516                 (void *)&cmd_config_speed_specific_id,
1517                 (void *)&cmd_config_speed_specific_item1,
1518                 (void *)&cmd_config_speed_specific_value1,
1519                 (void *)&cmd_config_speed_specific_item2,
1520                 (void *)&cmd_config_speed_specific_value2,
1521                 NULL,
1522         },
1523 };
1524
1525 /* *** configure loopback for all ports *** */
1526 struct cmd_config_loopback_all {
1527         cmdline_fixed_string_t port;
1528         cmdline_fixed_string_t keyword;
1529         cmdline_fixed_string_t all;
1530         cmdline_fixed_string_t item;
1531         uint32_t mode;
1532 };
1533
1534 static void
1535 cmd_config_loopback_all_parsed(void *parsed_result,
1536                         __attribute__((unused)) struct cmdline *cl,
1537                         __attribute__((unused)) void *data)
1538 {
1539         struct cmd_config_loopback_all *res = parsed_result;
1540         portid_t pid;
1541
1542         if (!all_ports_stopped()) {
1543                 printf("Please stop all ports first\n");
1544                 return;
1545         }
1546
1547         RTE_ETH_FOREACH_DEV(pid) {
1548                 ports[pid].dev_conf.lpbk_mode = res->mode;
1549         }
1550
1551         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1552 }
1553
1554 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1556 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1558                                                         "config");
1559 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1561 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1563                                                         "loopback");
1564 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1565         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1566
1567 cmdline_parse_inst_t cmd_config_loopback_all = {
1568         .f = cmd_config_loopback_all_parsed,
1569         .data = NULL,
1570         .help_str = "port config all loopback <mode>",
1571         .tokens = {
1572                 (void *)&cmd_config_loopback_all_port,
1573                 (void *)&cmd_config_loopback_all_keyword,
1574                 (void *)&cmd_config_loopback_all_all,
1575                 (void *)&cmd_config_loopback_all_item,
1576                 (void *)&cmd_config_loopback_all_mode,
1577                 NULL,
1578         },
1579 };
1580
1581 /* *** configure loopback for specific port *** */
1582 struct cmd_config_loopback_specific {
1583         cmdline_fixed_string_t port;
1584         cmdline_fixed_string_t keyword;
1585         uint16_t port_id;
1586         cmdline_fixed_string_t item;
1587         uint32_t mode;
1588 };
1589
1590 static void
1591 cmd_config_loopback_specific_parsed(void *parsed_result,
1592                                 __attribute__((unused)) struct cmdline *cl,
1593                                 __attribute__((unused)) void *data)
1594 {
1595         struct cmd_config_loopback_specific *res = parsed_result;
1596
1597         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1598                 return;
1599
1600         if (!port_is_stopped(res->port_id)) {
1601                 printf("Please stop port %u first\n", res->port_id);
1602                 return;
1603         }
1604
1605         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1606
1607         cmd_reconfig_device_queue(res->port_id, 1, 1);
1608 }
1609
1610
1611 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1612         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1613                                                                 "port");
1614 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1615         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1616                                                                 "config");
1617 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1618         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1619                                                                 UINT16);
1620 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1621         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1622                                                                 "loopback");
1623 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1624         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1625                               UINT32);
1626
1627 cmdline_parse_inst_t cmd_config_loopback_specific = {
1628         .f = cmd_config_loopback_specific_parsed,
1629         .data = NULL,
1630         .help_str = "port config <port_id> loopback <mode>",
1631         .tokens = {
1632                 (void *)&cmd_config_loopback_specific_port,
1633                 (void *)&cmd_config_loopback_specific_keyword,
1634                 (void *)&cmd_config_loopback_specific_id,
1635                 (void *)&cmd_config_loopback_specific_item,
1636                 (void *)&cmd_config_loopback_specific_mode,
1637                 NULL,
1638         },
1639 };
1640
1641 /* *** configure txq/rxq, txd/rxd *** */
1642 struct cmd_config_rx_tx {
1643         cmdline_fixed_string_t port;
1644         cmdline_fixed_string_t keyword;
1645         cmdline_fixed_string_t all;
1646         cmdline_fixed_string_t name;
1647         uint16_t value;
1648 };
1649
1650 static void
1651 cmd_config_rx_tx_parsed(void *parsed_result,
1652                         __attribute__((unused)) struct cmdline *cl,
1653                         __attribute__((unused)) void *data)
1654 {
1655         struct cmd_config_rx_tx *res = parsed_result;
1656
1657         if (!all_ports_stopped()) {
1658                 printf("Please stop all ports first\n");
1659                 return;
1660         }
1661         if (!strcmp(res->name, "rxq")) {
1662                 if (!res->value && !nb_txq) {
1663                         printf("Warning: Either rx or tx queues should be non zero\n");
1664                         return;
1665                 }
1666                 if (check_nb_rxq(res->value) != 0)
1667                         return;
1668                 nb_rxq = res->value;
1669         }
1670         else if (!strcmp(res->name, "txq")) {
1671                 if (!res->value && !nb_rxq) {
1672                         printf("Warning: Either rx or tx queues should be non zero\n");
1673                         return;
1674                 }
1675                 if (check_nb_txq(res->value) != 0)
1676                         return;
1677                 nb_txq = res->value;
1678         }
1679         else if (!strcmp(res->name, "rxd")) {
1680                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1681                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1682                                         res->value, RTE_TEST_RX_DESC_MAX);
1683                         return;
1684                 }
1685                 nb_rxd = res->value;
1686         } else if (!strcmp(res->name, "txd")) {
1687                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1688                         printf("txd %d invalid - must be > 0 && <= %d\n",
1689                                         res->value, RTE_TEST_TX_DESC_MAX);
1690                         return;
1691                 }
1692                 nb_txd = res->value;
1693         } else {
1694                 printf("Unknown parameter\n");
1695                 return;
1696         }
1697
1698         fwd_config_setup();
1699
1700         init_port_config();
1701
1702         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1703 }
1704
1705 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1706         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1707 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1708         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1709 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1710         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1711 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1713                                                 "rxq#txq#rxd#txd");
1714 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1715         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1716
1717 cmdline_parse_inst_t cmd_config_rx_tx = {
1718         .f = cmd_config_rx_tx_parsed,
1719         .data = NULL,
1720         .help_str = "port config all rxq|txq|rxd|txd <value>",
1721         .tokens = {
1722                 (void *)&cmd_config_rx_tx_port,
1723                 (void *)&cmd_config_rx_tx_keyword,
1724                 (void *)&cmd_config_rx_tx_all,
1725                 (void *)&cmd_config_rx_tx_name,
1726                 (void *)&cmd_config_rx_tx_value,
1727                 NULL,
1728         },
1729 };
1730
1731 /* *** config max packet length *** */
1732 struct cmd_config_max_pkt_len_result {
1733         cmdline_fixed_string_t port;
1734         cmdline_fixed_string_t keyword;
1735         cmdline_fixed_string_t all;
1736         cmdline_fixed_string_t name;
1737         uint32_t value;
1738 };
1739
1740 static void
1741 cmd_config_max_pkt_len_parsed(void *parsed_result,
1742                                 __attribute__((unused)) struct cmdline *cl,
1743                                 __attribute__((unused)) void *data)
1744 {
1745         struct cmd_config_max_pkt_len_result *res = parsed_result;
1746         portid_t pid;
1747
1748         if (!all_ports_stopped()) {
1749                 printf("Please stop all ports first\n");
1750                 return;
1751         }
1752
1753         RTE_ETH_FOREACH_DEV(pid) {
1754                 struct rte_port *port = &ports[pid];
1755                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1756
1757                 if (!strcmp(res->name, "max-pkt-len")) {
1758                         if (res->value < ETHER_MIN_LEN) {
1759                                 printf("max-pkt-len can not be less than %d\n",
1760                                                 ETHER_MIN_LEN);
1761                                 return;
1762                         }
1763                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1764                                 return;
1765
1766                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1767                         if (res->value > ETHER_MAX_LEN)
1768                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1769                         else
1770                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1771                         port->dev_conf.rxmode.offloads = rx_offloads;
1772                 } else {
1773                         printf("Unknown parameter\n");
1774                         return;
1775                 }
1776         }
1777
1778         init_port_config();
1779
1780         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1781 }
1782
1783 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1784         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1785                                                                 "port");
1786 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1788                                                                 "config");
1789 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1791                                                                 "all");
1792 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1794                                                                 "max-pkt-len");
1795 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1796         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1797                                                                 UINT32);
1798
1799 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1800         .f = cmd_config_max_pkt_len_parsed,
1801         .data = NULL,
1802         .help_str = "port config all max-pkt-len <value>",
1803         .tokens = {
1804                 (void *)&cmd_config_max_pkt_len_port,
1805                 (void *)&cmd_config_max_pkt_len_keyword,
1806                 (void *)&cmd_config_max_pkt_len_all,
1807                 (void *)&cmd_config_max_pkt_len_name,
1808                 (void *)&cmd_config_max_pkt_len_value,
1809                 NULL,
1810         },
1811 };
1812
1813 /* *** configure port MTU *** */
1814 struct cmd_config_mtu_result {
1815         cmdline_fixed_string_t port;
1816         cmdline_fixed_string_t keyword;
1817         cmdline_fixed_string_t mtu;
1818         portid_t port_id;
1819         uint16_t value;
1820 };
1821
1822 static void
1823 cmd_config_mtu_parsed(void *parsed_result,
1824                       __attribute__((unused)) struct cmdline *cl,
1825                       __attribute__((unused)) void *data)
1826 {
1827         struct cmd_config_mtu_result *res = parsed_result;
1828
1829         if (res->value < ETHER_MIN_LEN) {
1830                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1831                 return;
1832         }
1833         port_mtu_set(res->port_id, res->value);
1834 }
1835
1836 cmdline_parse_token_string_t cmd_config_mtu_port =
1837         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1838                                  "port");
1839 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1841                                  "config");
1842 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1844                                  "mtu");
1845 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1846         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1847 cmdline_parse_token_num_t cmd_config_mtu_value =
1848         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1849
1850 cmdline_parse_inst_t cmd_config_mtu = {
1851         .f = cmd_config_mtu_parsed,
1852         .data = NULL,
1853         .help_str = "port config mtu <port_id> <value>",
1854         .tokens = {
1855                 (void *)&cmd_config_mtu_port,
1856                 (void *)&cmd_config_mtu_keyword,
1857                 (void *)&cmd_config_mtu_mtu,
1858                 (void *)&cmd_config_mtu_port_id,
1859                 (void *)&cmd_config_mtu_value,
1860                 NULL,
1861         },
1862 };
1863
1864 /* *** configure rx mode *** */
1865 struct cmd_config_rx_mode_flag {
1866         cmdline_fixed_string_t port;
1867         cmdline_fixed_string_t keyword;
1868         cmdline_fixed_string_t all;
1869         cmdline_fixed_string_t name;
1870         cmdline_fixed_string_t value;
1871 };
1872
1873 static void
1874 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1875                                 __attribute__((unused)) struct cmdline *cl,
1876                                 __attribute__((unused)) void *data)
1877 {
1878         struct cmd_config_rx_mode_flag *res = parsed_result;
1879         portid_t pid;
1880
1881         if (!all_ports_stopped()) {
1882                 printf("Please stop all ports first\n");
1883                 return;
1884         }
1885
1886         RTE_ETH_FOREACH_DEV(pid) {
1887                 struct rte_port *port;
1888                 uint64_t rx_offloads;
1889
1890                 port = &ports[pid];
1891                 rx_offloads = port->dev_conf.rxmode.offloads;
1892                 if (!strcmp(res->name, "crc-strip")) {
1893                         if (!strcmp(res->value, "on"))
1894                                 rx_offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
1895                         else if (!strcmp(res->value, "off"))
1896                                 rx_offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
1897                         else {
1898                                 printf("Unknown parameter\n");
1899                                 return;
1900                         }
1901                 } else if (!strcmp(res->name, "scatter")) {
1902                         if (!strcmp(res->value, "on")) {
1903                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
1904                         } else if (!strcmp(res->value, "off")) {
1905                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
1906                         } else {
1907                                 printf("Unknown parameter\n");
1908                                 return;
1909                         }
1910                 } else if (!strcmp(res->name, "rx-cksum")) {
1911                         if (!strcmp(res->value, "on"))
1912                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
1913                         else if (!strcmp(res->value, "off"))
1914                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
1915                         else {
1916                                 printf("Unknown parameter\n");
1917                                 return;
1918                         }
1919                 } else if (!strcmp(res->name, "rx-timestamp")) {
1920                         if (!strcmp(res->value, "on"))
1921                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
1922                         else if (!strcmp(res->value, "off"))
1923                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
1924                         else {
1925                                 printf("Unknown parameter\n");
1926                                 return;
1927                         }
1928                 } else if (!strcmp(res->name, "hw-vlan")) {
1929                         if (!strcmp(res->value, "on")) {
1930                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
1931                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1932                         } else if (!strcmp(res->value, "off")) {
1933                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
1934                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
1935                         } else {
1936                                 printf("Unknown parameter\n");
1937                                 return;
1938                         }
1939                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
1940                         if (!strcmp(res->value, "on"))
1941                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
1942                         else if (!strcmp(res->value, "off"))
1943                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
1944                         else {
1945                                 printf("Unknown parameter\n");
1946                                 return;
1947                         }
1948                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
1949                         if (!strcmp(res->value, "on"))
1950                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
1951                         else if (!strcmp(res->value, "off"))
1952                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
1953                         else {
1954                                 printf("Unknown parameter\n");
1955                                 return;
1956                         }
1957                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
1958                         if (!strcmp(res->value, "on"))
1959                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
1960                         else if (!strcmp(res->value, "off"))
1961                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
1962                         else {
1963                                 printf("Unknown parameter\n");
1964                                 return;
1965                         }
1966                 } else if (!strcmp(res->name, "drop-en")) {
1967                         if (!strcmp(res->value, "on"))
1968                                 rx_drop_en = 1;
1969                         else if (!strcmp(res->value, "off"))
1970                                 rx_drop_en = 0;
1971                         else {
1972                                 printf("Unknown parameter\n");
1973                                 return;
1974                         }
1975                 } else {
1976                         printf("Unknown parameter\n");
1977                         return;
1978                 }
1979                 port->dev_conf.rxmode.offloads = rx_offloads;
1980         }
1981
1982         init_port_config();
1983
1984         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1985 }
1986
1987 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1988         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1989 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1990         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1991                                                                 "config");
1992 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1993         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1994 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1995         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1996                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1997                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1998 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1999         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2000                                                         "on#off");
2001
2002 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2003         .f = cmd_config_rx_mode_flag_parsed,
2004         .data = NULL,
2005         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2006                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2007         .tokens = {
2008                 (void *)&cmd_config_rx_mode_flag_port,
2009                 (void *)&cmd_config_rx_mode_flag_keyword,
2010                 (void *)&cmd_config_rx_mode_flag_all,
2011                 (void *)&cmd_config_rx_mode_flag_name,
2012                 (void *)&cmd_config_rx_mode_flag_value,
2013                 NULL,
2014         },
2015 };
2016
2017 /* *** configure rss *** */
2018 struct cmd_config_rss {
2019         cmdline_fixed_string_t port;
2020         cmdline_fixed_string_t keyword;
2021         cmdline_fixed_string_t all;
2022         cmdline_fixed_string_t name;
2023         cmdline_fixed_string_t value;
2024 };
2025
2026 static void
2027 cmd_config_rss_parsed(void *parsed_result,
2028                         __attribute__((unused)) struct cmdline *cl,
2029                         __attribute__((unused)) void *data)
2030 {
2031         struct cmd_config_rss *res = parsed_result;
2032         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2033         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2034         int use_default = 0;
2035         int all_updated = 1;
2036         int diag;
2037         uint16_t i;
2038
2039         if (!strcmp(res->value, "all"))
2040                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2041                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2042                                         ETH_RSS_L2_PAYLOAD;
2043         else if (!strcmp(res->value, "ip"))
2044                 rss_conf.rss_hf = ETH_RSS_IP;
2045         else if (!strcmp(res->value, "udp"))
2046                 rss_conf.rss_hf = ETH_RSS_UDP;
2047         else if (!strcmp(res->value, "tcp"))
2048                 rss_conf.rss_hf = ETH_RSS_TCP;
2049         else if (!strcmp(res->value, "sctp"))
2050                 rss_conf.rss_hf = ETH_RSS_SCTP;
2051         else if (!strcmp(res->value, "ether"))
2052                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2053         else if (!strcmp(res->value, "port"))
2054                 rss_conf.rss_hf = ETH_RSS_PORT;
2055         else if (!strcmp(res->value, "vxlan"))
2056                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2057         else if (!strcmp(res->value, "geneve"))
2058                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2059         else if (!strcmp(res->value, "nvgre"))
2060                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2061         else if (!strcmp(res->value, "none"))
2062                 rss_conf.rss_hf = 0;
2063         else if (!strcmp(res->value, "default"))
2064                 use_default = 1;
2065         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2066                                                 atoi(res->value) < 64)
2067                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2068         else {
2069                 printf("Unknown parameter\n");
2070                 return;
2071         }
2072         rss_conf.rss_key = NULL;
2073         /* Update global configuration for RSS types. */
2074         RTE_ETH_FOREACH_DEV(i) {
2075                 struct rte_eth_rss_conf local_rss_conf;
2076
2077                 rte_eth_dev_info_get(i, &dev_info);
2078                 if (use_default)
2079                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2080
2081                 local_rss_conf = rss_conf;
2082                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2083                         dev_info.flow_type_rss_offloads;
2084                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2085                         printf("Port %u modified RSS hash function based on hardware support,"
2086                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2087                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2088                 }
2089                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2090                 if (diag < 0) {
2091                         all_updated = 0;
2092                         printf("Configuration of RSS hash at ethernet port %d "
2093                                 "failed with error (%d): %s.\n",
2094                                 i, -diag, strerror(-diag));
2095                 }
2096         }
2097         if (all_updated && !use_default)
2098                 rss_hf = rss_conf.rss_hf;
2099 }
2100
2101 cmdline_parse_token_string_t cmd_config_rss_port =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2103 cmdline_parse_token_string_t cmd_config_rss_keyword =
2104         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2105 cmdline_parse_token_string_t cmd_config_rss_all =
2106         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2107 cmdline_parse_token_string_t cmd_config_rss_name =
2108         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2109 cmdline_parse_token_string_t cmd_config_rss_value =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2111
2112 cmdline_parse_inst_t cmd_config_rss = {
2113         .f = cmd_config_rss_parsed,
2114         .data = NULL,
2115         .help_str = "port config all rss "
2116                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
2117         .tokens = {
2118                 (void *)&cmd_config_rss_port,
2119                 (void *)&cmd_config_rss_keyword,
2120                 (void *)&cmd_config_rss_all,
2121                 (void *)&cmd_config_rss_name,
2122                 (void *)&cmd_config_rss_value,
2123                 NULL,
2124         },
2125 };
2126
2127 /* *** configure rss hash key *** */
2128 struct cmd_config_rss_hash_key {
2129         cmdline_fixed_string_t port;
2130         cmdline_fixed_string_t config;
2131         portid_t port_id;
2132         cmdline_fixed_string_t rss_hash_key;
2133         cmdline_fixed_string_t rss_type;
2134         cmdline_fixed_string_t key;
2135 };
2136
2137 static uint8_t
2138 hexa_digit_to_value(char hexa_digit)
2139 {
2140         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2141                 return (uint8_t) (hexa_digit - '0');
2142         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2143                 return (uint8_t) ((hexa_digit - 'a') + 10);
2144         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2145                 return (uint8_t) ((hexa_digit - 'A') + 10);
2146         /* Invalid hexa digit */
2147         return 0xFF;
2148 }
2149
2150 static uint8_t
2151 parse_and_check_key_hexa_digit(char *key, int idx)
2152 {
2153         uint8_t hexa_v;
2154
2155         hexa_v = hexa_digit_to_value(key[idx]);
2156         if (hexa_v == 0xFF)
2157                 printf("invalid key: character %c at position %d is not a "
2158                        "valid hexa digit\n", key[idx], idx);
2159         return hexa_v;
2160 }
2161
2162 static void
2163 cmd_config_rss_hash_key_parsed(void *parsed_result,
2164                                __attribute__((unused)) struct cmdline *cl,
2165                                __attribute__((unused)) void *data)
2166 {
2167         struct cmd_config_rss_hash_key *res = parsed_result;
2168         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2169         uint8_t xdgt0;
2170         uint8_t xdgt1;
2171         int i;
2172         struct rte_eth_dev_info dev_info;
2173         uint8_t hash_key_size;
2174         uint32_t key_len;
2175
2176         memset(&dev_info, 0, sizeof(dev_info));
2177         rte_eth_dev_info_get(res->port_id, &dev_info);
2178         if (dev_info.hash_key_size > 0 &&
2179                         dev_info.hash_key_size <= sizeof(hash_key))
2180                 hash_key_size = dev_info.hash_key_size;
2181         else {
2182                 printf("dev_info did not provide a valid hash key size\n");
2183                 return;
2184         }
2185         /* Check the length of the RSS hash key */
2186         key_len = strlen(res->key);
2187         if (key_len != (hash_key_size * 2)) {
2188                 printf("key length: %d invalid - key must be a string of %d"
2189                            " hexa-decimal numbers\n",
2190                            (int) key_len, hash_key_size * 2);
2191                 return;
2192         }
2193         /* Translate RSS hash key into binary representation */
2194         for (i = 0; i < hash_key_size; i++) {
2195                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2196                 if (xdgt0 == 0xFF)
2197                         return;
2198                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2199                 if (xdgt1 == 0xFF)
2200                         return;
2201                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2202         }
2203         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2204                         hash_key_size);
2205 }
2206
2207 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2208         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2209 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2210         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2211                                  "config");
2212 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2213         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2214 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2215         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2216                                  rss_hash_key, "rss-hash-key");
2217 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2218         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2219                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2220                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2221                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2222                                  "ipv6-tcp-ex#ipv6-udp-ex");
2223 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2225
2226 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2227         .f = cmd_config_rss_hash_key_parsed,
2228         .data = NULL,
2229         .help_str = "port config <port_id> rss-hash-key "
2230                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2231                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2232                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2233                 "<string of hex digits (variable length, NIC dependent)>",
2234         .tokens = {
2235                 (void *)&cmd_config_rss_hash_key_port,
2236                 (void *)&cmd_config_rss_hash_key_config,
2237                 (void *)&cmd_config_rss_hash_key_port_id,
2238                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2239                 (void *)&cmd_config_rss_hash_key_rss_type,
2240                 (void *)&cmd_config_rss_hash_key_value,
2241                 NULL,
2242         },
2243 };
2244
2245 /* *** configure port rxq/txq ring size *** */
2246 struct cmd_config_rxtx_ring_size {
2247         cmdline_fixed_string_t port;
2248         cmdline_fixed_string_t config;
2249         portid_t portid;
2250         cmdline_fixed_string_t rxtxq;
2251         uint16_t qid;
2252         cmdline_fixed_string_t rsize;
2253         uint16_t size;
2254 };
2255
2256 static void
2257 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2258                                  __attribute__((unused)) struct cmdline *cl,
2259                                  __attribute__((unused)) void *data)
2260 {
2261         struct cmd_config_rxtx_ring_size *res = parsed_result;
2262         struct rte_port *port;
2263         uint8_t isrx;
2264
2265         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2266                 return;
2267
2268         if (res->portid == (portid_t)RTE_PORT_ALL) {
2269                 printf("Invalid port id\n");
2270                 return;
2271         }
2272
2273         port = &ports[res->portid];
2274
2275         if (!strcmp(res->rxtxq, "rxq"))
2276                 isrx = 1;
2277         else if (!strcmp(res->rxtxq, "txq"))
2278                 isrx = 0;
2279         else {
2280                 printf("Unknown parameter\n");
2281                 return;
2282         }
2283
2284         if (isrx && rx_queue_id_is_invalid(res->qid))
2285                 return;
2286         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2287                 return;
2288
2289         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2290                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2291                        rx_free_thresh);
2292                 return;
2293         }
2294
2295         if (isrx)
2296                 port->nb_rx_desc[res->qid] = res->size;
2297         else
2298                 port->nb_tx_desc[res->qid] = res->size;
2299
2300         cmd_reconfig_device_queue(res->portid, 0, 1);
2301 }
2302
2303 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2304         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2305                                  port, "port");
2306 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2307         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2308                                  config, "config");
2309 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2310         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2311                                  portid, UINT16);
2312 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2313         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2314                                  rxtxq, "rxq#txq");
2315 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2316         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2317                               qid, UINT16);
2318 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2319         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2320                                  rsize, "ring_size");
2321 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2322         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2323                               size, UINT16);
2324
2325 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2326         .f = cmd_config_rxtx_ring_size_parsed,
2327         .data = NULL,
2328         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2329         .tokens = {
2330                 (void *)&cmd_config_rxtx_ring_size_port,
2331                 (void *)&cmd_config_rxtx_ring_size_config,
2332                 (void *)&cmd_config_rxtx_ring_size_portid,
2333                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2334                 (void *)&cmd_config_rxtx_ring_size_qid,
2335                 (void *)&cmd_config_rxtx_ring_size_rsize,
2336                 (void *)&cmd_config_rxtx_ring_size_size,
2337                 NULL,
2338         },
2339 };
2340
2341 /* *** configure port rxq/txq start/stop *** */
2342 struct cmd_config_rxtx_queue {
2343         cmdline_fixed_string_t port;
2344         portid_t portid;
2345         cmdline_fixed_string_t rxtxq;
2346         uint16_t qid;
2347         cmdline_fixed_string_t opname;
2348 };
2349
2350 static void
2351 cmd_config_rxtx_queue_parsed(void *parsed_result,
2352                         __attribute__((unused)) struct cmdline *cl,
2353                         __attribute__((unused)) void *data)
2354 {
2355         struct cmd_config_rxtx_queue *res = parsed_result;
2356         uint8_t isrx;
2357         uint8_t isstart;
2358         int ret = 0;
2359
2360         if (test_done == 0) {
2361                 printf("Please stop forwarding first\n");
2362                 return;
2363         }
2364
2365         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2366                 return;
2367
2368         if (port_is_started(res->portid) != 1) {
2369                 printf("Please start port %u first\n", res->portid);
2370                 return;
2371         }
2372
2373         if (!strcmp(res->rxtxq, "rxq"))
2374                 isrx = 1;
2375         else if (!strcmp(res->rxtxq, "txq"))
2376                 isrx = 0;
2377         else {
2378                 printf("Unknown parameter\n");
2379                 return;
2380         }
2381
2382         if (isrx && rx_queue_id_is_invalid(res->qid))
2383                 return;
2384         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2385                 return;
2386
2387         if (!strcmp(res->opname, "start"))
2388                 isstart = 1;
2389         else if (!strcmp(res->opname, "stop"))
2390                 isstart = 0;
2391         else {
2392                 printf("Unknown parameter\n");
2393                 return;
2394         }
2395
2396         if (isstart && isrx)
2397                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2398         else if (!isstart && isrx)
2399                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2400         else if (isstart && !isrx)
2401                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2402         else
2403                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2404
2405         if (ret == -ENOTSUP)
2406                 printf("Function not supported in PMD driver\n");
2407 }
2408
2409 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2411 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2412         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2413 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2414         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2415 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2416         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2417 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2418         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2419                                                 "start#stop");
2420
2421 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2422         .f = cmd_config_rxtx_queue_parsed,
2423         .data = NULL,
2424         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2425         .tokens = {
2426                 (void *)&cmd_config_rxtx_queue_port,
2427                 (void *)&cmd_config_rxtx_queue_portid,
2428                 (void *)&cmd_config_rxtx_queue_rxtxq,
2429                 (void *)&cmd_config_rxtx_queue_qid,
2430                 (void *)&cmd_config_rxtx_queue_opname,
2431                 NULL,
2432         },
2433 };
2434
2435 /* *** configure port rxq/txq setup *** */
2436 struct cmd_setup_rxtx_queue {
2437         cmdline_fixed_string_t port;
2438         portid_t portid;
2439         cmdline_fixed_string_t rxtxq;
2440         uint16_t qid;
2441         cmdline_fixed_string_t setup;
2442 };
2443
2444 /* Common CLI fields for queue setup */
2445 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2446         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2447 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2448         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2449 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2450         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2451 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2452         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2453 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2454         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2455
2456 static void
2457 cmd_setup_rxtx_queue_parsed(
2458         void *parsed_result,
2459         __attribute__((unused)) struct cmdline *cl,
2460         __attribute__((unused)) void *data)
2461 {
2462         struct cmd_setup_rxtx_queue *res = parsed_result;
2463         struct rte_port *port;
2464         struct rte_mempool *mp;
2465         unsigned int socket_id;
2466         uint8_t isrx = 0;
2467         int ret;
2468
2469         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2470                 return;
2471
2472         if (res->portid == (portid_t)RTE_PORT_ALL) {
2473                 printf("Invalid port id\n");
2474                 return;
2475         }
2476
2477         if (!strcmp(res->rxtxq, "rxq"))
2478                 isrx = 1;
2479         else if (!strcmp(res->rxtxq, "txq"))
2480                 isrx = 0;
2481         else {
2482                 printf("Unknown parameter\n");
2483                 return;
2484         }
2485
2486         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2487                 printf("Invalid rx queue\n");
2488                 return;
2489         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2490                 printf("Invalid tx queue\n");
2491                 return;
2492         }
2493
2494         port = &ports[res->portid];
2495         if (isrx) {
2496                 socket_id = rxring_numa[res->portid];
2497                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2498                         socket_id = port->socket_id;
2499
2500                 mp = mbuf_pool_find(socket_id);
2501                 if (mp == NULL) {
2502                         printf("Failed to setup RX queue: "
2503                                 "No mempool allocation"
2504                                 " on the socket %d\n",
2505                                 rxring_numa[res->portid]);
2506                         return;
2507                 }
2508                 ret = rte_eth_rx_queue_setup(res->portid,
2509                                              res->qid,
2510                                              port->nb_rx_desc[res->qid],
2511                                              socket_id,
2512                                              &port->rx_conf[res->qid],
2513                                              mp);
2514                 if (ret)
2515                         printf("Failed to setup RX queue\n");
2516         } else {
2517                 socket_id = txring_numa[res->portid];
2518                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2519                         socket_id = port->socket_id;
2520
2521                 ret = rte_eth_tx_queue_setup(res->portid,
2522                                              res->qid,
2523                                              port->nb_tx_desc[res->qid],
2524                                              socket_id,
2525                                              &port->tx_conf[res->qid]);
2526                 if (ret)
2527                         printf("Failed to setup TX queue\n");
2528         }
2529 }
2530
2531 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2532         .f = cmd_setup_rxtx_queue_parsed,
2533         .data = NULL,
2534         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2535         .tokens = {
2536                 (void *)&cmd_setup_rxtx_queue_port,
2537                 (void *)&cmd_setup_rxtx_queue_portid,
2538                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2539                 (void *)&cmd_setup_rxtx_queue_qid,
2540                 (void *)&cmd_setup_rxtx_queue_setup,
2541                 NULL,
2542         },
2543 };
2544
2545
2546 /* *** Configure RSS RETA *** */
2547 struct cmd_config_rss_reta {
2548         cmdline_fixed_string_t port;
2549         cmdline_fixed_string_t keyword;
2550         portid_t port_id;
2551         cmdline_fixed_string_t name;
2552         cmdline_fixed_string_t list_name;
2553         cmdline_fixed_string_t list_of_items;
2554 };
2555
2556 static int
2557 parse_reta_config(const char *str,
2558                   struct rte_eth_rss_reta_entry64 *reta_conf,
2559                   uint16_t nb_entries)
2560 {
2561         int i;
2562         unsigned size;
2563         uint16_t hash_index, idx, shift;
2564         uint16_t nb_queue;
2565         char s[256];
2566         const char *p, *p0 = str;
2567         char *end;
2568         enum fieldnames {
2569                 FLD_HASH_INDEX = 0,
2570                 FLD_QUEUE,
2571                 _NUM_FLD
2572         };
2573         unsigned long int_fld[_NUM_FLD];
2574         char *str_fld[_NUM_FLD];
2575
2576         while ((p = strchr(p0,'(')) != NULL) {
2577                 ++p;
2578                 if((p0 = strchr(p,')')) == NULL)
2579                         return -1;
2580
2581                 size = p0 - p;
2582                 if(size >= sizeof(s))
2583                         return -1;
2584
2585                 snprintf(s, sizeof(s), "%.*s", size, p);
2586                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2587                         return -1;
2588                 for (i = 0; i < _NUM_FLD; i++) {
2589                         errno = 0;
2590                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2591                         if (errno != 0 || end == str_fld[i] ||
2592                                         int_fld[i] > 65535)
2593                                 return -1;
2594                 }
2595
2596                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2597                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2598
2599                 if (hash_index >= nb_entries) {
2600                         printf("Invalid RETA hash index=%d\n", hash_index);
2601                         return -1;
2602                 }
2603
2604                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2605                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2606                 reta_conf[idx].mask |= (1ULL << shift);
2607                 reta_conf[idx].reta[shift] = nb_queue;
2608         }
2609
2610         return 0;
2611 }
2612
2613 static void
2614 cmd_set_rss_reta_parsed(void *parsed_result,
2615                         __attribute__((unused)) struct cmdline *cl,
2616                         __attribute__((unused)) void *data)
2617 {
2618         int ret;
2619         struct rte_eth_dev_info dev_info;
2620         struct rte_eth_rss_reta_entry64 reta_conf[8];
2621         struct cmd_config_rss_reta *res = parsed_result;
2622
2623         memset(&dev_info, 0, sizeof(dev_info));
2624         rte_eth_dev_info_get(res->port_id, &dev_info);
2625         if (dev_info.reta_size == 0) {
2626                 printf("Redirection table size is 0 which is "
2627                                         "invalid for RSS\n");
2628                 return;
2629         } else
2630                 printf("The reta size of port %d is %u\n",
2631                         res->port_id, dev_info.reta_size);
2632         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2633                 printf("Currently do not support more than %u entries of "
2634                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2635                 return;
2636         }
2637
2638         memset(reta_conf, 0, sizeof(reta_conf));
2639         if (!strcmp(res->list_name, "reta")) {
2640                 if (parse_reta_config(res->list_of_items, reta_conf,
2641                                                 dev_info.reta_size)) {
2642                         printf("Invalid RSS Redirection Table "
2643                                         "config entered\n");
2644                         return;
2645                 }
2646                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2647                                 reta_conf, dev_info.reta_size);
2648                 if (ret != 0)
2649                         printf("Bad redirection table parameter, "
2650                                         "return code = %d \n", ret);
2651         }
2652 }
2653
2654 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2656 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2657         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2658 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2659         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2660 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2661         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2662 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2663         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2664 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2666                                  NULL);
2667 cmdline_parse_inst_t cmd_config_rss_reta = {
2668         .f = cmd_set_rss_reta_parsed,
2669         .data = NULL,
2670         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2671         .tokens = {
2672                 (void *)&cmd_config_rss_reta_port,
2673                 (void *)&cmd_config_rss_reta_keyword,
2674                 (void *)&cmd_config_rss_reta_port_id,
2675                 (void *)&cmd_config_rss_reta_name,
2676                 (void *)&cmd_config_rss_reta_list_name,
2677                 (void *)&cmd_config_rss_reta_list_of_items,
2678                 NULL,
2679         },
2680 };
2681
2682 /* *** SHOW PORT RETA INFO *** */
2683 struct cmd_showport_reta {
2684         cmdline_fixed_string_t show;
2685         cmdline_fixed_string_t port;
2686         portid_t port_id;
2687         cmdline_fixed_string_t rss;
2688         cmdline_fixed_string_t reta;
2689         uint16_t size;
2690         cmdline_fixed_string_t list_of_items;
2691 };
2692
2693 static int
2694 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2695                            uint16_t nb_entries,
2696                            char *str)
2697 {
2698         uint32_t size;
2699         const char *p, *p0 = str;
2700         char s[256];
2701         char *end;
2702         char *str_fld[8];
2703         uint16_t i;
2704         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2705                         RTE_RETA_GROUP_SIZE;
2706         int ret;
2707
2708         p = strchr(p0, '(');
2709         if (p == NULL)
2710                 return -1;
2711         p++;
2712         p0 = strchr(p, ')');
2713         if (p0 == NULL)
2714                 return -1;
2715         size = p0 - p;
2716         if (size >= sizeof(s)) {
2717                 printf("The string size exceeds the internal buffer size\n");
2718                 return -1;
2719         }
2720         snprintf(s, sizeof(s), "%.*s", size, p);
2721         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2722         if (ret <= 0 || ret != num) {
2723                 printf("The bits of masks do not match the number of "
2724                                         "reta entries: %u\n", num);
2725                 return -1;
2726         }
2727         for (i = 0; i < ret; i++)
2728                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2729
2730         return 0;
2731 }
2732
2733 static void
2734 cmd_showport_reta_parsed(void *parsed_result,
2735                          __attribute__((unused)) struct cmdline *cl,
2736                          __attribute__((unused)) void *data)
2737 {
2738         struct cmd_showport_reta *res = parsed_result;
2739         struct rte_eth_rss_reta_entry64 reta_conf[8];
2740         struct rte_eth_dev_info dev_info;
2741         uint16_t max_reta_size;
2742
2743         memset(&dev_info, 0, sizeof(dev_info));
2744         rte_eth_dev_info_get(res->port_id, &dev_info);
2745         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2746         if (res->size == 0 || res->size > max_reta_size) {
2747                 printf("Invalid redirection table size: %u (1-%u)\n",
2748                         res->size, max_reta_size);
2749                 return;
2750         }
2751
2752         memset(reta_conf, 0, sizeof(reta_conf));
2753         if (showport_parse_reta_config(reta_conf, res->size,
2754                                 res->list_of_items) < 0) {
2755                 printf("Invalid string: %s for reta masks\n",
2756                                         res->list_of_items);
2757                 return;
2758         }
2759         port_rss_reta_info(res->port_id, reta_conf, res->size);
2760 }
2761
2762 cmdline_parse_token_string_t cmd_showport_reta_show =
2763         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2764 cmdline_parse_token_string_t cmd_showport_reta_port =
2765         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2766 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2767         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2768 cmdline_parse_token_string_t cmd_showport_reta_rss =
2769         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2770 cmdline_parse_token_string_t cmd_showport_reta_reta =
2771         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2772 cmdline_parse_token_num_t cmd_showport_reta_size =
2773         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2774 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2775         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2776                                         list_of_items, NULL);
2777
2778 cmdline_parse_inst_t cmd_showport_reta = {
2779         .f = cmd_showport_reta_parsed,
2780         .data = NULL,
2781         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2782         .tokens = {
2783                 (void *)&cmd_showport_reta_show,
2784                 (void *)&cmd_showport_reta_port,
2785                 (void *)&cmd_showport_reta_port_id,
2786                 (void *)&cmd_showport_reta_rss,
2787                 (void *)&cmd_showport_reta_reta,
2788                 (void *)&cmd_showport_reta_size,
2789                 (void *)&cmd_showport_reta_list_of_items,
2790                 NULL,
2791         },
2792 };
2793
2794 /* *** Show RSS hash configuration *** */
2795 struct cmd_showport_rss_hash {
2796         cmdline_fixed_string_t show;
2797         cmdline_fixed_string_t port;
2798         portid_t port_id;
2799         cmdline_fixed_string_t rss_hash;
2800         cmdline_fixed_string_t rss_type;
2801         cmdline_fixed_string_t key; /* optional argument */
2802 };
2803
2804 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2805                                 __attribute__((unused)) struct cmdline *cl,
2806                                 void *show_rss_key)
2807 {
2808         struct cmd_showport_rss_hash *res = parsed_result;
2809
2810         port_rss_hash_conf_show(res->port_id, res->rss_type,
2811                                 show_rss_key != NULL);
2812 }
2813
2814 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2815         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2816 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2817         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2818 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2819         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2820 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2821         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2822                                  "rss-hash");
2823 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2824         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2825                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2826                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2827                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2828                                  "ipv6-tcp-ex#ipv6-udp-ex");
2829 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2830         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2831
2832 cmdline_parse_inst_t cmd_showport_rss_hash = {
2833         .f = cmd_showport_rss_hash_parsed,
2834         .data = NULL,
2835         .help_str = "show port <port_id> rss-hash "
2836                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2837                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2838                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2839         .tokens = {
2840                 (void *)&cmd_showport_rss_hash_show,
2841                 (void *)&cmd_showport_rss_hash_port,
2842                 (void *)&cmd_showport_rss_hash_port_id,
2843                 (void *)&cmd_showport_rss_hash_rss_hash,
2844                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2845                 NULL,
2846         },
2847 };
2848
2849 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2850         .f = cmd_showport_rss_hash_parsed,
2851         .data = (void *)1,
2852         .help_str = "show port <port_id> rss-hash "
2853                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2854                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2855                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2856         .tokens = {
2857                 (void *)&cmd_showport_rss_hash_show,
2858                 (void *)&cmd_showport_rss_hash_port,
2859                 (void *)&cmd_showport_rss_hash_port_id,
2860                 (void *)&cmd_showport_rss_hash_rss_hash,
2861                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2862                 (void *)&cmd_showport_rss_hash_rss_key,
2863                 NULL,
2864         },
2865 };
2866
2867 /* *** Configure DCB *** */
2868 struct cmd_config_dcb {
2869         cmdline_fixed_string_t port;
2870         cmdline_fixed_string_t config;
2871         portid_t port_id;
2872         cmdline_fixed_string_t dcb;
2873         cmdline_fixed_string_t vt;
2874         cmdline_fixed_string_t vt_en;
2875         uint8_t num_tcs;
2876         cmdline_fixed_string_t pfc;
2877         cmdline_fixed_string_t pfc_en;
2878 };
2879
2880 static void
2881 cmd_config_dcb_parsed(void *parsed_result,
2882                         __attribute__((unused)) struct cmdline *cl,
2883                         __attribute__((unused)) void *data)
2884 {
2885         struct cmd_config_dcb *res = parsed_result;
2886         portid_t port_id = res->port_id;
2887         struct rte_port *port;
2888         uint8_t pfc_en;
2889         int ret;
2890
2891         port = &ports[port_id];
2892         /** Check if the port is not started **/
2893         if (port->port_status != RTE_PORT_STOPPED) {
2894                 printf("Please stop port %d first\n", port_id);
2895                 return;
2896         }
2897
2898         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2899                 printf("The invalid number of traffic class,"
2900                         " only 4 or 8 allowed.\n");
2901                 return;
2902         }
2903
2904         if (nb_fwd_lcores < res->num_tcs) {
2905                 printf("nb_cores shouldn't be less than number of TCs.\n");
2906                 return;
2907         }
2908         if (!strncmp(res->pfc_en, "on", 2))
2909                 pfc_en = 1;
2910         else
2911                 pfc_en = 0;
2912
2913         /* DCB in VT mode */
2914         if (!strncmp(res->vt_en, "on", 2))
2915                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2916                                 (enum rte_eth_nb_tcs)res->num_tcs,
2917                                 pfc_en);
2918         else
2919                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2920                                 (enum rte_eth_nb_tcs)res->num_tcs,
2921                                 pfc_en);
2922
2923
2924         if (ret != 0) {
2925                 printf("Cannot initialize network ports.\n");
2926                 return;
2927         }
2928
2929         cmd_reconfig_device_queue(port_id, 1, 1);
2930 }
2931
2932 cmdline_parse_token_string_t cmd_config_dcb_port =
2933         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2934 cmdline_parse_token_string_t cmd_config_dcb_config =
2935         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2936 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2937         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2938 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2939         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2940 cmdline_parse_token_string_t cmd_config_dcb_vt =
2941         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2942 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2943         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2944 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2945         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2946 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2947         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2948 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2949         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2950
2951 cmdline_parse_inst_t cmd_config_dcb = {
2952         .f = cmd_config_dcb_parsed,
2953         .data = NULL,
2954         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2955         .tokens = {
2956                 (void *)&cmd_config_dcb_port,
2957                 (void *)&cmd_config_dcb_config,
2958                 (void *)&cmd_config_dcb_port_id,
2959                 (void *)&cmd_config_dcb_dcb,
2960                 (void *)&cmd_config_dcb_vt,
2961                 (void *)&cmd_config_dcb_vt_en,
2962                 (void *)&cmd_config_dcb_num_tcs,
2963                 (void *)&cmd_config_dcb_pfc,
2964                 (void *)&cmd_config_dcb_pfc_en,
2965                 NULL,
2966         },
2967 };
2968
2969 /* *** configure number of packets per burst *** */
2970 struct cmd_config_burst {
2971         cmdline_fixed_string_t port;
2972         cmdline_fixed_string_t keyword;
2973         cmdline_fixed_string_t all;
2974         cmdline_fixed_string_t name;
2975         uint16_t value;
2976 };
2977
2978 static void
2979 cmd_config_burst_parsed(void *parsed_result,
2980                         __attribute__((unused)) struct cmdline *cl,
2981                         __attribute__((unused)) void *data)
2982 {
2983         struct cmd_config_burst *res = parsed_result;
2984         struct rte_eth_dev_info dev_info;
2985         uint16_t rec_nb_pkts;
2986
2987         if (!all_ports_stopped()) {
2988                 printf("Please stop all ports first\n");
2989                 return;
2990         }
2991
2992         if (!strcmp(res->name, "burst")) {
2993                 if (res->value == 0) {
2994                         /* If user gives a value of zero, query the PMD for
2995                          * its recommended Rx burst size. Testpmd uses a single
2996                          * size for all ports, so assume all ports are the same
2997                          * NIC model and use the values from Port 0.
2998                          */
2999                         rte_eth_dev_info_get(0, &dev_info);
3000                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3001
3002                         if (rec_nb_pkts == 0) {
3003                                 printf("PMD does not recommend a burst size.\n"
3004                                         "User provided value must be between"
3005                                         " 1 and %d\n", MAX_PKT_BURST);
3006                                 return;
3007                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3008                                 printf("PMD recommended burst size of %d"
3009                                         " exceeds maximum value of %d\n",
3010                                         rec_nb_pkts, MAX_PKT_BURST);
3011                                 return;
3012                         }
3013                         printf("Using PMD-provided burst value of %d\n",
3014                                 rec_nb_pkts);
3015                         nb_pkt_per_burst = rec_nb_pkts;
3016                 } else if (res->value > MAX_PKT_BURST) {
3017                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3018                         return;
3019                 } else
3020                         nb_pkt_per_burst = res->value;
3021         } else {
3022                 printf("Unknown parameter\n");
3023                 return;
3024         }
3025
3026         init_port_config();
3027
3028         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3029 }
3030
3031 cmdline_parse_token_string_t cmd_config_burst_port =
3032         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3033 cmdline_parse_token_string_t cmd_config_burst_keyword =
3034         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3035 cmdline_parse_token_string_t cmd_config_burst_all =
3036         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3037 cmdline_parse_token_string_t cmd_config_burst_name =
3038         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3039 cmdline_parse_token_num_t cmd_config_burst_value =
3040         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3041
3042 cmdline_parse_inst_t cmd_config_burst = {
3043         .f = cmd_config_burst_parsed,
3044         .data = NULL,
3045         .help_str = "port config all burst <value>",
3046         .tokens = {
3047                 (void *)&cmd_config_burst_port,
3048                 (void *)&cmd_config_burst_keyword,
3049                 (void *)&cmd_config_burst_all,
3050                 (void *)&cmd_config_burst_name,
3051                 (void *)&cmd_config_burst_value,
3052                 NULL,
3053         },
3054 };
3055
3056 /* *** configure rx/tx queues *** */
3057 struct cmd_config_thresh {
3058         cmdline_fixed_string_t port;
3059         cmdline_fixed_string_t keyword;
3060         cmdline_fixed_string_t all;
3061         cmdline_fixed_string_t name;
3062         uint8_t value;
3063 };
3064
3065 static void
3066 cmd_config_thresh_parsed(void *parsed_result,
3067                         __attribute__((unused)) struct cmdline *cl,
3068                         __attribute__((unused)) void *data)
3069 {
3070         struct cmd_config_thresh *res = parsed_result;
3071
3072         if (!all_ports_stopped()) {
3073                 printf("Please stop all ports first\n");
3074                 return;
3075         }
3076
3077         if (!strcmp(res->name, "txpt"))
3078                 tx_pthresh = res->value;
3079         else if(!strcmp(res->name, "txht"))
3080                 tx_hthresh = res->value;
3081         else if(!strcmp(res->name, "txwt"))
3082                 tx_wthresh = res->value;
3083         else if(!strcmp(res->name, "rxpt"))
3084                 rx_pthresh = res->value;
3085         else if(!strcmp(res->name, "rxht"))
3086                 rx_hthresh = res->value;
3087         else if(!strcmp(res->name, "rxwt"))
3088                 rx_wthresh = res->value;
3089         else {
3090                 printf("Unknown parameter\n");
3091                 return;
3092         }
3093
3094         init_port_config();
3095
3096         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3097 }
3098
3099 cmdline_parse_token_string_t cmd_config_thresh_port =
3100         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3101 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3102         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3103 cmdline_parse_token_string_t cmd_config_thresh_all =
3104         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3105 cmdline_parse_token_string_t cmd_config_thresh_name =
3106         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3107                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3108 cmdline_parse_token_num_t cmd_config_thresh_value =
3109         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3110
3111 cmdline_parse_inst_t cmd_config_thresh = {
3112         .f = cmd_config_thresh_parsed,
3113         .data = NULL,
3114         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3115         .tokens = {
3116                 (void *)&cmd_config_thresh_port,
3117                 (void *)&cmd_config_thresh_keyword,
3118                 (void *)&cmd_config_thresh_all,
3119                 (void *)&cmd_config_thresh_name,
3120                 (void *)&cmd_config_thresh_value,
3121                 NULL,
3122         },
3123 };
3124
3125 /* *** configure free/rs threshold *** */
3126 struct cmd_config_threshold {
3127         cmdline_fixed_string_t port;
3128         cmdline_fixed_string_t keyword;
3129         cmdline_fixed_string_t all;
3130         cmdline_fixed_string_t name;
3131         uint16_t value;
3132 };
3133
3134 static void
3135 cmd_config_threshold_parsed(void *parsed_result,
3136                         __attribute__((unused)) struct cmdline *cl,
3137                         __attribute__((unused)) void *data)
3138 {
3139         struct cmd_config_threshold *res = parsed_result;
3140
3141         if (!all_ports_stopped()) {
3142                 printf("Please stop all ports first\n");
3143                 return;
3144         }
3145
3146         if (!strcmp(res->name, "txfreet"))
3147                 tx_free_thresh = res->value;
3148         else if (!strcmp(res->name, "txrst"))
3149                 tx_rs_thresh = res->value;
3150         else if (!strcmp(res->name, "rxfreet"))
3151                 rx_free_thresh = res->value;
3152         else {
3153                 printf("Unknown parameter\n");
3154                 return;
3155         }
3156
3157         init_port_config();
3158
3159         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3160 }
3161
3162 cmdline_parse_token_string_t cmd_config_threshold_port =
3163         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3164 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3165         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3166                                                                 "config");
3167 cmdline_parse_token_string_t cmd_config_threshold_all =
3168         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3169 cmdline_parse_token_string_t cmd_config_threshold_name =
3170         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3171                                                 "txfreet#txrst#rxfreet");
3172 cmdline_parse_token_num_t cmd_config_threshold_value =
3173         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3174
3175 cmdline_parse_inst_t cmd_config_threshold = {
3176         .f = cmd_config_threshold_parsed,
3177         .data = NULL,
3178         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3179         .tokens = {
3180                 (void *)&cmd_config_threshold_port,
3181                 (void *)&cmd_config_threshold_keyword,
3182                 (void *)&cmd_config_threshold_all,
3183                 (void *)&cmd_config_threshold_name,
3184                 (void *)&cmd_config_threshold_value,
3185                 NULL,
3186         },
3187 };
3188
3189 /* *** stop *** */
3190 struct cmd_stop_result {
3191         cmdline_fixed_string_t stop;
3192 };
3193
3194 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3195                             __attribute__((unused)) struct cmdline *cl,
3196                             __attribute__((unused)) void *data)
3197 {
3198         stop_packet_forwarding();
3199 }
3200
3201 cmdline_parse_token_string_t cmd_stop_stop =
3202         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3203
3204 cmdline_parse_inst_t cmd_stop = {
3205         .f = cmd_stop_parsed,
3206         .data = NULL,
3207         .help_str = "stop: Stop packet forwarding",
3208         .tokens = {
3209                 (void *)&cmd_stop_stop,
3210                 NULL,
3211         },
3212 };
3213
3214 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3215
3216 unsigned int
3217 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3218                 unsigned int *parsed_items, int check_unique_values)
3219 {
3220         unsigned int nb_item;
3221         unsigned int value;
3222         unsigned int i;
3223         unsigned int j;
3224         int value_ok;
3225         char c;
3226
3227         /*
3228          * First parse all items in the list and store their value.
3229          */
3230         value = 0;
3231         nb_item = 0;
3232         value_ok = 0;
3233         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3234                 c = str[i];
3235                 if ((c >= '0') && (c <= '9')) {
3236                         value = (unsigned int) (value * 10 + (c - '0'));
3237                         value_ok = 1;
3238                         continue;
3239                 }
3240                 if (c != ',') {
3241                         printf("character %c is not a decimal digit\n", c);
3242                         return 0;
3243                 }
3244                 if (! value_ok) {
3245                         printf("No valid value before comma\n");
3246                         return 0;
3247                 }
3248                 if (nb_item < max_items) {
3249                         parsed_items[nb_item] = value;
3250                         value_ok = 0;
3251                         value = 0;
3252                 }
3253                 nb_item++;
3254         }
3255         if (nb_item >= max_items) {
3256                 printf("Number of %s = %u > %u (maximum items)\n",
3257                        item_name, nb_item + 1, max_items);
3258                 return 0;
3259         }
3260         parsed_items[nb_item++] = value;
3261         if (! check_unique_values)
3262                 return nb_item;
3263
3264         /*
3265          * Then, check that all values in the list are differents.
3266          * No optimization here...
3267          */
3268         for (i = 0; i < nb_item; i++) {
3269                 for (j = i + 1; j < nb_item; j++) {
3270                         if (parsed_items[j] == parsed_items[i]) {
3271                                 printf("duplicated %s %u at index %u and %u\n",
3272                                        item_name, parsed_items[i], i, j);
3273                                 return 0;
3274                         }
3275                 }
3276         }
3277         return nb_item;
3278 }
3279
3280 struct cmd_set_list_result {
3281         cmdline_fixed_string_t cmd_keyword;
3282         cmdline_fixed_string_t list_name;
3283         cmdline_fixed_string_t list_of_items;
3284 };
3285
3286 static void cmd_set_list_parsed(void *parsed_result,
3287                                 __attribute__((unused)) struct cmdline *cl,
3288                                 __attribute__((unused)) void *data)
3289 {
3290         struct cmd_set_list_result *res;
3291         union {
3292                 unsigned int lcorelist[RTE_MAX_LCORE];
3293                 unsigned int portlist[RTE_MAX_ETHPORTS];
3294         } parsed_items;
3295         unsigned int nb_item;
3296
3297         if (test_done == 0) {
3298                 printf("Please stop forwarding first\n");
3299                 return;
3300         }
3301
3302         res = parsed_result;
3303         if (!strcmp(res->list_name, "corelist")) {
3304                 nb_item = parse_item_list(res->list_of_items, "core",
3305                                           RTE_MAX_LCORE,
3306                                           parsed_items.lcorelist, 1);
3307                 if (nb_item > 0) {
3308                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3309                         fwd_config_setup();
3310                 }
3311                 return;
3312         }
3313         if (!strcmp(res->list_name, "portlist")) {
3314                 nb_item = parse_item_list(res->list_of_items, "port",
3315                                           RTE_MAX_ETHPORTS,
3316                                           parsed_items.portlist, 1);
3317                 if (nb_item > 0) {
3318                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3319                         fwd_config_setup();
3320                 }
3321         }
3322 }
3323
3324 cmdline_parse_token_string_t cmd_set_list_keyword =
3325         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3326                                  "set");
3327 cmdline_parse_token_string_t cmd_set_list_name =
3328         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3329                                  "corelist#portlist");
3330 cmdline_parse_token_string_t cmd_set_list_of_items =
3331         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3332                                  NULL);
3333
3334 cmdline_parse_inst_t cmd_set_fwd_list = {
3335         .f = cmd_set_list_parsed,
3336         .data = NULL,
3337         .help_str = "set corelist|portlist <list0[,list1]*>",
3338         .tokens = {
3339                 (void *)&cmd_set_list_keyword,
3340                 (void *)&cmd_set_list_name,
3341                 (void *)&cmd_set_list_of_items,
3342                 NULL,
3343         },
3344 };
3345
3346 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3347
3348 struct cmd_setmask_result {
3349         cmdline_fixed_string_t set;
3350         cmdline_fixed_string_t mask;
3351         uint64_t hexavalue;
3352 };
3353
3354 static void cmd_set_mask_parsed(void *parsed_result,
3355                                 __attribute__((unused)) struct cmdline *cl,
3356                                 __attribute__((unused)) void *data)
3357 {
3358         struct cmd_setmask_result *res = parsed_result;
3359
3360         if (test_done == 0) {
3361                 printf("Please stop forwarding first\n");
3362                 return;
3363         }
3364         if (!strcmp(res->mask, "coremask")) {
3365                 set_fwd_lcores_mask(res->hexavalue);
3366                 fwd_config_setup();
3367         } else if (!strcmp(res->mask, "portmask")) {
3368                 set_fwd_ports_mask(res->hexavalue);
3369                 fwd_config_setup();
3370         }
3371 }
3372
3373 cmdline_parse_token_string_t cmd_setmask_set =
3374         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3375 cmdline_parse_token_string_t cmd_setmask_mask =
3376         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3377                                  "coremask#portmask");
3378 cmdline_parse_token_num_t cmd_setmask_value =
3379         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3380
3381 cmdline_parse_inst_t cmd_set_fwd_mask = {
3382         .f = cmd_set_mask_parsed,
3383         .data = NULL,
3384         .help_str = "set coremask|portmask <hexadecimal value>",
3385         .tokens = {
3386                 (void *)&cmd_setmask_set,
3387                 (void *)&cmd_setmask_mask,
3388                 (void *)&cmd_setmask_value,
3389                 NULL,
3390         },
3391 };
3392
3393 /*
3394  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3395  */
3396 struct cmd_set_result {
3397         cmdline_fixed_string_t set;
3398         cmdline_fixed_string_t what;
3399         uint16_t value;
3400 };
3401
3402 static void cmd_set_parsed(void *parsed_result,
3403                            __attribute__((unused)) struct cmdline *cl,
3404                            __attribute__((unused)) void *data)
3405 {
3406         struct cmd_set_result *res = parsed_result;
3407         if (!strcmp(res->what, "nbport")) {
3408                 set_fwd_ports_number(res->value);
3409                 fwd_config_setup();
3410         } else if (!strcmp(res->what, "nbcore")) {
3411                 set_fwd_lcores_number(res->value);
3412                 fwd_config_setup();
3413         } else if (!strcmp(res->what, "burst"))
3414                 set_nb_pkt_per_burst(res->value);
3415         else if (!strcmp(res->what, "verbose"))
3416                 set_verbose_level(res->value);
3417 }
3418
3419 cmdline_parse_token_string_t cmd_set_set =
3420         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3421 cmdline_parse_token_string_t cmd_set_what =
3422         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3423                                  "nbport#nbcore#burst#verbose");
3424 cmdline_parse_token_num_t cmd_set_value =
3425         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3426
3427 cmdline_parse_inst_t cmd_set_numbers = {
3428         .f = cmd_set_parsed,
3429         .data = NULL,
3430         .help_str = "set nbport|nbcore|burst|verbose <value>",
3431         .tokens = {
3432                 (void *)&cmd_set_set,
3433                 (void *)&cmd_set_what,
3434                 (void *)&cmd_set_value,
3435                 NULL,
3436         },
3437 };
3438
3439 /* *** SET LOG LEVEL CONFIGURATION *** */
3440
3441 struct cmd_set_log_result {
3442         cmdline_fixed_string_t set;
3443         cmdline_fixed_string_t log;
3444         cmdline_fixed_string_t type;
3445         uint32_t level;
3446 };
3447
3448 static void
3449 cmd_set_log_parsed(void *parsed_result,
3450                    __attribute__((unused)) struct cmdline *cl,
3451                    __attribute__((unused)) void *data)
3452 {
3453         struct cmd_set_log_result *res;
3454         int ret;
3455
3456         res = parsed_result;
3457         if (!strcmp(res->type, "global"))
3458                 rte_log_set_global_level(res->level);
3459         else {
3460                 ret = rte_log_set_level_regexp(res->type, res->level);
3461                 if (ret < 0)
3462                         printf("Unable to set log level\n");
3463         }
3464 }
3465
3466 cmdline_parse_token_string_t cmd_set_log_set =
3467         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3468 cmdline_parse_token_string_t cmd_set_log_log =
3469         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3470 cmdline_parse_token_string_t cmd_set_log_type =
3471         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3472 cmdline_parse_token_num_t cmd_set_log_level =
3473         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3474
3475 cmdline_parse_inst_t cmd_set_log = {
3476         .f = cmd_set_log_parsed,
3477         .data = NULL,
3478         .help_str = "set log global|<type> <level>",
3479         .tokens = {
3480                 (void *)&cmd_set_log_set,
3481                 (void *)&cmd_set_log_log,
3482                 (void *)&cmd_set_log_type,
3483                 (void *)&cmd_set_log_level,
3484                 NULL,
3485         },
3486 };
3487
3488 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3489
3490 struct cmd_set_txpkts_result {
3491         cmdline_fixed_string_t cmd_keyword;
3492         cmdline_fixed_string_t txpkts;
3493         cmdline_fixed_string_t seg_lengths;
3494 };
3495
3496 static void
3497 cmd_set_txpkts_parsed(void *parsed_result,
3498                       __attribute__((unused)) struct cmdline *cl,
3499                       __attribute__((unused)) void *data)
3500 {
3501         struct cmd_set_txpkts_result *res;
3502         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3503         unsigned int nb_segs;
3504
3505         res = parsed_result;
3506         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3507                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3508         if (nb_segs > 0)
3509                 set_tx_pkt_segments(seg_lengths, nb_segs);
3510 }
3511
3512 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3513         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3514                                  cmd_keyword, "set");
3515 cmdline_parse_token_string_t cmd_set_txpkts_name =
3516         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3517                                  txpkts, "txpkts");
3518 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3519         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3520                                  seg_lengths, NULL);
3521
3522 cmdline_parse_inst_t cmd_set_txpkts = {
3523         .f = cmd_set_txpkts_parsed,
3524         .data = NULL,
3525         .help_str = "set txpkts <len0[,len1]*>",
3526         .tokens = {
3527                 (void *)&cmd_set_txpkts_keyword,
3528                 (void *)&cmd_set_txpkts_name,
3529                 (void *)&cmd_set_txpkts_lengths,
3530                 NULL,
3531         },
3532 };
3533
3534 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3535
3536 struct cmd_set_txsplit_result {
3537         cmdline_fixed_string_t cmd_keyword;
3538         cmdline_fixed_string_t txsplit;
3539         cmdline_fixed_string_t mode;
3540 };
3541
3542 static void
3543 cmd_set_txsplit_parsed(void *parsed_result,
3544                       __attribute__((unused)) struct cmdline *cl,
3545                       __attribute__((unused)) void *data)
3546 {
3547         struct cmd_set_txsplit_result *res;
3548
3549         res = parsed_result;
3550         set_tx_pkt_split(res->mode);
3551 }
3552
3553 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3554         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3555                                  cmd_keyword, "set");
3556 cmdline_parse_token_string_t cmd_set_txsplit_name =
3557         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3558                                  txsplit, "txsplit");
3559 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3560         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3561                                  mode, NULL);
3562
3563 cmdline_parse_inst_t cmd_set_txsplit = {
3564         .f = cmd_set_txsplit_parsed,
3565         .data = NULL,
3566         .help_str = "set txsplit on|off|rand",
3567         .tokens = {
3568                 (void *)&cmd_set_txsplit_keyword,
3569                 (void *)&cmd_set_txsplit_name,
3570                 (void *)&cmd_set_txsplit_mode,
3571                 NULL,
3572         },
3573 };
3574
3575 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3576 struct cmd_rx_vlan_filter_all_result {
3577         cmdline_fixed_string_t rx_vlan;
3578         cmdline_fixed_string_t what;
3579         cmdline_fixed_string_t all;
3580         portid_t port_id;
3581 };
3582
3583 static void
3584 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3585                               __attribute__((unused)) struct cmdline *cl,
3586                               __attribute__((unused)) void *data)
3587 {
3588         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3589
3590         if (!strcmp(res->what, "add"))
3591                 rx_vlan_all_filter_set(res->port_id, 1);
3592         else
3593                 rx_vlan_all_filter_set(res->port_id, 0);
3594 }
3595
3596 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3597         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3598                                  rx_vlan, "rx_vlan");
3599 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3600         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3601                                  what, "add#rm");
3602 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3603         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3604                                  all, "all");
3605 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3606         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3607                               port_id, UINT16);
3608
3609 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3610         .f = cmd_rx_vlan_filter_all_parsed,
3611         .data = NULL,
3612         .help_str = "rx_vlan add|rm all <port_id>: "
3613                 "Add/Remove all identifiers to/from the set of VLAN "
3614                 "identifiers filtered by a port",
3615         .tokens = {
3616                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3617                 (void *)&cmd_rx_vlan_filter_all_what,
3618                 (void *)&cmd_rx_vlan_filter_all_all,
3619                 (void *)&cmd_rx_vlan_filter_all_portid,
3620                 NULL,
3621         },
3622 };
3623
3624 /* *** VLAN OFFLOAD SET ON A PORT *** */
3625 struct cmd_vlan_offload_result {
3626         cmdline_fixed_string_t vlan;
3627         cmdline_fixed_string_t set;
3628         cmdline_fixed_string_t vlan_type;
3629         cmdline_fixed_string_t what;
3630         cmdline_fixed_string_t on;
3631         cmdline_fixed_string_t port_id;
3632 };
3633
3634 static void
3635 cmd_vlan_offload_parsed(void *parsed_result,
3636                           __attribute__((unused)) struct cmdline *cl,
3637                           __attribute__((unused)) void *data)
3638 {
3639         int on;
3640         struct cmd_vlan_offload_result *res = parsed_result;
3641         char *str;
3642         int i, len = 0;
3643         portid_t port_id = 0;
3644         unsigned int tmp;
3645
3646         str = res->port_id;
3647         len = strnlen(str, STR_TOKEN_SIZE);
3648         i = 0;
3649         /* Get port_id first */
3650         while(i < len){
3651                 if(str[i] == ',')
3652                         break;
3653
3654                 i++;
3655         }
3656         str[i]='\0';
3657         tmp = strtoul(str, NULL, 0);
3658         /* If port_id greater that what portid_t can represent, return */
3659         if(tmp >= RTE_MAX_ETHPORTS)
3660                 return;
3661         port_id = (portid_t)tmp;
3662
3663         if (!strcmp(res->on, "on"))
3664                 on = 1;
3665         else
3666                 on = 0;
3667
3668         if (!strcmp(res->what, "strip"))
3669                 rx_vlan_strip_set(port_id,  on);
3670         else if(!strcmp(res->what, "stripq")){
3671                 uint16_t queue_id = 0;
3672
3673                 /* No queue_id, return */
3674                 if(i + 1 >= len) {
3675                         printf("must specify (port,queue_id)\n");
3676                         return;
3677                 }
3678                 tmp = strtoul(str + i + 1, NULL, 0);
3679                 /* If queue_id greater that what 16-bits can represent, return */
3680                 if(tmp > 0xffff)
3681                         return;
3682
3683                 queue_id = (uint16_t)tmp;
3684                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3685         }
3686         else if (!strcmp(res->what, "filter"))
3687                 rx_vlan_filter_set(port_id, on);
3688         else
3689                 vlan_extend_set(port_id, on);
3690
3691         return;
3692 }
3693
3694 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3695         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3696                                  vlan, "vlan");
3697 cmdline_parse_token_string_t cmd_vlan_offload_set =
3698         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3699                                  set, "set");
3700 cmdline_parse_token_string_t cmd_vlan_offload_what =
3701         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3702                                  what, "strip#filter#qinq#stripq");
3703 cmdline_parse_token_string_t cmd_vlan_offload_on =
3704         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3705                               on, "on#off");
3706 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3707         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3708                               port_id, NULL);
3709
3710 cmdline_parse_inst_t cmd_vlan_offload = {
3711         .f = cmd_vlan_offload_parsed,
3712         .data = NULL,
3713         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3714                 "<port_id[,queue_id]>: "
3715                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3716         .tokens = {
3717                 (void *)&cmd_vlan_offload_vlan,
3718                 (void *)&cmd_vlan_offload_set,
3719                 (void *)&cmd_vlan_offload_what,
3720                 (void *)&cmd_vlan_offload_on,
3721                 (void *)&cmd_vlan_offload_portid,
3722                 NULL,
3723         },
3724 };
3725
3726 /* *** VLAN TPID SET ON A PORT *** */
3727 struct cmd_vlan_tpid_result {
3728         cmdline_fixed_string_t vlan;
3729         cmdline_fixed_string_t set;
3730         cmdline_fixed_string_t vlan_type;
3731         cmdline_fixed_string_t what;
3732         uint16_t tp_id;
3733         portid_t port_id;
3734 };
3735
3736 static void
3737 cmd_vlan_tpid_parsed(void *parsed_result,
3738                           __attribute__((unused)) struct cmdline *cl,
3739                           __attribute__((unused)) void *data)
3740 {
3741         struct cmd_vlan_tpid_result *res = parsed_result;
3742         enum rte_vlan_type vlan_type;
3743
3744         if (!strcmp(res->vlan_type, "inner"))
3745                 vlan_type = ETH_VLAN_TYPE_INNER;
3746         else if (!strcmp(res->vlan_type, "outer"))
3747                 vlan_type = ETH_VLAN_TYPE_OUTER;
3748         else {
3749                 printf("Unknown vlan type\n");
3750                 return;
3751         }
3752         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3753 }
3754
3755 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3756         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3757                                  vlan, "vlan");
3758 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3759         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3760                                  set, "set");
3761 cmdline_parse_token_string_t cmd_vlan_type =
3762         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3763                                  vlan_type, "inner#outer");
3764 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3765         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3766                                  what, "tpid");
3767 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3768         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3769                               tp_id, UINT16);
3770 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3771         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3772                               port_id, UINT16);
3773
3774 cmdline_parse_inst_t cmd_vlan_tpid = {
3775         .f = cmd_vlan_tpid_parsed,
3776         .data = NULL,
3777         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3778                 "Set the VLAN Ether type",
3779         .tokens = {
3780                 (void *)&cmd_vlan_tpid_vlan,
3781                 (void *)&cmd_vlan_tpid_set,
3782                 (void *)&cmd_vlan_type,
3783                 (void *)&cmd_vlan_tpid_what,
3784                 (void *)&cmd_vlan_tpid_tpid,
3785                 (void *)&cmd_vlan_tpid_portid,
3786                 NULL,
3787         },
3788 };
3789
3790 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3791 struct cmd_rx_vlan_filter_result {
3792         cmdline_fixed_string_t rx_vlan;
3793         cmdline_fixed_string_t what;
3794         uint16_t vlan_id;
3795         portid_t port_id;
3796 };
3797
3798 static void
3799 cmd_rx_vlan_filter_parsed(void *parsed_result,
3800                           __attribute__((unused)) struct cmdline *cl,
3801                           __attribute__((unused)) void *data)
3802 {
3803         struct cmd_rx_vlan_filter_result *res = parsed_result;
3804
3805         if (!strcmp(res->what, "add"))
3806                 rx_vft_set(res->port_id, res->vlan_id, 1);
3807         else
3808                 rx_vft_set(res->port_id, res->vlan_id, 0);
3809 }
3810
3811 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3812         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3813                                  rx_vlan, "rx_vlan");
3814 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3815         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3816                                  what, "add#rm");
3817 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3818         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3819                               vlan_id, UINT16);
3820 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3821         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3822                               port_id, UINT16);
3823
3824 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3825         .f = cmd_rx_vlan_filter_parsed,
3826         .data = NULL,
3827         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3828                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3829                 "identifiers filtered by a port",
3830         .tokens = {
3831                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3832                 (void *)&cmd_rx_vlan_filter_what,
3833                 (void *)&cmd_rx_vlan_filter_vlanid,
3834                 (void *)&cmd_rx_vlan_filter_portid,
3835                 NULL,
3836         },
3837 };
3838
3839 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3840 struct cmd_tx_vlan_set_result {
3841         cmdline_fixed_string_t tx_vlan;
3842         cmdline_fixed_string_t set;
3843         portid_t port_id;
3844         uint16_t vlan_id;
3845 };
3846
3847 static void
3848 cmd_tx_vlan_set_parsed(void *parsed_result,
3849                        __attribute__((unused)) struct cmdline *cl,
3850                        __attribute__((unused)) void *data)
3851 {
3852         struct cmd_tx_vlan_set_result *res = parsed_result;
3853
3854         if (!port_is_stopped(res->port_id)) {
3855                 printf("Please stop port %d first\n", res->port_id);
3856                 return;
3857         }
3858
3859         tx_vlan_set(res->port_id, res->vlan_id);
3860
3861         cmd_reconfig_device_queue(res->port_id, 1, 1);
3862 }
3863
3864 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3865         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3866                                  tx_vlan, "tx_vlan");
3867 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3868         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3869                                  set, "set");
3870 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3871         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3872                               port_id, UINT16);
3873 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3874         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3875                               vlan_id, UINT16);
3876
3877 cmdline_parse_inst_t cmd_tx_vlan_set = {
3878         .f = cmd_tx_vlan_set_parsed,
3879         .data = NULL,
3880         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3881                 "Enable hardware insertion of a single VLAN header "
3882                 "with a given TAG Identifier in packets sent on a port",
3883         .tokens = {
3884                 (void *)&cmd_tx_vlan_set_tx_vlan,
3885                 (void *)&cmd_tx_vlan_set_set,
3886                 (void *)&cmd_tx_vlan_set_portid,
3887                 (void *)&cmd_tx_vlan_set_vlanid,
3888                 NULL,
3889         },
3890 };
3891
3892 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3893 struct cmd_tx_vlan_set_qinq_result {
3894         cmdline_fixed_string_t tx_vlan;
3895         cmdline_fixed_string_t set;
3896         portid_t port_id;
3897         uint16_t vlan_id;
3898         uint16_t vlan_id_outer;
3899 };
3900
3901 static void
3902 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3903                             __attribute__((unused)) struct cmdline *cl,
3904                             __attribute__((unused)) void *data)
3905 {
3906         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3907
3908         if (!port_is_stopped(res->port_id)) {
3909                 printf("Please stop port %d first\n", res->port_id);
3910                 return;
3911         }
3912
3913         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3914
3915         cmd_reconfig_device_queue(res->port_id, 1, 1);
3916 }
3917
3918 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3919         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3920                 tx_vlan, "tx_vlan");
3921 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3922         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3923                 set, "set");
3924 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3925         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3926                 port_id, UINT16);
3927 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3928         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3929                 vlan_id, UINT16);
3930 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3931         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3932                 vlan_id_outer, UINT16);
3933
3934 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3935         .f = cmd_tx_vlan_set_qinq_parsed,
3936         .data = NULL,
3937         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3938                 "Enable hardware insertion of double VLAN header "
3939                 "with given TAG Identifiers in packets sent on a port",
3940         .tokens = {
3941                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3942                 (void *)&cmd_tx_vlan_set_qinq_set,
3943                 (void *)&cmd_tx_vlan_set_qinq_portid,
3944                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3945                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3946                 NULL,
3947         },
3948 };
3949
3950 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3951 struct cmd_tx_vlan_set_pvid_result {
3952         cmdline_fixed_string_t tx_vlan;
3953         cmdline_fixed_string_t set;
3954         cmdline_fixed_string_t pvid;
3955         portid_t port_id;
3956         uint16_t vlan_id;
3957         cmdline_fixed_string_t mode;
3958 };
3959
3960 static void
3961 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3962                             __attribute__((unused)) struct cmdline *cl,
3963                             __attribute__((unused)) void *data)
3964 {
3965         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3966
3967         if (strcmp(res->mode, "on") == 0)
3968                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3969         else
3970                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3971 }
3972
3973 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3974         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3975                                  tx_vlan, "tx_vlan");
3976 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3977         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3978                                  set, "set");
3979 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3980         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3981                                  pvid, "pvid");
3982 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3983         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3984                              port_id, UINT16);
3985 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3986         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3987                               vlan_id, UINT16);
3988 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3989         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3990                                  mode, "on#off");
3991
3992 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3993         .f = cmd_tx_vlan_set_pvid_parsed,
3994         .data = NULL,
3995         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3996         .tokens = {
3997                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3998                 (void *)&cmd_tx_vlan_set_pvid_set,
3999                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4000                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4001                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4002                 (void *)&cmd_tx_vlan_set_pvid_mode,
4003                 NULL,
4004         },
4005 };
4006
4007 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4008 struct cmd_tx_vlan_reset_result {
4009         cmdline_fixed_string_t tx_vlan;
4010         cmdline_fixed_string_t reset;
4011         portid_t port_id;
4012 };
4013
4014 static void
4015 cmd_tx_vlan_reset_parsed(void *parsed_result,
4016                          __attribute__((unused)) struct cmdline *cl,
4017                          __attribute__((unused)) void *data)
4018 {
4019         struct cmd_tx_vlan_reset_result *res = parsed_result;
4020
4021         if (!port_is_stopped(res->port_id)) {
4022                 printf("Please stop port %d first\n", res->port_id);
4023                 return;
4024         }
4025
4026         tx_vlan_reset(res->port_id);
4027
4028         cmd_reconfig_device_queue(res->port_id, 1, 1);
4029 }
4030
4031 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4032         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4033                                  tx_vlan, "tx_vlan");
4034 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4035         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4036                                  reset, "reset");
4037 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4038         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4039                               port_id, UINT16);
4040
4041 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4042         .f = cmd_tx_vlan_reset_parsed,
4043         .data = NULL,
4044         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4045                 "VLAN header in packets sent on a port",
4046         .tokens = {
4047                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4048                 (void *)&cmd_tx_vlan_reset_reset,
4049                 (void *)&cmd_tx_vlan_reset_portid,
4050                 NULL,
4051         },
4052 };
4053
4054
4055 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4056 struct cmd_csum_result {
4057         cmdline_fixed_string_t csum;
4058         cmdline_fixed_string_t mode;
4059         cmdline_fixed_string_t proto;
4060         cmdline_fixed_string_t hwsw;
4061         portid_t port_id;
4062 };
4063
4064 static void
4065 csum_show(int port_id)
4066 {
4067         struct rte_eth_dev_info dev_info;
4068         uint64_t tx_offloads;
4069
4070         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4071         printf("Parse tunnel is %s\n",
4072                 (ports[port_id].parse_tunnel) ? "on" : "off");
4073         printf("IP checksum offload is %s\n",
4074                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4075         printf("UDP checksum offload is %s\n",
4076                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4077         printf("TCP checksum offload is %s\n",
4078                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4079         printf("SCTP checksum offload is %s\n",
4080                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4081         printf("Outer-Ip checksum offload is %s\n",
4082                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4083
4084         /* display warnings if configuration is not supported by the NIC */
4085         rte_eth_dev_info_get(port_id, &dev_info);
4086         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4087                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4088                 printf("Warning: hardware IP checksum enabled but not "
4089                         "supported by port %d\n", port_id);
4090         }
4091         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4092                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4093                 printf("Warning: hardware UDP checksum enabled but not "
4094                         "supported by port %d\n", port_id);
4095         }
4096         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4097                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4098                 printf("Warning: hardware TCP checksum enabled but not "
4099                         "supported by port %d\n", port_id);
4100         }
4101         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4102                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4103                 printf("Warning: hardware SCTP checksum enabled but not "
4104                         "supported by port %d\n", port_id);
4105         }
4106         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4107                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4108                 printf("Warning: hardware outer IP checksum enabled but not "
4109                         "supported by port %d\n", port_id);
4110         }
4111 }
4112
4113 static void
4114 cmd_csum_parsed(void *parsed_result,
4115                        __attribute__((unused)) struct cmdline *cl,
4116                        __attribute__((unused)) void *data)
4117 {
4118         struct cmd_csum_result *res = parsed_result;
4119         int hw = 0;
4120         uint64_t csum_offloads = 0;
4121         struct rte_eth_dev_info dev_info;
4122
4123         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4124                 printf("invalid port %d\n", res->port_id);
4125                 return;
4126         }
4127         if (!port_is_stopped(res->port_id)) {
4128                 printf("Please stop port %d first\n", res->port_id);
4129                 return;
4130         }
4131
4132         rte_eth_dev_info_get(res->port_id, &dev_info);
4133         if (!strcmp(res->mode, "set")) {
4134
4135                 if (!strcmp(res->hwsw, "hw"))
4136                         hw = 1;
4137
4138                 if (!strcmp(res->proto, "ip")) {
4139                         if (hw == 0 || (dev_info.tx_offload_capa &
4140                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4141                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4142                         } else {
4143                                 printf("IP checksum offload is not supported "
4144                                        "by port %u\n", res->port_id);
4145                         }
4146                 } else if (!strcmp(res->proto, "udp")) {
4147                         if (hw == 0 || (dev_info.tx_offload_capa &
4148                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4149                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4150                         } else {
4151                                 printf("UDP checksum offload is not supported "
4152                                        "by port %u\n", res->port_id);
4153                         }
4154                 } else if (!strcmp(res->proto, "tcp")) {
4155                         if (hw == 0 || (dev_info.tx_offload_capa &
4156                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4157                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4158                         } else {
4159                                 printf("TCP checksum offload is not supported "
4160                                        "by port %u\n", res->port_id);
4161                         }
4162                 } else if (!strcmp(res->proto, "sctp")) {
4163                         if (hw == 0 || (dev_info.tx_offload_capa &
4164                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4165                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4166                         } else {
4167                                 printf("SCTP checksum offload is not supported "
4168                                        "by port %u\n", res->port_id);
4169                         }
4170                 } else if (!strcmp(res->proto, "outer-ip")) {
4171                         if (hw == 0 || (dev_info.tx_offload_capa &
4172                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4173                                 csum_offloads |=
4174                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4175                         } else {
4176                                 printf("Outer IP checksum offload is not "
4177                                        "supported by port %u\n", res->port_id);
4178                         }
4179                 }
4180
4181                 if (hw) {
4182                         ports[res->port_id].dev_conf.txmode.offloads |=
4183                                                         csum_offloads;
4184                 } else {
4185                         ports[res->port_id].dev_conf.txmode.offloads &=
4186                                                         (~csum_offloads);
4187                 }
4188         }
4189         csum_show(res->port_id);
4190
4191         cmd_reconfig_device_queue(res->port_id, 1, 1);
4192 }
4193
4194 cmdline_parse_token_string_t cmd_csum_csum =
4195         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4196                                 csum, "csum");
4197 cmdline_parse_token_string_t cmd_csum_mode =
4198         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4199                                 mode, "set");
4200 cmdline_parse_token_string_t cmd_csum_proto =
4201         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4202                                 proto, "ip#tcp#udp#sctp#outer-ip");
4203 cmdline_parse_token_string_t cmd_csum_hwsw =
4204         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4205                                 hwsw, "hw#sw");
4206 cmdline_parse_token_num_t cmd_csum_portid =
4207         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4208                                 port_id, UINT16);
4209
4210 cmdline_parse_inst_t cmd_csum_set = {
4211         .f = cmd_csum_parsed,
4212         .data = NULL,
4213         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
4214                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4215                 "using csum forward engine",
4216         .tokens = {
4217                 (void *)&cmd_csum_csum,
4218                 (void *)&cmd_csum_mode,
4219                 (void *)&cmd_csum_proto,
4220                 (void *)&cmd_csum_hwsw,
4221                 (void *)&cmd_csum_portid,
4222                 NULL,
4223         },
4224 };
4225
4226 cmdline_parse_token_string_t cmd_csum_mode_show =
4227         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4228                                 mode, "show");
4229
4230 cmdline_parse_inst_t cmd_csum_show = {
4231         .f = cmd_csum_parsed,
4232         .data = NULL,
4233         .help_str = "csum show <port_id>: Show checksum offload configuration",
4234         .tokens = {
4235                 (void *)&cmd_csum_csum,
4236                 (void *)&cmd_csum_mode_show,
4237                 (void *)&cmd_csum_portid,
4238                 NULL,
4239         },
4240 };
4241
4242 /* Enable/disable tunnel parsing */
4243 struct cmd_csum_tunnel_result {
4244         cmdline_fixed_string_t csum;
4245         cmdline_fixed_string_t parse;
4246         cmdline_fixed_string_t onoff;
4247         portid_t port_id;
4248 };
4249
4250 static void
4251 cmd_csum_tunnel_parsed(void *parsed_result,
4252                        __attribute__((unused)) struct cmdline *cl,
4253                        __attribute__((unused)) void *data)
4254 {
4255         struct cmd_csum_tunnel_result *res = parsed_result;
4256
4257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4258                 return;
4259
4260         if (!strcmp(res->onoff, "on"))
4261                 ports[res->port_id].parse_tunnel = 1;
4262         else
4263                 ports[res->port_id].parse_tunnel = 0;
4264
4265         csum_show(res->port_id);
4266 }
4267
4268 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4269         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4270                                 csum, "csum");
4271 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4272         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4273                                 parse, "parse_tunnel");
4274 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4275         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4276                                 onoff, "on#off");
4277 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4278         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4279                                 port_id, UINT16);
4280
4281 cmdline_parse_inst_t cmd_csum_tunnel = {
4282         .f = cmd_csum_tunnel_parsed,
4283         .data = NULL,
4284         .help_str = "csum parse_tunnel on|off <port_id>: "
4285                 "Enable/Disable parsing of tunnels for csum engine",
4286         .tokens = {
4287                 (void *)&cmd_csum_tunnel_csum,
4288                 (void *)&cmd_csum_tunnel_parse,
4289                 (void *)&cmd_csum_tunnel_onoff,
4290                 (void *)&cmd_csum_tunnel_portid,
4291                 NULL,
4292         },
4293 };
4294
4295 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4296 struct cmd_tso_set_result {
4297         cmdline_fixed_string_t tso;
4298         cmdline_fixed_string_t mode;
4299         uint16_t tso_segsz;
4300         portid_t port_id;
4301 };
4302
4303 static void
4304 cmd_tso_set_parsed(void *parsed_result,
4305                        __attribute__((unused)) struct cmdline *cl,
4306                        __attribute__((unused)) void *data)
4307 {
4308         struct cmd_tso_set_result *res = parsed_result;
4309         struct rte_eth_dev_info dev_info;
4310
4311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4312                 return;
4313         if (!port_is_stopped(res->port_id)) {
4314                 printf("Please stop port %d first\n", res->port_id);
4315                 return;
4316         }
4317
4318         if (!strcmp(res->mode, "set"))
4319                 ports[res->port_id].tso_segsz = res->tso_segsz;
4320
4321         rte_eth_dev_info_get(res->port_id, &dev_info);
4322         if ((ports[res->port_id].tso_segsz != 0) &&
4323                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4324                 printf("Error: TSO is not supported by port %d\n",
4325                        res->port_id);
4326                 return;
4327         }
4328
4329         if (ports[res->port_id].tso_segsz == 0) {
4330                 ports[res->port_id].dev_conf.txmode.offloads &=
4331                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4332                 printf("TSO for non-tunneled packets is disabled\n");
4333         } else {
4334                 ports[res->port_id].dev_conf.txmode.offloads |=
4335                                                 DEV_TX_OFFLOAD_TCP_TSO;
4336                 printf("TSO segment size for non-tunneled packets is %d\n",
4337                         ports[res->port_id].tso_segsz);
4338         }
4339
4340         /* display warnings if configuration is not supported by the NIC */
4341         rte_eth_dev_info_get(res->port_id, &dev_info);
4342         if ((ports[res->port_id].tso_segsz != 0) &&
4343                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4344                 printf("Warning: TSO enabled but not "
4345                         "supported by port %d\n", res->port_id);
4346         }
4347
4348         cmd_reconfig_device_queue(res->port_id, 1, 1);
4349 }
4350
4351 cmdline_parse_token_string_t cmd_tso_set_tso =
4352         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4353                                 tso, "tso");
4354 cmdline_parse_token_string_t cmd_tso_set_mode =
4355         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4356                                 mode, "set");
4357 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4358         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4359                                 tso_segsz, UINT16);
4360 cmdline_parse_token_num_t cmd_tso_set_portid =
4361         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4362                                 port_id, UINT16);
4363
4364 cmdline_parse_inst_t cmd_tso_set = {
4365         .f = cmd_tso_set_parsed,
4366         .data = NULL,
4367         .help_str = "tso set <tso_segsz> <port_id>: "
4368                 "Set TSO segment size of non-tunneled packets for csum engine "
4369                 "(0 to disable)",
4370         .tokens = {
4371                 (void *)&cmd_tso_set_tso,
4372                 (void *)&cmd_tso_set_mode,
4373                 (void *)&cmd_tso_set_tso_segsz,
4374                 (void *)&cmd_tso_set_portid,
4375                 NULL,
4376         },
4377 };
4378
4379 cmdline_parse_token_string_t cmd_tso_show_mode =
4380         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4381                                 mode, "show");
4382
4383
4384 cmdline_parse_inst_t cmd_tso_show = {
4385         .f = cmd_tso_set_parsed,
4386         .data = NULL,
4387         .help_str = "tso show <port_id>: "
4388                 "Show TSO segment size of non-tunneled packets for csum engine",
4389         .tokens = {
4390                 (void *)&cmd_tso_set_tso,
4391                 (void *)&cmd_tso_show_mode,
4392                 (void *)&cmd_tso_set_portid,
4393                 NULL,
4394         },
4395 };
4396
4397 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4398 struct cmd_tunnel_tso_set_result {
4399         cmdline_fixed_string_t tso;
4400         cmdline_fixed_string_t mode;
4401         uint16_t tso_segsz;
4402         portid_t port_id;
4403 };
4404
4405 static struct rte_eth_dev_info
4406 check_tunnel_tso_nic_support(portid_t port_id)
4407 {
4408         struct rte_eth_dev_info dev_info;
4409
4410         rte_eth_dev_info_get(port_id, &dev_info);
4411         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4412                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4413                        "not enabled for port %d\n", port_id);
4414         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4415                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4416                        "not enabled for port %d\n", port_id);
4417         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4418                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4419                        "not enabled for port %d\n", port_id);
4420         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4421                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4422                        "not enabled for port %d\n", port_id);
4423         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4424                 printf("Warning: IP TUNNEL TSO not supported therefore "
4425                        "not enabled for port %d\n", port_id);
4426         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4427                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4428                        "not enabled for port %d\n", port_id);
4429         return dev_info;
4430 }
4431
4432 static void
4433 cmd_tunnel_tso_set_parsed(void *parsed_result,
4434                           __attribute__((unused)) struct cmdline *cl,
4435                           __attribute__((unused)) void *data)
4436 {
4437         struct cmd_tunnel_tso_set_result *res = parsed_result;
4438         struct rte_eth_dev_info dev_info;
4439
4440         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4441                 return;
4442         if (!port_is_stopped(res->port_id)) {
4443                 printf("Please stop port %d first\n", res->port_id);
4444                 return;
4445         }
4446
4447         if (!strcmp(res->mode, "set"))
4448                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4449
4450         dev_info = check_tunnel_tso_nic_support(res->port_id);
4451         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4452                 ports[res->port_id].dev_conf.txmode.offloads &=
4453                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4454                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4455                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4456                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4457                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4458                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4459                 printf("TSO for tunneled packets is disabled\n");
4460         } else {
4461                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4462                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4463                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4464                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4465                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4466                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4467
4468                 ports[res->port_id].dev_conf.txmode.offloads |=
4469                         (tso_offloads & dev_info.tx_offload_capa);
4470                 printf("TSO segment size for tunneled packets is %d\n",
4471                         ports[res->port_id].tunnel_tso_segsz);
4472
4473                 /* Below conditions are needed to make it work:
4474                  * (1) tunnel TSO is supported by the NIC;
4475                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4476                  * are recognized;
4477                  * (3) for tunneled pkts with outer L3 of IPv4,
4478                  * "csum set outer-ip" must be set to hw, because after tso,
4479                  * total_len of outer IP header is changed, and the checksum
4480                  * of outer IP header calculated by sw should be wrong; that
4481                  * is not necessary for IPv6 tunneled pkts because there's no
4482                  * checksum in IP header anymore.
4483                  */
4484
4485                 if (!ports[res->port_id].parse_tunnel)
4486                         printf("Warning: csum parse_tunnel must be set "
4487                                 "so that tunneled packets are recognized\n");
4488                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4489                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4490                         printf("Warning: csum set outer-ip must be set to hw "
4491                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4492         }
4493
4494         cmd_reconfig_device_queue(res->port_id, 1, 1);
4495 }
4496
4497 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4498         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4499                                 tso, "tunnel_tso");
4500 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4501         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4502                                 mode, "set");
4503 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4504         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4505                                 tso_segsz, UINT16);
4506 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4507         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4508                                 port_id, UINT16);
4509
4510 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4511         .f = cmd_tunnel_tso_set_parsed,
4512         .data = NULL,
4513         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4514                 "Set TSO segment size of tunneled packets for csum engine "
4515                 "(0 to disable)",
4516         .tokens = {
4517                 (void *)&cmd_tunnel_tso_set_tso,
4518                 (void *)&cmd_tunnel_tso_set_mode,
4519                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4520                 (void *)&cmd_tunnel_tso_set_portid,
4521                 NULL,
4522         },
4523 };
4524
4525 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4526         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4527                                 mode, "show");
4528
4529
4530 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4531         .f = cmd_tunnel_tso_set_parsed,
4532         .data = NULL,
4533         .help_str = "tunnel_tso show <port_id> "
4534                 "Show TSO segment size of tunneled packets for csum engine",
4535         .tokens = {
4536                 (void *)&cmd_tunnel_tso_set_tso,
4537                 (void *)&cmd_tunnel_tso_show_mode,
4538                 (void *)&cmd_tunnel_tso_set_portid,
4539                 NULL,
4540         },
4541 };
4542
4543 /* *** SET GRO FOR A PORT *** */
4544 struct cmd_gro_enable_result {
4545         cmdline_fixed_string_t cmd_set;
4546         cmdline_fixed_string_t cmd_port;
4547         cmdline_fixed_string_t cmd_keyword;
4548         cmdline_fixed_string_t cmd_onoff;
4549         portid_t cmd_pid;
4550 };
4551
4552 static void
4553 cmd_gro_enable_parsed(void *parsed_result,
4554                 __attribute__((unused)) struct cmdline *cl,
4555                 __attribute__((unused)) void *data)
4556 {
4557         struct cmd_gro_enable_result *res;
4558
4559         res = parsed_result;
4560         if (!strcmp(res->cmd_keyword, "gro"))
4561                 setup_gro(res->cmd_onoff, res->cmd_pid);
4562 }
4563
4564 cmdline_parse_token_string_t cmd_gro_enable_set =
4565         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4566                         cmd_set, "set");
4567 cmdline_parse_token_string_t cmd_gro_enable_port =
4568         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4569                         cmd_keyword, "port");
4570 cmdline_parse_token_num_t cmd_gro_enable_pid =
4571         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4572                         cmd_pid, UINT16);
4573 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4574         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4575                         cmd_keyword, "gro");
4576 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4577         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4578                         cmd_onoff, "on#off");
4579
4580 cmdline_parse_inst_t cmd_gro_enable = {
4581         .f = cmd_gro_enable_parsed,
4582         .data = NULL,
4583         .help_str = "set port <port_id> gro on|off",
4584         .tokens = {
4585                 (void *)&cmd_gro_enable_set,
4586                 (void *)&cmd_gro_enable_port,
4587                 (void *)&cmd_gro_enable_pid,
4588                 (void *)&cmd_gro_enable_keyword,
4589                 (void *)&cmd_gro_enable_onoff,
4590                 NULL,
4591         },
4592 };
4593
4594 /* *** DISPLAY GRO CONFIGURATION *** */
4595 struct cmd_gro_show_result {
4596         cmdline_fixed_string_t cmd_show;
4597         cmdline_fixed_string_t cmd_port;
4598         cmdline_fixed_string_t cmd_keyword;
4599         portid_t cmd_pid;
4600 };
4601
4602 static void
4603 cmd_gro_show_parsed(void *parsed_result,
4604                 __attribute__((unused)) struct cmdline *cl,
4605                 __attribute__((unused)) void *data)
4606 {
4607         struct cmd_gro_show_result *res;
4608
4609         res = parsed_result;
4610         if (!strcmp(res->cmd_keyword, "gro"))
4611                 show_gro(res->cmd_pid);
4612 }
4613
4614 cmdline_parse_token_string_t cmd_gro_show_show =
4615         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4616                         cmd_show, "show");
4617 cmdline_parse_token_string_t cmd_gro_show_port =
4618         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4619                         cmd_port, "port");
4620 cmdline_parse_token_num_t cmd_gro_show_pid =
4621         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4622                         cmd_pid, UINT16);
4623 cmdline_parse_token_string_t cmd_gro_show_keyword =
4624         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4625                         cmd_keyword, "gro");
4626
4627 cmdline_parse_inst_t cmd_gro_show = {
4628         .f = cmd_gro_show_parsed,
4629         .data = NULL,
4630         .help_str = "show port <port_id> gro",
4631         .tokens = {
4632                 (void *)&cmd_gro_show_show,
4633                 (void *)&cmd_gro_show_port,
4634                 (void *)&cmd_gro_show_pid,
4635                 (void *)&cmd_gro_show_keyword,
4636                 NULL,
4637         },
4638 };
4639
4640 /* *** SET FLUSH CYCLES FOR GRO *** */
4641 struct cmd_gro_flush_result {
4642         cmdline_fixed_string_t cmd_set;
4643         cmdline_fixed_string_t cmd_keyword;
4644         cmdline_fixed_string_t cmd_flush;
4645         uint8_t cmd_cycles;
4646 };
4647
4648 static void
4649 cmd_gro_flush_parsed(void *parsed_result,
4650                 __attribute__((unused)) struct cmdline *cl,
4651                 __attribute__((unused)) void *data)
4652 {
4653         struct cmd_gro_flush_result *res;
4654
4655         res = parsed_result;
4656         if ((!strcmp(res->cmd_keyword, "gro")) &&
4657                         (!strcmp(res->cmd_flush, "flush")))
4658                 setup_gro_flush_cycles(res->cmd_cycles);
4659 }
4660
4661 cmdline_parse_token_string_t cmd_gro_flush_set =
4662         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4663                         cmd_set, "set");
4664 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4665         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4666                         cmd_keyword, "gro");
4667 cmdline_parse_token_string_t cmd_gro_flush_flush =
4668         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4669                         cmd_flush, "flush");
4670 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4671         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4672                         cmd_cycles, UINT8);
4673
4674 cmdline_parse_inst_t cmd_gro_flush = {
4675         .f = cmd_gro_flush_parsed,
4676         .data = NULL,
4677         .help_str = "set gro flush <cycles>",
4678         .tokens = {
4679                 (void *)&cmd_gro_flush_set,
4680                 (void *)&cmd_gro_flush_keyword,
4681                 (void *)&cmd_gro_flush_flush,
4682                 (void *)&cmd_gro_flush_cycles,
4683                 NULL,
4684         },
4685 };
4686
4687 /* *** ENABLE/DISABLE GSO *** */
4688 struct cmd_gso_enable_result {
4689         cmdline_fixed_string_t cmd_set;
4690         cmdline_fixed_string_t cmd_port;
4691         cmdline_fixed_string_t cmd_keyword;
4692         cmdline_fixed_string_t cmd_mode;
4693         portid_t cmd_pid;
4694 };
4695
4696 static void
4697 cmd_gso_enable_parsed(void *parsed_result,
4698                 __attribute__((unused)) struct cmdline *cl,
4699                 __attribute__((unused)) void *data)
4700 {
4701         struct cmd_gso_enable_result *res;
4702
4703         res = parsed_result;
4704         if (!strcmp(res->cmd_keyword, "gso"))
4705                 setup_gso(res->cmd_mode, res->cmd_pid);
4706 }
4707
4708 cmdline_parse_token_string_t cmd_gso_enable_set =
4709         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4710                         cmd_set, "set");
4711 cmdline_parse_token_string_t cmd_gso_enable_port =
4712         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4713                         cmd_port, "port");
4714 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4715         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4716                         cmd_keyword, "gso");
4717 cmdline_parse_token_string_t cmd_gso_enable_mode =
4718         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4719                         cmd_mode, "on#off");
4720 cmdline_parse_token_num_t cmd_gso_enable_pid =
4721         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4722                         cmd_pid, UINT16);
4723
4724 cmdline_parse_inst_t cmd_gso_enable = {
4725         .f = cmd_gso_enable_parsed,
4726         .data = NULL,
4727         .help_str = "set port <port_id> gso on|off",
4728         .tokens = {
4729                 (void *)&cmd_gso_enable_set,
4730                 (void *)&cmd_gso_enable_port,
4731                 (void *)&cmd_gso_enable_pid,
4732                 (void *)&cmd_gso_enable_keyword,
4733                 (void *)&cmd_gso_enable_mode,
4734                 NULL,
4735         },
4736 };
4737
4738 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4739 struct cmd_gso_size_result {
4740         cmdline_fixed_string_t cmd_set;
4741         cmdline_fixed_string_t cmd_keyword;
4742         cmdline_fixed_string_t cmd_segsz;
4743         uint16_t cmd_size;
4744 };
4745
4746 static void
4747 cmd_gso_size_parsed(void *parsed_result,
4748                        __attribute__((unused)) struct cmdline *cl,
4749                        __attribute__((unused)) void *data)
4750 {
4751         struct cmd_gso_size_result *res = parsed_result;
4752
4753         if (test_done == 0) {
4754                 printf("Before setting GSO segsz, please first"
4755                                 " stop fowarding\n");
4756                 return;
4757         }
4758
4759         if (!strcmp(res->cmd_keyword, "gso") &&
4760                         !strcmp(res->cmd_segsz, "segsz")) {
4761                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4762                         printf("gso_size should be larger than %zu."
4763                                         " Please input a legal value\n",
4764                                         RTE_GSO_SEG_SIZE_MIN);
4765                 else
4766                         gso_max_segment_size = res->cmd_size;
4767         }
4768 }
4769
4770 cmdline_parse_token_string_t cmd_gso_size_set =
4771         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4772                                 cmd_set, "set");
4773 cmdline_parse_token_string_t cmd_gso_size_keyword =
4774         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4775                                 cmd_keyword, "gso");
4776 cmdline_parse_token_string_t cmd_gso_size_segsz =
4777         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4778                                 cmd_segsz, "segsz");
4779 cmdline_parse_token_num_t cmd_gso_size_size =
4780         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4781                                 cmd_size, UINT16);
4782
4783 cmdline_parse_inst_t cmd_gso_size = {
4784         .f = cmd_gso_size_parsed,
4785         .data = NULL,
4786         .help_str = "set gso segsz <length>",
4787         .tokens = {
4788                 (void *)&cmd_gso_size_set,
4789                 (void *)&cmd_gso_size_keyword,
4790                 (void *)&cmd_gso_size_segsz,
4791                 (void *)&cmd_gso_size_size,
4792                 NULL,
4793         },
4794 };
4795
4796 /* *** SHOW GSO CONFIGURATION *** */
4797 struct cmd_gso_show_result {
4798         cmdline_fixed_string_t cmd_show;
4799         cmdline_fixed_string_t cmd_port;
4800         cmdline_fixed_string_t cmd_keyword;
4801         portid_t cmd_pid;
4802 };
4803
4804 static void
4805 cmd_gso_show_parsed(void *parsed_result,
4806                        __attribute__((unused)) struct cmdline *cl,
4807                        __attribute__((unused)) void *data)
4808 {
4809         struct cmd_gso_show_result *res = parsed_result;
4810
4811         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4812                 printf("invalid port id %u\n", res->cmd_pid);
4813                 return;
4814         }
4815         if (!strcmp(res->cmd_keyword, "gso")) {
4816                 if (gso_ports[res->cmd_pid].enable) {
4817                         printf("Max GSO'd packet size: %uB\n"
4818                                         "Supported GSO types: TCP/IPv4, "
4819                                         "UDP/IPv4, VxLAN with inner "
4820                                         "TCP/IPv4 packet, GRE with inner "
4821                                         "TCP/IPv4 packet\n",
4822                                         gso_max_segment_size);
4823                 } else
4824                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4825         }
4826 }
4827
4828 cmdline_parse_token_string_t cmd_gso_show_show =
4829 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4830                 cmd_show, "show");
4831 cmdline_parse_token_string_t cmd_gso_show_port =
4832 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4833                 cmd_port, "port");
4834 cmdline_parse_token_string_t cmd_gso_show_keyword =
4835         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4836                                 cmd_keyword, "gso");
4837 cmdline_parse_token_num_t cmd_gso_show_pid =
4838         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4839                                 cmd_pid, UINT16);
4840
4841 cmdline_parse_inst_t cmd_gso_show = {
4842         .f = cmd_gso_show_parsed,
4843         .data = NULL,
4844         .help_str = "show port <port_id> gso",
4845         .tokens = {
4846                 (void *)&cmd_gso_show_show,
4847                 (void *)&cmd_gso_show_port,
4848                 (void *)&cmd_gso_show_pid,
4849                 (void *)&cmd_gso_show_keyword,
4850                 NULL,
4851         },
4852 };
4853
4854 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4855 struct cmd_set_flush_rx {
4856         cmdline_fixed_string_t set;
4857         cmdline_fixed_string_t flush_rx;
4858         cmdline_fixed_string_t mode;
4859 };
4860
4861 static void
4862 cmd_set_flush_rx_parsed(void *parsed_result,
4863                 __attribute__((unused)) struct cmdline *cl,
4864                 __attribute__((unused)) void *data)
4865 {
4866         struct cmd_set_flush_rx *res = parsed_result;
4867         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4868 }
4869
4870 cmdline_parse_token_string_t cmd_setflushrx_set =
4871         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4872                         set, "set");
4873 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4874         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4875                         flush_rx, "flush_rx");
4876 cmdline_parse_token_string_t cmd_setflushrx_mode =
4877         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4878                         mode, "on#off");
4879
4880
4881 cmdline_parse_inst_t cmd_set_flush_rx = {
4882         .f = cmd_set_flush_rx_parsed,
4883         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4884         .data = NULL,
4885         .tokens = {
4886                 (void *)&cmd_setflushrx_set,
4887                 (void *)&cmd_setflushrx_flush_rx,
4888                 (void *)&cmd_setflushrx_mode,
4889                 NULL,
4890         },
4891 };
4892
4893 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4894 struct cmd_set_link_check {
4895         cmdline_fixed_string_t set;
4896         cmdline_fixed_string_t link_check;
4897         cmdline_fixed_string_t mode;
4898 };
4899
4900 static void
4901 cmd_set_link_check_parsed(void *parsed_result,
4902                 __attribute__((unused)) struct cmdline *cl,
4903                 __attribute__((unused)) void *data)
4904 {
4905         struct cmd_set_link_check *res = parsed_result;
4906         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4907 }
4908
4909 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4910         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4911                         set, "set");
4912 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4913         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4914                         link_check, "link_check");
4915 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4916         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4917                         mode, "on#off");
4918
4919
4920 cmdline_parse_inst_t cmd_set_link_check = {
4921         .f = cmd_set_link_check_parsed,
4922         .help_str = "set link_check on|off: Enable/Disable link status check "
4923                     "when starting/stopping a port",
4924         .data = NULL,
4925         .tokens = {
4926                 (void *)&cmd_setlinkcheck_set,
4927                 (void *)&cmd_setlinkcheck_link_check,
4928                 (void *)&cmd_setlinkcheck_mode,
4929                 NULL,
4930         },
4931 };
4932
4933 /* *** SET NIC BYPASS MODE *** */
4934 struct cmd_set_bypass_mode_result {
4935         cmdline_fixed_string_t set;
4936         cmdline_fixed_string_t bypass;
4937         cmdline_fixed_string_t mode;
4938         cmdline_fixed_string_t value;
4939         portid_t port_id;
4940 };
4941
4942 static void
4943 cmd_set_bypass_mode_parsed(void *parsed_result,
4944                 __attribute__((unused)) struct cmdline *cl,
4945                 __attribute__((unused)) void *data)
4946 {
4947         struct cmd_set_bypass_mode_result *res = parsed_result;
4948         portid_t port_id = res->port_id;
4949         int32_t rc = -EINVAL;
4950
4951 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4952         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4953
4954         if (!strcmp(res->value, "bypass"))
4955                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4956         else if (!strcmp(res->value, "isolate"))
4957                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4958         else
4959                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4960
4961         /* Set the bypass mode for the relevant port. */
4962         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4963 #endif
4964         if (rc != 0)
4965                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4966 }
4967
4968 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4969         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4970                         set, "set");
4971 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4972         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4973                         bypass, "bypass");
4974 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4975         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4976                         mode, "mode");
4977 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4978         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4979                         value, "normal#bypass#isolate");
4980 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4981         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4982                                 port_id, UINT16);
4983
4984 cmdline_parse_inst_t cmd_set_bypass_mode = {
4985         .f = cmd_set_bypass_mode_parsed,
4986         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4987                     "Set the NIC bypass mode for port_id",
4988         .data = NULL,
4989         .tokens = {
4990                 (void *)&cmd_setbypass_mode_set,
4991                 (void *)&cmd_setbypass_mode_bypass,
4992                 (void *)&cmd_setbypass_mode_mode,
4993                 (void *)&cmd_setbypass_mode_value,
4994                 (void *)&cmd_setbypass_mode_port,
4995                 NULL,
4996         },
4997 };
4998
4999 /* *** SET NIC BYPASS EVENT *** */
5000 struct cmd_set_bypass_event_result {
5001         cmdline_fixed_string_t set;
5002         cmdline_fixed_string_t bypass;
5003         cmdline_fixed_string_t event;
5004         cmdline_fixed_string_t event_value;
5005         cmdline_fixed_string_t mode;
5006         cmdline_fixed_string_t mode_value;
5007         portid_t port_id;
5008 };
5009
5010 static void
5011 cmd_set_bypass_event_parsed(void *parsed_result,
5012                 __attribute__((unused)) struct cmdline *cl,
5013                 __attribute__((unused)) void *data)
5014 {
5015         int32_t rc = -EINVAL;
5016         struct cmd_set_bypass_event_result *res = parsed_result;
5017         portid_t port_id = res->port_id;
5018
5019 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5020         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5021         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5022
5023         if (!strcmp(res->event_value, "timeout"))
5024                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5025         else if (!strcmp(res->event_value, "os_on"))
5026                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5027         else if (!strcmp(res->event_value, "os_off"))
5028                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5029         else if (!strcmp(res->event_value, "power_on"))
5030                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5031         else if (!strcmp(res->event_value, "power_off"))
5032                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5033         else
5034                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5035
5036         if (!strcmp(res->mode_value, "bypass"))
5037                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5038         else if (!strcmp(res->mode_value, "isolate"))
5039                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5040         else
5041                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5042
5043         /* Set the watchdog timeout. */
5044         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5045
5046                 rc = -EINVAL;
5047                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5048                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5049                                                            bypass_timeout);
5050                 }
5051                 if (rc != 0) {
5052                         printf("Failed to set timeout value %u "
5053                         "for port %d, errto code: %d.\n",
5054                         bypass_timeout, port_id, rc);
5055                 }
5056         }
5057
5058         /* Set the bypass event to transition to bypass mode. */
5059         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5060                                               bypass_mode);
5061 #endif
5062
5063         if (rc != 0)
5064                 printf("\t Failed to set bypass event for port = %d.\n",
5065                        port_id);
5066 }
5067
5068 cmdline_parse_token_string_t cmd_setbypass_event_set =
5069         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5070                         set, "set");
5071 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5072         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5073                         bypass, "bypass");
5074 cmdline_parse_token_string_t cmd_setbypass_event_event =
5075         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5076                         event, "event");
5077 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5078         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5079                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5080 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5081         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5082                         mode, "mode");
5083 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5084         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5085                         mode_value, "normal#bypass#isolate");
5086 cmdline_parse_token_num_t cmd_setbypass_event_port =
5087         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5088                                 port_id, UINT16);
5089
5090 cmdline_parse_inst_t cmd_set_bypass_event = {
5091         .f = cmd_set_bypass_event_parsed,
5092         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5093                 "power_off mode normal|bypass|isolate <port_id>: "
5094                 "Set the NIC bypass event mode for port_id",
5095         .data = NULL,
5096         .tokens = {
5097                 (void *)&cmd_setbypass_event_set,
5098                 (void *)&cmd_setbypass_event_bypass,
5099                 (void *)&cmd_setbypass_event_event,
5100                 (void *)&cmd_setbypass_event_event_value,
5101                 (void *)&cmd_setbypass_event_mode,
5102                 (void *)&cmd_setbypass_event_mode_value,
5103                 (void *)&cmd_setbypass_event_port,
5104                 NULL,
5105         },
5106 };
5107
5108
5109 /* *** SET NIC BYPASS TIMEOUT *** */
5110 struct cmd_set_bypass_timeout_result {
5111         cmdline_fixed_string_t set;
5112         cmdline_fixed_string_t bypass;
5113         cmdline_fixed_string_t timeout;
5114         cmdline_fixed_string_t value;
5115 };
5116
5117 static void
5118 cmd_set_bypass_timeout_parsed(void *parsed_result,
5119                 __attribute__((unused)) struct cmdline *cl,
5120                 __attribute__((unused)) void *data)
5121 {
5122         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5123
5124 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5125         if (!strcmp(res->value, "1.5"))
5126                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5127         else if (!strcmp(res->value, "2"))
5128                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5129         else if (!strcmp(res->value, "3"))
5130                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5131         else if (!strcmp(res->value, "4"))
5132                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5133         else if (!strcmp(res->value, "8"))
5134                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5135         else if (!strcmp(res->value, "16"))
5136                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5137         else if (!strcmp(res->value, "32"))
5138                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5139         else
5140                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5141 #endif
5142 }
5143
5144 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5145         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5146                         set, "set");
5147 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5148         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5149                         bypass, "bypass");
5150 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5151         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5152                         timeout, "timeout");
5153 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5154         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5155                         value, "0#1.5#2#3#4#8#16#32");
5156
5157 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5158         .f = cmd_set_bypass_timeout_parsed,
5159         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5160                 "Set the NIC bypass watchdog timeout in seconds",
5161         .data = NULL,
5162         .tokens = {
5163                 (void *)&cmd_setbypass_timeout_set,
5164                 (void *)&cmd_setbypass_timeout_bypass,
5165                 (void *)&cmd_setbypass_timeout_timeout,
5166                 (void *)&cmd_setbypass_timeout_value,
5167                 NULL,
5168         },
5169 };
5170
5171 /* *** SHOW NIC BYPASS MODE *** */
5172 struct cmd_show_bypass_config_result {
5173         cmdline_fixed_string_t show;
5174         cmdline_fixed_string_t bypass;
5175         cmdline_fixed_string_t config;
5176         portid_t port_id;
5177 };
5178
5179 static void
5180 cmd_show_bypass_config_parsed(void *parsed_result,
5181                 __attribute__((unused)) struct cmdline *cl,
5182                 __attribute__((unused)) void *data)
5183 {
5184         struct cmd_show_bypass_config_result *res = parsed_result;
5185         portid_t port_id = res->port_id;
5186         int rc = -EINVAL;
5187 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5188         uint32_t event_mode;
5189         uint32_t bypass_mode;
5190         uint32_t timeout = bypass_timeout;
5191         int i;
5192
5193         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5194                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5195         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5196                 {"UNKNOWN", "normal", "bypass", "isolate"};
5197         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5198                 "NONE",
5199                 "OS/board on",
5200                 "power supply on",
5201                 "OS/board off",
5202                 "power supply off",
5203                 "timeout"};
5204         int num_events = (sizeof events) / (sizeof events[0]);
5205
5206         /* Display the bypass mode.*/
5207         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5208                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5209                 return;
5210         }
5211         else {
5212                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5213                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5214
5215                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5216         }
5217
5218         /* Display the bypass timeout.*/
5219         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5220                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5221
5222         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5223
5224         /* Display the bypass events and associated modes. */
5225         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5226
5227                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5228                         printf("\tFailed to get bypass mode for event = %s\n",
5229                                 events[i]);
5230                 } else {
5231                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5232                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5233
5234                         printf("\tbypass event: %-16s = %s\n", events[i],
5235                                 modes[event_mode]);
5236                 }
5237         }
5238 #endif
5239         if (rc != 0)
5240                 printf("\tFailed to get bypass configuration for port = %d\n",
5241                        port_id);
5242 }
5243
5244 cmdline_parse_token_string_t cmd_showbypass_config_show =
5245         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5246                         show, "show");
5247 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5248         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5249                         bypass, "bypass");
5250 cmdline_parse_token_string_t cmd_showbypass_config_config =
5251         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5252                         config, "config");
5253 cmdline_parse_token_num_t cmd_showbypass_config_port =
5254         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5255                                 port_id, UINT16);
5256
5257 cmdline_parse_inst_t cmd_show_bypass_config = {
5258         .f = cmd_show_bypass_config_parsed,
5259         .help_str = "show bypass config <port_id>: "
5260                     "Show the NIC bypass config for port_id",
5261         .data = NULL,
5262         .tokens = {
5263                 (void *)&cmd_showbypass_config_show,
5264                 (void *)&cmd_showbypass_config_bypass,
5265                 (void *)&cmd_showbypass_config_config,
5266                 (void *)&cmd_showbypass_config_port,
5267                 NULL,
5268         },
5269 };
5270
5271 #ifdef RTE_LIBRTE_PMD_BOND
5272 /* *** SET BONDING MODE *** */
5273 struct cmd_set_bonding_mode_result {
5274         cmdline_fixed_string_t set;
5275         cmdline_fixed_string_t bonding;
5276         cmdline_fixed_string_t mode;
5277         uint8_t value;
5278         portid_t port_id;
5279 };
5280
5281 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5282                 __attribute__((unused))  struct cmdline *cl,
5283                 __attribute__((unused)) void *data)
5284 {
5285         struct cmd_set_bonding_mode_result *res = parsed_result;
5286         portid_t port_id = res->port_id;
5287
5288         /* Set the bonding mode for the relevant port. */
5289         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5290                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5291 }
5292
5293 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5294 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5295                 set, "set");
5296 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5297 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5298                 bonding, "bonding");
5299 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5300 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5301                 mode, "mode");
5302 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5303 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5304                 value, UINT8);
5305 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5306 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5307                 port_id, UINT16);
5308
5309 cmdline_parse_inst_t cmd_set_bonding_mode = {
5310                 .f = cmd_set_bonding_mode_parsed,
5311                 .help_str = "set bonding mode <mode_value> <port_id>: "
5312                         "Set the bonding mode for port_id",
5313                 .data = NULL,
5314                 .tokens = {
5315                                 (void *) &cmd_setbonding_mode_set,
5316                                 (void *) &cmd_setbonding_mode_bonding,
5317                                 (void *) &cmd_setbonding_mode_mode,
5318                                 (void *) &cmd_setbonding_mode_value,
5319                                 (void *) &cmd_setbonding_mode_port,
5320                                 NULL
5321                 }
5322 };
5323
5324 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5325 struct cmd_set_bonding_lacp_dedicated_queues_result {
5326         cmdline_fixed_string_t set;
5327         cmdline_fixed_string_t bonding;
5328         cmdline_fixed_string_t lacp;
5329         cmdline_fixed_string_t dedicated_queues;
5330         portid_t port_id;
5331         cmdline_fixed_string_t mode;
5332 };
5333
5334 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5335                 __attribute__((unused))  struct cmdline *cl,
5336                 __attribute__((unused)) void *data)
5337 {
5338         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5339         portid_t port_id = res->port_id;
5340         struct rte_port *port;
5341
5342         port = &ports[port_id];
5343
5344         /** Check if the port is not started **/
5345         if (port->port_status != RTE_PORT_STOPPED) {
5346                 printf("Please stop port %d first\n", port_id);
5347                 return;
5348         }
5349
5350         if (!strcmp(res->mode, "enable")) {
5351                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5352                         printf("Dedicate queues for LACP control packets"
5353                                         " enabled\n");
5354                 else
5355                         printf("Enabling dedicate queues for LACP control "
5356                                         "packets on port %d failed\n", port_id);
5357         } else if (!strcmp(res->mode, "disable")) {
5358                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5359                         printf("Dedicated queues for LACP control packets "
5360                                         "disabled\n");
5361                 else
5362                         printf("Disabling dedicated queues for LACP control "
5363                                         "traffic on port %d failed\n", port_id);
5364         }
5365 }
5366
5367 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5368 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5369                 set, "set");
5370 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5371 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5372                 bonding, "bonding");
5373 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5374 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5375                 lacp, "lacp");
5376 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5377 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5378                 dedicated_queues, "dedicated_queues");
5379 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5380 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5381                 port_id, UINT16);
5382 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5383 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5384                 mode, "enable#disable");
5385
5386 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5387                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5388                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5389                         "enable|disable: "
5390                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5391                 .data = NULL,
5392                 .tokens = {
5393                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5394                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5395                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5396                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5397                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5398                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5399                         NULL
5400                 }
5401 };
5402
5403 /* *** SET BALANCE XMIT POLICY *** */
5404 struct cmd_set_bonding_balance_xmit_policy_result {
5405         cmdline_fixed_string_t set;
5406         cmdline_fixed_string_t bonding;
5407         cmdline_fixed_string_t balance_xmit_policy;
5408         portid_t port_id;
5409         cmdline_fixed_string_t policy;
5410 };
5411
5412 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5413                 __attribute__((unused))  struct cmdline *cl,
5414                 __attribute__((unused)) void *data)
5415 {
5416         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5417         portid_t port_id = res->port_id;
5418         uint8_t policy;
5419
5420         if (!strcmp(res->policy, "l2")) {
5421                 policy = BALANCE_XMIT_POLICY_LAYER2;
5422         } else if (!strcmp(res->policy, "l23")) {
5423                 policy = BALANCE_XMIT_POLICY_LAYER23;
5424         } else if (!strcmp(res->policy, "l34")) {
5425                 policy = BALANCE_XMIT_POLICY_LAYER34;
5426         } else {
5427                 printf("\t Invalid xmit policy selection");
5428                 return;
5429         }
5430
5431         /* Set the bonding mode for the relevant port. */
5432         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5433                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5434                                 port_id);
5435         }
5436 }
5437
5438 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5439 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5440                 set, "set");
5441 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5442 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5443                 bonding, "bonding");
5444 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5445 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5446                 balance_xmit_policy, "balance_xmit_policy");
5447 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5448 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5449                 port_id, UINT16);
5450 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5451 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5452                 policy, "l2#l23#l34");
5453
5454 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5455                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5456                 .help_str = "set bonding balance_xmit_policy <port_id> "
5457                         "l2|l23|l34: "
5458                         "Set the bonding balance_xmit_policy for port_id",
5459                 .data = NULL,
5460                 .tokens = {
5461                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5462                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5463                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5464                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5465                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5466                                 NULL
5467                 }
5468 };
5469
5470 /* *** SHOW NIC BONDING CONFIGURATION *** */
5471 struct cmd_show_bonding_config_result {
5472         cmdline_fixed_string_t show;
5473         cmdline_fixed_string_t bonding;
5474         cmdline_fixed_string_t config;
5475         portid_t port_id;
5476 };
5477
5478 static void cmd_show_bonding_config_parsed(void *parsed_result,
5479                 __attribute__((unused))  struct cmdline *cl,
5480                 __attribute__((unused)) void *data)
5481 {
5482         struct cmd_show_bonding_config_result *res = parsed_result;
5483         int bonding_mode, agg_mode;
5484         portid_t slaves[RTE_MAX_ETHPORTS];
5485         int num_slaves, num_active_slaves;
5486         int primary_id;
5487         int i;
5488         portid_t port_id = res->port_id;
5489
5490         /* Display the bonding mode.*/
5491         bonding_mode = rte_eth_bond_mode_get(port_id);
5492         if (bonding_mode < 0) {
5493                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5494                 return;
5495         } else
5496                 printf("\tBonding mode: %d\n", bonding_mode);
5497
5498         if (bonding_mode == BONDING_MODE_BALANCE) {
5499                 int balance_xmit_policy;
5500
5501                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5502                 if (balance_xmit_policy < 0) {
5503                         printf("\tFailed to get balance xmit policy for port = %d\n",
5504                                         port_id);
5505                         return;
5506                 } else {
5507                         printf("\tBalance Xmit Policy: ");
5508
5509                         switch (balance_xmit_policy) {
5510                         case BALANCE_XMIT_POLICY_LAYER2:
5511                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5512                                 break;
5513                         case BALANCE_XMIT_POLICY_LAYER23:
5514                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5515                                 break;
5516                         case BALANCE_XMIT_POLICY_LAYER34:
5517                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5518                                 break;
5519                         }
5520                         printf("\n");
5521                 }
5522         }
5523
5524         if (bonding_mode == BONDING_MODE_8023AD) {
5525                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5526                 printf("\tIEEE802.3AD Aggregator Mode: ");
5527                 switch (agg_mode) {
5528                 case AGG_BANDWIDTH:
5529                         printf("bandwidth");
5530                         break;
5531                 case AGG_STABLE:
5532                         printf("stable");
5533                         break;
5534                 case AGG_COUNT:
5535                         printf("count");
5536                         break;
5537                 }
5538                 printf("\n");
5539         }
5540
5541         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5542
5543         if (num_slaves < 0) {
5544                 printf("\tFailed to get slave list for port = %d\n", port_id);
5545                 return;
5546         }
5547         if (num_slaves > 0) {
5548                 printf("\tSlaves (%d): [", num_slaves);
5549                 for (i = 0; i < num_slaves - 1; i++)
5550                         printf("%d ", slaves[i]);
5551
5552                 printf("%d]\n", slaves[num_slaves - 1]);
5553         } else {
5554                 printf("\tSlaves: []\n");
5555
5556         }
5557
5558         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5559                         RTE_MAX_ETHPORTS);
5560
5561         if (num_active_slaves < 0) {
5562                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5563                 return;
5564         }
5565         if (num_active_slaves > 0) {
5566                 printf("\tActive Slaves (%d): [", num_active_slaves);
5567                 for (i = 0; i < num_active_slaves - 1; i++)
5568                         printf("%d ", slaves[i]);
5569
5570                 printf("%d]\n", slaves[num_active_slaves - 1]);
5571
5572         } else {
5573                 printf("\tActive Slaves: []\n");
5574
5575         }
5576
5577         primary_id = rte_eth_bond_primary_get(port_id);
5578         if (primary_id < 0) {
5579                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5580                 return;
5581         } else
5582                 printf("\tPrimary: [%d]\n", primary_id);
5583
5584 }
5585
5586 cmdline_parse_token_string_t cmd_showbonding_config_show =
5587 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5588                 show, "show");
5589 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5590 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5591                 bonding, "bonding");
5592 cmdline_parse_token_string_t cmd_showbonding_config_config =
5593 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5594                 config, "config");
5595 cmdline_parse_token_num_t cmd_showbonding_config_port =
5596 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5597                 port_id, UINT16);
5598
5599 cmdline_parse_inst_t cmd_show_bonding_config = {
5600                 .f = cmd_show_bonding_config_parsed,
5601                 .help_str = "show bonding config <port_id>: "
5602                         "Show the bonding config for port_id",
5603                 .data = NULL,
5604                 .tokens = {
5605                                 (void *)&cmd_showbonding_config_show,
5606                                 (void *)&cmd_showbonding_config_bonding,
5607                                 (void *)&cmd_showbonding_config_config,
5608                                 (void *)&cmd_showbonding_config_port,
5609                                 NULL
5610                 }
5611 };
5612
5613 /* *** SET BONDING PRIMARY *** */
5614 struct cmd_set_bonding_primary_result {
5615         cmdline_fixed_string_t set;
5616         cmdline_fixed_string_t bonding;
5617         cmdline_fixed_string_t primary;
5618         portid_t slave_id;
5619         portid_t port_id;
5620 };
5621
5622 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5623                 __attribute__((unused))  struct cmdline *cl,
5624                 __attribute__((unused)) void *data)
5625 {
5626         struct cmd_set_bonding_primary_result *res = parsed_result;
5627         portid_t master_port_id = res->port_id;
5628         portid_t slave_port_id = res->slave_id;
5629
5630         /* Set the primary slave for a bonded device. */
5631         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5632                 printf("\t Failed to set primary slave for port = %d.\n",
5633                                 master_port_id);
5634                 return;
5635         }
5636         init_port_config();
5637 }
5638
5639 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5640 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5641                 set, "set");
5642 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5643 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5644                 bonding, "bonding");
5645 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5646 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5647                 primary, "primary");
5648 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5649 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5650                 slave_id, UINT16);
5651 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5652 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5653                 port_id, UINT16);
5654
5655 cmdline_parse_inst_t cmd_set_bonding_primary = {
5656                 .f = cmd_set_bonding_primary_parsed,
5657                 .help_str = "set bonding primary <slave_id> <port_id>: "
5658                         "Set the primary slave for port_id",
5659                 .data = NULL,
5660                 .tokens = {
5661                                 (void *)&cmd_setbonding_primary_set,
5662                                 (void *)&cmd_setbonding_primary_bonding,
5663                                 (void *)&cmd_setbonding_primary_primary,
5664                                 (void *)&cmd_setbonding_primary_slave,
5665                                 (void *)&cmd_setbonding_primary_port,
5666                                 NULL
5667                 }
5668 };
5669
5670 /* *** ADD SLAVE *** */
5671 struct cmd_add_bonding_slave_result {
5672         cmdline_fixed_string_t add;
5673         cmdline_fixed_string_t bonding;
5674         cmdline_fixed_string_t slave;
5675         portid_t slave_id;
5676         portid_t port_id;
5677 };
5678
5679 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5680                 __attribute__((unused))  struct cmdline *cl,
5681                 __attribute__((unused)) void *data)
5682 {
5683         struct cmd_add_bonding_slave_result *res = parsed_result;
5684         portid_t master_port_id = res->port_id;
5685         portid_t slave_port_id = res->slave_id;
5686
5687         /* add the slave for a bonded device. */
5688         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5689                 printf("\t Failed to add slave %d to master port = %d.\n",
5690                                 slave_port_id, master_port_id);
5691                 return;
5692         }
5693         init_port_config();
5694         set_port_slave_flag(slave_port_id);
5695 }
5696
5697 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5698 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5699                 add, "add");
5700 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5701 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5702                 bonding, "bonding");
5703 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5704 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5705                 slave, "slave");
5706 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5707 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5708                 slave_id, UINT16);
5709 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5710 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5711                 port_id, UINT16);
5712
5713 cmdline_parse_inst_t cmd_add_bonding_slave = {
5714                 .f = cmd_add_bonding_slave_parsed,
5715                 .help_str = "add bonding slave <slave_id> <port_id>: "
5716                         "Add a slave device to a bonded device",
5717                 .data = NULL,
5718                 .tokens = {
5719                                 (void *)&cmd_addbonding_slave_add,
5720                                 (void *)&cmd_addbonding_slave_bonding,
5721                                 (void *)&cmd_addbonding_slave_slave,
5722                                 (void *)&cmd_addbonding_slave_slaveid,
5723                                 (void *)&cmd_addbonding_slave_port,
5724                                 NULL
5725                 }
5726 };
5727
5728 /* *** REMOVE SLAVE *** */
5729 struct cmd_remove_bonding_slave_result {
5730         cmdline_fixed_string_t remove;
5731         cmdline_fixed_string_t bonding;
5732         cmdline_fixed_string_t slave;
5733         portid_t slave_id;
5734         portid_t port_id;
5735 };
5736
5737 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5738                 __attribute__((unused))  struct cmdline *cl,
5739                 __attribute__((unused)) void *data)
5740 {
5741         struct cmd_remove_bonding_slave_result *res = parsed_result;
5742         portid_t master_port_id = res->port_id;
5743         portid_t slave_port_id = res->slave_id;
5744
5745         /* remove the slave from a bonded device. */
5746         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5747                 printf("\t Failed to remove slave %d from master port = %d.\n",
5748                                 slave_port_id, master_port_id);
5749                 return;
5750         }
5751         init_port_config();
5752         clear_port_slave_flag(slave_port_id);
5753 }
5754
5755 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5756                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5757                                 remove, "remove");
5758 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5759                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5760                                 bonding, "bonding");
5761 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5762                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5763                                 slave, "slave");
5764 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5765                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5766                                 slave_id, UINT16);
5767 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5768                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5769                                 port_id, UINT16);
5770
5771 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5772                 .f = cmd_remove_bonding_slave_parsed,
5773                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5774                         "Remove a slave device from a bonded device",
5775                 .data = NULL,
5776                 .tokens = {
5777                                 (void *)&cmd_removebonding_slave_remove,
5778                                 (void *)&cmd_removebonding_slave_bonding,
5779                                 (void *)&cmd_removebonding_slave_slave,
5780                                 (void *)&cmd_removebonding_slave_slaveid,
5781                                 (void *)&cmd_removebonding_slave_port,
5782                                 NULL
5783                 }
5784 };
5785
5786 /* *** CREATE BONDED DEVICE *** */
5787 struct cmd_create_bonded_device_result {
5788         cmdline_fixed_string_t create;
5789         cmdline_fixed_string_t bonded;
5790         cmdline_fixed_string_t device;
5791         uint8_t mode;
5792         uint8_t socket;
5793 };
5794
5795 static int bond_dev_num = 0;
5796
5797 static void cmd_create_bonded_device_parsed(void *parsed_result,
5798                 __attribute__((unused))  struct cmdline *cl,
5799                 __attribute__((unused)) void *data)
5800 {
5801         struct cmd_create_bonded_device_result *res = parsed_result;
5802         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5803         int port_id;
5804
5805         if (test_done == 0) {
5806                 printf("Please stop forwarding first\n");
5807                 return;
5808         }
5809
5810         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5811                         bond_dev_num++);
5812
5813         /* Create a new bonded device. */
5814         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5815         if (port_id < 0) {
5816                 printf("\t Failed to create bonded device.\n");
5817                 return;
5818         } else {
5819                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5820                                 port_id);
5821
5822                 /* Update number of ports */
5823                 nb_ports = rte_eth_dev_count_avail();
5824                 reconfig(port_id, res->socket);
5825                 rte_eth_promiscuous_enable(port_id);
5826         }
5827
5828 }
5829
5830 cmdline_parse_token_string_t cmd_createbonded_device_create =
5831                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5832                                 create, "create");
5833 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5834                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5835                                 bonded, "bonded");
5836 cmdline_parse_token_string_t cmd_createbonded_device_device =
5837                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5838                                 device, "device");
5839 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5840                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5841                                 mode, UINT8);
5842 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5843                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5844                                 socket, UINT8);
5845
5846 cmdline_parse_inst_t cmd_create_bonded_device = {
5847                 .f = cmd_create_bonded_device_parsed,
5848                 .help_str = "create bonded device <mode> <socket>: "
5849                         "Create a new bonded device with specific bonding mode and socket",
5850                 .data = NULL,
5851                 .tokens = {
5852                                 (void *)&cmd_createbonded_device_create,
5853                                 (void *)&cmd_createbonded_device_bonded,
5854                                 (void *)&cmd_createbonded_device_device,
5855                                 (void *)&cmd_createbonded_device_mode,
5856                                 (void *)&cmd_createbonded_device_socket,
5857                                 NULL
5858                 }
5859 };
5860
5861 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5862 struct cmd_set_bond_mac_addr_result {
5863         cmdline_fixed_string_t set;
5864         cmdline_fixed_string_t bonding;
5865         cmdline_fixed_string_t mac_addr;
5866         uint16_t port_num;
5867         struct ether_addr address;
5868 };
5869
5870 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5871                 __attribute__((unused))  struct cmdline *cl,
5872                 __attribute__((unused)) void *data)
5873 {
5874         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5875         int ret;
5876
5877         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5878                 return;
5879
5880         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5881
5882         /* check the return value and print it if is < 0 */
5883         if (ret < 0)
5884                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5885 }
5886
5887 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5888                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5889 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5890                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5891                                 "bonding");
5892 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5893                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5894                                 "mac_addr");
5895 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5896                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5897                                 port_num, UINT16);
5898 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5899                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5900
5901 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5902                 .f = cmd_set_bond_mac_addr_parsed,
5903                 .data = (void *) 0,
5904                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5905                 .tokens = {
5906                                 (void *)&cmd_set_bond_mac_addr_set,
5907                                 (void *)&cmd_set_bond_mac_addr_bonding,
5908                                 (void *)&cmd_set_bond_mac_addr_mac,
5909                                 (void *)&cmd_set_bond_mac_addr_portnum,
5910                                 (void *)&cmd_set_bond_mac_addr_addr,
5911                                 NULL
5912                 }
5913 };
5914
5915
5916 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5917 struct cmd_set_bond_mon_period_result {
5918         cmdline_fixed_string_t set;
5919         cmdline_fixed_string_t bonding;
5920         cmdline_fixed_string_t mon_period;
5921         uint16_t port_num;
5922         uint32_t period_ms;
5923 };
5924
5925 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5926                 __attribute__((unused))  struct cmdline *cl,
5927                 __attribute__((unused)) void *data)
5928 {
5929         struct cmd_set_bond_mon_period_result *res = parsed_result;
5930         int ret;
5931
5932         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5933
5934         /* check the return value and print it if is < 0 */
5935         if (ret < 0)
5936                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5937 }
5938
5939 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5940                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5941                                 set, "set");
5942 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5943                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5944                                 bonding, "bonding");
5945 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5946                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5947                                 mon_period,     "mon_period");
5948 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5949                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5950                                 port_num, UINT16);
5951 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5952                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5953                                 period_ms, UINT32);
5954
5955 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5956                 .f = cmd_set_bond_mon_period_parsed,
5957                 .data = (void *) 0,
5958                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5959                 .tokens = {
5960                                 (void *)&cmd_set_bond_mon_period_set,
5961                                 (void *)&cmd_set_bond_mon_period_bonding,
5962                                 (void *)&cmd_set_bond_mon_period_mon_period,
5963                                 (void *)&cmd_set_bond_mon_period_portnum,
5964                                 (void *)&cmd_set_bond_mon_period_period_ms,
5965                                 NULL
5966                 }
5967 };
5968
5969
5970
5971 struct cmd_set_bonding_agg_mode_policy_result {
5972         cmdline_fixed_string_t set;
5973         cmdline_fixed_string_t bonding;
5974         cmdline_fixed_string_t agg_mode;
5975         uint16_t port_num;
5976         cmdline_fixed_string_t policy;
5977 };
5978
5979
5980 static void
5981 cmd_set_bonding_agg_mode(void *parsed_result,
5982                 __attribute__((unused)) struct cmdline *cl,
5983                 __attribute__((unused)) void *data)
5984 {
5985         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5986         uint8_t policy = AGG_BANDWIDTH;
5987
5988         if (!strcmp(res->policy, "bandwidth"))
5989                 policy = AGG_BANDWIDTH;
5990         else if (!strcmp(res->policy, "stable"))
5991                 policy = AGG_STABLE;
5992         else if (!strcmp(res->policy, "count"))
5993                 policy = AGG_COUNT;
5994
5995         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5996 }
5997
5998
5999 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6000         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6001                                 set, "set");
6002 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6003         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6004                                 bonding, "bonding");
6005
6006 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6007         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6008                                 agg_mode, "agg_mode");
6009
6010 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6011         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6012                                 port_num, UINT16);
6013
6014 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6015         TOKEN_STRING_INITIALIZER(
6016                         struct cmd_set_bonding_balance_xmit_policy_result,
6017                 policy, "stable#bandwidth#count");
6018
6019 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6020         .f = cmd_set_bonding_agg_mode,
6021         .data = (void *) 0,
6022         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6023         .tokens = {
6024                         (void *)&cmd_set_bonding_agg_mode_set,
6025                         (void *)&cmd_set_bonding_agg_mode_bonding,
6026                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6027                         (void *)&cmd_set_bonding_agg_mode_portnum,
6028                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6029                         NULL
6030                 }
6031 };
6032
6033
6034 #endif /* RTE_LIBRTE_PMD_BOND */
6035
6036 /* *** SET FORWARDING MODE *** */
6037 struct cmd_set_fwd_mode_result {
6038         cmdline_fixed_string_t set;
6039         cmdline_fixed_string_t fwd;
6040         cmdline_fixed_string_t mode;
6041 };
6042
6043 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6044                                     __attribute__((unused)) struct cmdline *cl,
6045                                     __attribute__((unused)) void *data)
6046 {
6047         struct cmd_set_fwd_mode_result *res = parsed_result;
6048
6049         retry_enabled = 0;
6050         set_pkt_forwarding_mode(res->mode);
6051 }
6052
6053 cmdline_parse_token_string_t cmd_setfwd_set =
6054         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6055 cmdline_parse_token_string_t cmd_setfwd_fwd =
6056         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6057 cmdline_parse_token_string_t cmd_setfwd_mode =
6058         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6059                 "" /* defined at init */);
6060
6061 cmdline_parse_inst_t cmd_set_fwd_mode = {
6062         .f = cmd_set_fwd_mode_parsed,
6063         .data = NULL,
6064         .help_str = NULL, /* defined at init */
6065         .tokens = {
6066                 (void *)&cmd_setfwd_set,
6067                 (void *)&cmd_setfwd_fwd,
6068                 (void *)&cmd_setfwd_mode,
6069                 NULL,
6070         },
6071 };
6072
6073 static void cmd_set_fwd_mode_init(void)
6074 {
6075         char *modes, *c;
6076         static char token[128];
6077         static char help[256];
6078         cmdline_parse_token_string_t *token_struct;
6079
6080         modes = list_pkt_forwarding_modes();
6081         snprintf(help, sizeof(help), "set fwd %s: "
6082                 "Set packet forwarding mode", modes);
6083         cmd_set_fwd_mode.help_str = help;
6084
6085         /* string token separator is # */
6086         for (c = token; *modes != '\0'; modes++)
6087                 if (*modes == '|')
6088                         *c++ = '#';
6089                 else
6090                         *c++ = *modes;
6091         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6092         token_struct->string_data.str = token;
6093 }
6094
6095 /* *** SET RETRY FORWARDING MODE *** */
6096 struct cmd_set_fwd_retry_mode_result {
6097         cmdline_fixed_string_t set;
6098         cmdline_fixed_string_t fwd;
6099         cmdline_fixed_string_t mode;
6100         cmdline_fixed_string_t retry;
6101 };
6102
6103 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6104                             __attribute__((unused)) struct cmdline *cl,
6105                             __attribute__((unused)) void *data)
6106 {
6107         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6108
6109         retry_enabled = 1;
6110         set_pkt_forwarding_mode(res->mode);
6111 }
6112
6113 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6114         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6115                         set, "set");
6116 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6117         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6118                         fwd, "fwd");
6119 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6120         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6121                         mode,
6122                 "" /* defined at init */);
6123 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6124         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6125                         retry, "retry");
6126
6127 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6128         .f = cmd_set_fwd_retry_mode_parsed,
6129         .data = NULL,
6130         .help_str = NULL, /* defined at init */
6131         .tokens = {
6132                 (void *)&cmd_setfwd_retry_set,
6133                 (void *)&cmd_setfwd_retry_fwd,
6134                 (void *)&cmd_setfwd_retry_mode,
6135                 (void *)&cmd_setfwd_retry_retry,
6136                 NULL,
6137         },
6138 };
6139
6140 static void cmd_set_fwd_retry_mode_init(void)
6141 {
6142         char *modes, *c;
6143         static char token[128];
6144         static char help[256];
6145         cmdline_parse_token_string_t *token_struct;
6146
6147         modes = list_pkt_forwarding_retry_modes();
6148         snprintf(help, sizeof(help), "set fwd %s retry: "
6149                 "Set packet forwarding mode with retry", modes);
6150         cmd_set_fwd_retry_mode.help_str = help;
6151
6152         /* string token separator is # */
6153         for (c = token; *modes != '\0'; modes++)
6154                 if (*modes == '|')
6155                         *c++ = '#';
6156                 else
6157                         *c++ = *modes;
6158         token_struct = (cmdline_parse_token_string_t *)
6159                 cmd_set_fwd_retry_mode.tokens[2];
6160         token_struct->string_data.str = token;
6161 }
6162
6163 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6164 struct cmd_set_burst_tx_retry_result {
6165         cmdline_fixed_string_t set;
6166         cmdline_fixed_string_t burst;
6167         cmdline_fixed_string_t tx;
6168         cmdline_fixed_string_t delay;
6169         uint32_t time;
6170         cmdline_fixed_string_t retry;
6171         uint32_t retry_num;
6172 };
6173
6174 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6175                                         __attribute__((unused)) struct cmdline *cl,
6176                                         __attribute__((unused)) void *data)
6177 {
6178         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6179
6180         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6181                 && !strcmp(res->tx, "tx")) {
6182                 if (!strcmp(res->delay, "delay"))
6183                         burst_tx_delay_time = res->time;
6184                 if (!strcmp(res->retry, "retry"))
6185                         burst_tx_retry_num = res->retry_num;
6186         }
6187
6188 }
6189
6190 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6191         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6192 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6193         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6194                                  "burst");
6195 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6196         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6197 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6198         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6199 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6200         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6201 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6202         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6203 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6204         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6205
6206 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6207         .f = cmd_set_burst_tx_retry_parsed,
6208         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6209         .tokens = {
6210                 (void *)&cmd_set_burst_tx_retry_set,
6211                 (void *)&cmd_set_burst_tx_retry_burst,
6212                 (void *)&cmd_set_burst_tx_retry_tx,
6213                 (void *)&cmd_set_burst_tx_retry_delay,
6214                 (void *)&cmd_set_burst_tx_retry_time,
6215                 (void *)&cmd_set_burst_tx_retry_retry,
6216                 (void *)&cmd_set_burst_tx_retry_retry_num,
6217                 NULL,
6218         },
6219 };
6220
6221 /* *** SET PROMISC MODE *** */
6222 struct cmd_set_promisc_mode_result {
6223         cmdline_fixed_string_t set;
6224         cmdline_fixed_string_t promisc;
6225         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6226         uint16_t port_num;               /* valid if "allports" argument == 0 */
6227         cmdline_fixed_string_t mode;
6228 };
6229
6230 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6231                                         __attribute__((unused)) struct cmdline *cl,
6232                                         void *allports)
6233 {
6234         struct cmd_set_promisc_mode_result *res = parsed_result;
6235         int enable;
6236         portid_t i;
6237
6238         if (!strcmp(res->mode, "on"))
6239                 enable = 1;
6240         else
6241                 enable = 0;
6242
6243         /* all ports */
6244         if (allports) {
6245                 RTE_ETH_FOREACH_DEV(i) {
6246                         if (enable)
6247                                 rte_eth_promiscuous_enable(i);
6248                         else
6249                                 rte_eth_promiscuous_disable(i);
6250                 }
6251         }
6252         else {
6253                 if (enable)
6254                         rte_eth_promiscuous_enable(res->port_num);
6255                 else
6256                         rte_eth_promiscuous_disable(res->port_num);
6257         }
6258 }
6259
6260 cmdline_parse_token_string_t cmd_setpromisc_set =
6261         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6262 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6263         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6264                                  "promisc");
6265 cmdline_parse_token_string_t cmd_setpromisc_portall =
6266         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6267                                  "all");
6268 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6269         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6270                               UINT16);
6271 cmdline_parse_token_string_t cmd_setpromisc_mode =
6272         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6273                                  "on#off");
6274
6275 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6276         .f = cmd_set_promisc_mode_parsed,
6277         .data = (void *)1,
6278         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6279         .tokens = {
6280                 (void *)&cmd_setpromisc_set,
6281                 (void *)&cmd_setpromisc_promisc,
6282                 (void *)&cmd_setpromisc_portall,
6283                 (void *)&cmd_setpromisc_mode,
6284                 NULL,
6285         },
6286 };
6287
6288 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6289         .f = cmd_set_promisc_mode_parsed,
6290         .data = (void *)0,
6291         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6292         .tokens = {
6293                 (void *)&cmd_setpromisc_set,
6294                 (void *)&cmd_setpromisc_promisc,
6295                 (void *)&cmd_setpromisc_portnum,
6296                 (void *)&cmd_setpromisc_mode,
6297                 NULL,
6298         },
6299 };
6300
6301 /* *** SET ALLMULTI MODE *** */
6302 struct cmd_set_allmulti_mode_result {
6303         cmdline_fixed_string_t set;
6304         cmdline_fixed_string_t allmulti;
6305         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6306         uint16_t port_num;               /* valid if "allports" argument == 0 */
6307         cmdline_fixed_string_t mode;
6308 };
6309
6310 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6311                                         __attribute__((unused)) struct cmdline *cl,
6312                                         void *allports)
6313 {
6314         struct cmd_set_allmulti_mode_result *res = parsed_result;
6315         int enable;
6316         portid_t i;
6317
6318         if (!strcmp(res->mode, "on"))
6319                 enable = 1;
6320         else
6321                 enable = 0;
6322
6323         /* all ports */
6324         if (allports) {
6325                 RTE_ETH_FOREACH_DEV(i) {
6326                         if (enable)
6327                                 rte_eth_allmulticast_enable(i);
6328                         else
6329                                 rte_eth_allmulticast_disable(i);
6330                 }
6331         }
6332         else {
6333                 if (enable)
6334                         rte_eth_allmulticast_enable(res->port_num);
6335                 else
6336                         rte_eth_allmulticast_disable(res->port_num);
6337         }
6338 }
6339
6340 cmdline_parse_token_string_t cmd_setallmulti_set =
6341         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6342 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6343         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6344                                  "allmulti");
6345 cmdline_parse_token_string_t cmd_setallmulti_portall =
6346         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6347                                  "all");
6348 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6349         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6350                               UINT16);
6351 cmdline_parse_token_string_t cmd_setallmulti_mode =
6352         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6353                                  "on#off");
6354
6355 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6356         .f = cmd_set_allmulti_mode_parsed,
6357         .data = (void *)1,
6358         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6359         .tokens = {
6360                 (void *)&cmd_setallmulti_set,
6361                 (void *)&cmd_setallmulti_allmulti,
6362                 (void *)&cmd_setallmulti_portall,
6363                 (void *)&cmd_setallmulti_mode,
6364                 NULL,
6365         },
6366 };
6367
6368 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6369         .f = cmd_set_allmulti_mode_parsed,
6370         .data = (void *)0,
6371         .help_str = "set allmulti <port_id> on|off: "
6372                 "Set allmulti mode on port_id",
6373         .tokens = {
6374                 (void *)&cmd_setallmulti_set,
6375                 (void *)&cmd_setallmulti_allmulti,
6376                 (void *)&cmd_setallmulti_portnum,
6377                 (void *)&cmd_setallmulti_mode,
6378                 NULL,
6379         },
6380 };
6381
6382 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6383 struct cmd_link_flow_ctrl_set_result {
6384         cmdline_fixed_string_t set;
6385         cmdline_fixed_string_t flow_ctrl;
6386         cmdline_fixed_string_t rx;
6387         cmdline_fixed_string_t rx_lfc_mode;
6388         cmdline_fixed_string_t tx;
6389         cmdline_fixed_string_t tx_lfc_mode;
6390         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6391         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6392         cmdline_fixed_string_t autoneg_str;
6393         cmdline_fixed_string_t autoneg;
6394         cmdline_fixed_string_t hw_str;
6395         uint32_t high_water;
6396         cmdline_fixed_string_t lw_str;
6397         uint32_t low_water;
6398         cmdline_fixed_string_t pt_str;
6399         uint16_t pause_time;
6400         cmdline_fixed_string_t xon_str;
6401         uint16_t send_xon;
6402         portid_t port_id;
6403 };
6404
6405 cmdline_parse_token_string_t cmd_lfc_set_set =
6406         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6407                                 set, "set");
6408 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6409         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6410                                 flow_ctrl, "flow_ctrl");
6411 cmdline_parse_token_string_t cmd_lfc_set_rx =
6412         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6413                                 rx, "rx");
6414 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6415         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6416                                 rx_lfc_mode, "on#off");
6417 cmdline_parse_token_string_t cmd_lfc_set_tx =
6418         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6419                                 tx, "tx");
6420 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6421         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6422                                 tx_lfc_mode, "on#off");
6423 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6424         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6425                                 hw_str, "high_water");
6426 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6427         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6428                                 high_water, UINT32);
6429 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6430         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6431                                 lw_str, "low_water");
6432 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6433         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6434                                 low_water, UINT32);
6435 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6436         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6437                                 pt_str, "pause_time");
6438 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6439         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6440                                 pause_time, UINT16);
6441 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6442         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6443                                 xon_str, "send_xon");
6444 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6445         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6446                                 send_xon, UINT16);
6447 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6448         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6449                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6450 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6451         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6452                                 mac_ctrl_frame_fwd_mode, "on#off");
6453 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6454         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6455                                 autoneg_str, "autoneg");
6456 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6457         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6458                                 autoneg, "on#off");
6459 cmdline_parse_token_num_t cmd_lfc_set_portid =
6460         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6461                                 port_id, UINT16);
6462
6463 /* forward declaration */
6464 static void
6465 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6466                               void *data);
6467
6468 cmdline_parse_inst_t cmd_link_flow_control_set = {
6469         .f = cmd_link_flow_ctrl_set_parsed,
6470         .data = NULL,
6471         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6472                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6473                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6474         .tokens = {
6475                 (void *)&cmd_lfc_set_set,
6476                 (void *)&cmd_lfc_set_flow_ctrl,
6477                 (void *)&cmd_lfc_set_rx,
6478                 (void *)&cmd_lfc_set_rx_mode,
6479                 (void *)&cmd_lfc_set_tx,
6480                 (void *)&cmd_lfc_set_tx_mode,
6481                 (void *)&cmd_lfc_set_high_water,
6482                 (void *)&cmd_lfc_set_low_water,
6483                 (void *)&cmd_lfc_set_pause_time,
6484                 (void *)&cmd_lfc_set_send_xon,
6485                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6486                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6487                 (void *)&cmd_lfc_set_autoneg_str,
6488                 (void *)&cmd_lfc_set_autoneg,
6489                 (void *)&cmd_lfc_set_portid,
6490                 NULL,
6491         },
6492 };
6493
6494 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6495         .f = cmd_link_flow_ctrl_set_parsed,
6496         .data = (void *)&cmd_link_flow_control_set_rx,
6497         .help_str = "set flow_ctrl rx on|off <port_id>: "
6498                 "Change rx flow control parameter",
6499         .tokens = {
6500                 (void *)&cmd_lfc_set_set,
6501                 (void *)&cmd_lfc_set_flow_ctrl,
6502                 (void *)&cmd_lfc_set_rx,
6503                 (void *)&cmd_lfc_set_rx_mode,
6504                 (void *)&cmd_lfc_set_portid,
6505                 NULL,
6506         },
6507 };
6508
6509 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6510         .f = cmd_link_flow_ctrl_set_parsed,
6511         .data = (void *)&cmd_link_flow_control_set_tx,
6512         .help_str = "set flow_ctrl tx on|off <port_id>: "
6513                 "Change tx flow control parameter",
6514         .tokens = {
6515                 (void *)&cmd_lfc_set_set,
6516                 (void *)&cmd_lfc_set_flow_ctrl,
6517                 (void *)&cmd_lfc_set_tx,
6518                 (void *)&cmd_lfc_set_tx_mode,
6519                 (void *)&cmd_lfc_set_portid,
6520                 NULL,
6521         },
6522 };
6523
6524 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6525         .f = cmd_link_flow_ctrl_set_parsed,
6526         .data = (void *)&cmd_link_flow_control_set_hw,
6527         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6528                 "Change high water flow control parameter",
6529         .tokens = {
6530                 (void *)&cmd_lfc_set_set,
6531                 (void *)&cmd_lfc_set_flow_ctrl,
6532                 (void *)&cmd_lfc_set_high_water_str,
6533                 (void *)&cmd_lfc_set_high_water,
6534                 (void *)&cmd_lfc_set_portid,
6535                 NULL,
6536         },
6537 };
6538
6539 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6540         .f = cmd_link_flow_ctrl_set_parsed,
6541         .data = (void *)&cmd_link_flow_control_set_lw,
6542         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6543                 "Change low water flow control parameter",
6544         .tokens = {
6545                 (void *)&cmd_lfc_set_set,
6546                 (void *)&cmd_lfc_set_flow_ctrl,
6547                 (void *)&cmd_lfc_set_low_water_str,
6548                 (void *)&cmd_lfc_set_low_water,
6549                 (void *)&cmd_lfc_set_portid,
6550                 NULL,
6551         },
6552 };
6553
6554 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6555         .f = cmd_link_flow_ctrl_set_parsed,
6556         .data = (void *)&cmd_link_flow_control_set_pt,
6557         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6558                 "Change pause time flow control parameter",
6559         .tokens = {
6560                 (void *)&cmd_lfc_set_set,
6561                 (void *)&cmd_lfc_set_flow_ctrl,
6562                 (void *)&cmd_lfc_set_pause_time_str,
6563                 (void *)&cmd_lfc_set_pause_time,
6564                 (void *)&cmd_lfc_set_portid,
6565                 NULL,
6566         },
6567 };
6568
6569 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6570         .f = cmd_link_flow_ctrl_set_parsed,
6571         .data = (void *)&cmd_link_flow_control_set_xon,
6572         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6573                 "Change send_xon flow control parameter",
6574         .tokens = {
6575                 (void *)&cmd_lfc_set_set,
6576                 (void *)&cmd_lfc_set_flow_ctrl,
6577                 (void *)&cmd_lfc_set_send_xon_str,
6578                 (void *)&cmd_lfc_set_send_xon,
6579                 (void *)&cmd_lfc_set_portid,
6580                 NULL,
6581         },
6582 };
6583
6584 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6585         .f = cmd_link_flow_ctrl_set_parsed,
6586         .data = (void *)&cmd_link_flow_control_set_macfwd,
6587         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6588                 "Change mac ctrl fwd flow control parameter",
6589         .tokens = {
6590                 (void *)&cmd_lfc_set_set,
6591                 (void *)&cmd_lfc_set_flow_ctrl,
6592                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6593                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6594                 (void *)&cmd_lfc_set_portid,
6595                 NULL,
6596         },
6597 };
6598
6599 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6600         .f = cmd_link_flow_ctrl_set_parsed,
6601         .data = (void *)&cmd_link_flow_control_set_autoneg,
6602         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6603                 "Change autoneg flow control parameter",
6604         .tokens = {
6605                 (void *)&cmd_lfc_set_set,
6606                 (void *)&cmd_lfc_set_flow_ctrl,
6607                 (void *)&cmd_lfc_set_autoneg_str,
6608                 (void *)&cmd_lfc_set_autoneg,
6609                 (void *)&cmd_lfc_set_portid,
6610                 NULL,
6611         },
6612 };
6613
6614 static void
6615 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6616                               __attribute__((unused)) struct cmdline *cl,
6617                               void *data)
6618 {
6619         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6620         cmdline_parse_inst_t *cmd = data;
6621         struct rte_eth_fc_conf fc_conf;
6622         int rx_fc_en = 0;
6623         int tx_fc_en = 0;
6624         int ret;
6625
6626         /*
6627          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6628          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6629          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6630          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6631          */
6632         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6633                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6634         };
6635
6636         /* Partial command line, retrieve current configuration */
6637         if (cmd) {
6638                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6639                 if (ret != 0) {
6640                         printf("cannot get current flow ctrl parameters, return"
6641                                "code = %d\n", ret);
6642                         return;
6643                 }
6644
6645                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6646                     (fc_conf.mode == RTE_FC_FULL))
6647                         rx_fc_en = 1;
6648                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6649                     (fc_conf.mode == RTE_FC_FULL))
6650                         tx_fc_en = 1;
6651         }
6652
6653         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6654                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6655
6656         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6657                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6658
6659         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6660
6661         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6662                 fc_conf.high_water = res->high_water;
6663
6664         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6665                 fc_conf.low_water = res->low_water;
6666
6667         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6668                 fc_conf.pause_time = res->pause_time;
6669
6670         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6671                 fc_conf.send_xon = res->send_xon;
6672
6673         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6674                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6675                         fc_conf.mac_ctrl_frame_fwd = 1;
6676                 else
6677                         fc_conf.mac_ctrl_frame_fwd = 0;
6678         }
6679
6680         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6681                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6682
6683         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6684         if (ret != 0)
6685                 printf("bad flow contrl parameter, return code = %d \n", ret);
6686 }
6687
6688 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6689 struct cmd_priority_flow_ctrl_set_result {
6690         cmdline_fixed_string_t set;
6691         cmdline_fixed_string_t pfc_ctrl;
6692         cmdline_fixed_string_t rx;
6693         cmdline_fixed_string_t rx_pfc_mode;
6694         cmdline_fixed_string_t tx;
6695         cmdline_fixed_string_t tx_pfc_mode;
6696         uint32_t high_water;
6697         uint32_t low_water;
6698         uint16_t pause_time;
6699         uint8_t  priority;
6700         portid_t port_id;
6701 };
6702
6703 static void
6704 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6705                        __attribute__((unused)) struct cmdline *cl,
6706                        __attribute__((unused)) void *data)
6707 {
6708         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6709         struct rte_eth_pfc_conf pfc_conf;
6710         int rx_fc_enable, tx_fc_enable;
6711         int ret;
6712
6713         /*
6714          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6715          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6716          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6717          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6718          */
6719         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6720                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6721         };
6722
6723         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6724         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6725         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6726         pfc_conf.fc.high_water = res->high_water;
6727         pfc_conf.fc.low_water  = res->low_water;
6728         pfc_conf.fc.pause_time = res->pause_time;
6729         pfc_conf.priority      = res->priority;
6730
6731         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6732         if (ret != 0)
6733                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6734 }
6735
6736 cmdline_parse_token_string_t cmd_pfc_set_set =
6737         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6738                                 set, "set");
6739 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6740         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6741                                 pfc_ctrl, "pfc_ctrl");
6742 cmdline_parse_token_string_t cmd_pfc_set_rx =
6743         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6744                                 rx, "rx");
6745 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6746         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6747                                 rx_pfc_mode, "on#off");
6748 cmdline_parse_token_string_t cmd_pfc_set_tx =
6749         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6750                                 tx, "tx");
6751 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6752         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6753                                 tx_pfc_mode, "on#off");
6754 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6755         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6756                                 high_water, UINT32);
6757 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6758         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6759                                 low_water, UINT32);
6760 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6761         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6762                                 pause_time, UINT16);
6763 cmdline_parse_token_num_t cmd_pfc_set_priority =
6764         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6765                                 priority, UINT8);
6766 cmdline_parse_token_num_t cmd_pfc_set_portid =
6767         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6768                                 port_id, UINT16);
6769
6770 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6771         .f = cmd_priority_flow_ctrl_set_parsed,
6772         .data = NULL,
6773         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6774                 "<pause_time> <priority> <port_id>: "
6775                 "Configure the Ethernet priority flow control",
6776         .tokens = {
6777                 (void *)&cmd_pfc_set_set,
6778                 (void *)&cmd_pfc_set_flow_ctrl,
6779                 (void *)&cmd_pfc_set_rx,
6780                 (void *)&cmd_pfc_set_rx_mode,
6781                 (void *)&cmd_pfc_set_tx,
6782                 (void *)&cmd_pfc_set_tx_mode,
6783                 (void *)&cmd_pfc_set_high_water,
6784                 (void *)&cmd_pfc_set_low_water,
6785                 (void *)&cmd_pfc_set_pause_time,
6786                 (void *)&cmd_pfc_set_priority,
6787                 (void *)&cmd_pfc_set_portid,
6788                 NULL,
6789         },
6790 };
6791
6792 /* *** RESET CONFIGURATION *** */
6793 struct cmd_reset_result {
6794         cmdline_fixed_string_t reset;
6795         cmdline_fixed_string_t def;
6796 };
6797
6798 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6799                              struct cmdline *cl,
6800                              __attribute__((unused)) void *data)
6801 {
6802         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6803         set_def_fwd_config();
6804 }
6805
6806 cmdline_parse_token_string_t cmd_reset_set =
6807         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6808 cmdline_parse_token_string_t cmd_reset_def =
6809         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6810                                  "default");
6811
6812 cmdline_parse_inst_t cmd_reset = {
6813         .f = cmd_reset_parsed,
6814         .data = NULL,
6815         .help_str = "set default: Reset default forwarding configuration",
6816         .tokens = {
6817                 (void *)&cmd_reset_set,
6818                 (void *)&cmd_reset_def,
6819                 NULL,
6820         },
6821 };
6822
6823 /* *** START FORWARDING *** */
6824 struct cmd_start_result {
6825         cmdline_fixed_string_t start;
6826 };
6827
6828 cmdline_parse_token_string_t cmd_start_start =
6829         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6830
6831 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6832                              __attribute__((unused)) struct cmdline *cl,
6833                              __attribute__((unused)) void *data)
6834 {
6835         start_packet_forwarding(0);
6836 }
6837
6838 cmdline_parse_inst_t cmd_start = {
6839         .f = cmd_start_parsed,
6840         .data = NULL,
6841         .help_str = "start: Start packet forwarding",
6842         .tokens = {
6843                 (void *)&cmd_start_start,
6844                 NULL,
6845         },
6846 };
6847
6848 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6849 struct cmd_start_tx_first_result {
6850         cmdline_fixed_string_t start;
6851         cmdline_fixed_string_t tx_first;
6852 };
6853
6854 static void
6855 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6856                           __attribute__((unused)) struct cmdline *cl,
6857                           __attribute__((unused)) void *data)
6858 {
6859         start_packet_forwarding(1);
6860 }
6861
6862 cmdline_parse_token_string_t cmd_start_tx_first_start =
6863         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6864                                  "start");
6865 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6866         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6867                                  tx_first, "tx_first");
6868
6869 cmdline_parse_inst_t cmd_start_tx_first = {
6870         .f = cmd_start_tx_first_parsed,
6871         .data = NULL,
6872         .help_str = "start tx_first: Start packet forwarding, "
6873                 "after sending 1 burst of packets",
6874         .tokens = {
6875                 (void *)&cmd_start_tx_first_start,
6876                 (void *)&cmd_start_tx_first_tx_first,
6877                 NULL,
6878         },
6879 };
6880
6881 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6882 struct cmd_start_tx_first_n_result {
6883         cmdline_fixed_string_t start;
6884         cmdline_fixed_string_t tx_first;
6885         uint32_t tx_num;
6886 };
6887
6888 static void
6889 cmd_start_tx_first_n_parsed(void *parsed_result,
6890                           __attribute__((unused)) struct cmdline *cl,
6891                           __attribute__((unused)) void *data)
6892 {
6893         struct cmd_start_tx_first_n_result *res = parsed_result;
6894
6895         start_packet_forwarding(res->tx_num);
6896 }
6897
6898 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6899         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6900                         start, "start");
6901 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6902         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6903                         tx_first, "tx_first");
6904 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6905         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6906                         tx_num, UINT32);
6907
6908 cmdline_parse_inst_t cmd_start_tx_first_n = {
6909         .f = cmd_start_tx_first_n_parsed,
6910         .data = NULL,
6911         .help_str = "start tx_first <num>: "
6912                 "packet forwarding, after sending <num> bursts of packets",
6913         .tokens = {
6914                 (void *)&cmd_start_tx_first_n_start,
6915                 (void *)&cmd_start_tx_first_n_tx_first,
6916                 (void *)&cmd_start_tx_first_n_tx_num,
6917                 NULL,
6918         },
6919 };
6920
6921 /* *** SET LINK UP *** */
6922 struct cmd_set_link_up_result {
6923         cmdline_fixed_string_t set;
6924         cmdline_fixed_string_t link_up;
6925         cmdline_fixed_string_t port;
6926         portid_t port_id;
6927 };
6928
6929 cmdline_parse_token_string_t cmd_set_link_up_set =
6930         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6931 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6932         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6933                                 "link-up");
6934 cmdline_parse_token_string_t cmd_set_link_up_port =
6935         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6936 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6937         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6938
6939 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6940                              __attribute__((unused)) struct cmdline *cl,
6941                              __attribute__((unused)) void *data)
6942 {
6943         struct cmd_set_link_up_result *res = parsed_result;
6944         dev_set_link_up(res->port_id);
6945 }
6946
6947 cmdline_parse_inst_t cmd_set_link_up = {
6948         .f = cmd_set_link_up_parsed,
6949         .data = NULL,
6950         .help_str = "set link-up port <port id>",
6951         .tokens = {
6952                 (void *)&cmd_set_link_up_set,
6953                 (void *)&cmd_set_link_up_link_up,
6954                 (void *)&cmd_set_link_up_port,
6955                 (void *)&cmd_set_link_up_port_id,
6956                 NULL,
6957         },
6958 };
6959
6960 /* *** SET LINK DOWN *** */
6961 struct cmd_set_link_down_result {
6962         cmdline_fixed_string_t set;
6963         cmdline_fixed_string_t link_down;
6964         cmdline_fixed_string_t port;
6965         portid_t port_id;
6966 };
6967
6968 cmdline_parse_token_string_t cmd_set_link_down_set =
6969         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6970 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6971         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6972                                 "link-down");
6973 cmdline_parse_token_string_t cmd_set_link_down_port =
6974         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6975 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6976         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6977
6978 static void cmd_set_link_down_parsed(
6979                                 __attribute__((unused)) void *parsed_result,
6980                                 __attribute__((unused)) struct cmdline *cl,
6981                                 __attribute__((unused)) void *data)
6982 {
6983         struct cmd_set_link_down_result *res = parsed_result;
6984         dev_set_link_down(res->port_id);
6985 }
6986
6987 cmdline_parse_inst_t cmd_set_link_down = {
6988         .f = cmd_set_link_down_parsed,
6989         .data = NULL,
6990         .help_str = "set link-down port <port id>",
6991         .tokens = {
6992                 (void *)&cmd_set_link_down_set,
6993                 (void *)&cmd_set_link_down_link_down,
6994                 (void *)&cmd_set_link_down_port,
6995                 (void *)&cmd_set_link_down_port_id,
6996                 NULL,
6997         },
6998 };
6999
7000 /* *** SHOW CFG *** */
7001 struct cmd_showcfg_result {
7002         cmdline_fixed_string_t show;
7003         cmdline_fixed_string_t cfg;
7004         cmdline_fixed_string_t what;
7005 };
7006
7007 static void cmd_showcfg_parsed(void *parsed_result,
7008                                __attribute__((unused)) struct cmdline *cl,
7009                                __attribute__((unused)) void *data)
7010 {
7011         struct cmd_showcfg_result *res = parsed_result;
7012         if (!strcmp(res->what, "rxtx"))
7013                 rxtx_config_display();
7014         else if (!strcmp(res->what, "cores"))
7015                 fwd_lcores_config_display();
7016         else if (!strcmp(res->what, "fwd"))
7017                 pkt_fwd_config_display(&cur_fwd_config);
7018         else if (!strcmp(res->what, "txpkts"))
7019                 show_tx_pkt_segments();
7020 }
7021
7022 cmdline_parse_token_string_t cmd_showcfg_show =
7023         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7024 cmdline_parse_token_string_t cmd_showcfg_port =
7025         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7026 cmdline_parse_token_string_t cmd_showcfg_what =
7027         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7028                                  "rxtx#cores#fwd#txpkts");
7029
7030 cmdline_parse_inst_t cmd_showcfg = {
7031         .f = cmd_showcfg_parsed,
7032         .data = NULL,
7033         .help_str = "show config rxtx|cores|fwd|txpkts",
7034         .tokens = {
7035                 (void *)&cmd_showcfg_show,
7036                 (void *)&cmd_showcfg_port,
7037                 (void *)&cmd_showcfg_what,
7038                 NULL,
7039         },
7040 };
7041
7042 /* *** SHOW ALL PORT INFO *** */
7043 struct cmd_showportall_result {
7044         cmdline_fixed_string_t show;
7045         cmdline_fixed_string_t port;
7046         cmdline_fixed_string_t what;
7047         cmdline_fixed_string_t all;
7048 };
7049
7050 static void cmd_showportall_parsed(void *parsed_result,
7051                                 __attribute__((unused)) struct cmdline *cl,
7052                                 __attribute__((unused)) void *data)
7053 {
7054         portid_t i;
7055
7056         struct cmd_showportall_result *res = parsed_result;
7057         if (!strcmp(res->show, "clear")) {
7058                 if (!strcmp(res->what, "stats"))
7059                         RTE_ETH_FOREACH_DEV(i)
7060                                 nic_stats_clear(i);
7061                 else if (!strcmp(res->what, "xstats"))
7062                         RTE_ETH_FOREACH_DEV(i)
7063                                 nic_xstats_clear(i);
7064         } else if (!strcmp(res->what, "info"))
7065                 RTE_ETH_FOREACH_DEV(i)
7066                         port_infos_display(i);
7067         else if (!strcmp(res->what, "stats"))
7068                 RTE_ETH_FOREACH_DEV(i)
7069                         nic_stats_display(i);
7070         else if (!strcmp(res->what, "xstats"))
7071                 RTE_ETH_FOREACH_DEV(i)
7072                         nic_xstats_display(i);
7073         else if (!strcmp(res->what, "fdir"))
7074                 RTE_ETH_FOREACH_DEV(i)
7075                         fdir_get_infos(i);
7076         else if (!strcmp(res->what, "stat_qmap"))
7077                 RTE_ETH_FOREACH_DEV(i)
7078                         nic_stats_mapping_display(i);
7079         else if (!strcmp(res->what, "dcb_tc"))
7080                 RTE_ETH_FOREACH_DEV(i)
7081                         port_dcb_info_display(i);
7082         else if (!strcmp(res->what, "cap"))
7083                 RTE_ETH_FOREACH_DEV(i)
7084                         port_offload_cap_display(i);
7085 }
7086
7087 cmdline_parse_token_string_t cmd_showportall_show =
7088         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7089                                  "show#clear");
7090 cmdline_parse_token_string_t cmd_showportall_port =
7091         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7092 cmdline_parse_token_string_t cmd_showportall_what =
7093         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7094                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7095 cmdline_parse_token_string_t cmd_showportall_all =
7096         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7097 cmdline_parse_inst_t cmd_showportall = {
7098         .f = cmd_showportall_parsed,
7099         .data = NULL,
7100         .help_str = "show|clear port "
7101                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7102         .tokens = {
7103                 (void *)&cmd_showportall_show,
7104                 (void *)&cmd_showportall_port,
7105                 (void *)&cmd_showportall_what,
7106                 (void *)&cmd_showportall_all,
7107                 NULL,
7108         },
7109 };
7110
7111 /* *** SHOW PORT INFO *** */
7112 struct cmd_showport_result {
7113         cmdline_fixed_string_t show;
7114         cmdline_fixed_string_t port;
7115         cmdline_fixed_string_t what;
7116         uint16_t portnum;
7117 };
7118
7119 static void cmd_showport_parsed(void *parsed_result,
7120                                 __attribute__((unused)) struct cmdline *cl,
7121                                 __attribute__((unused)) void *data)
7122 {
7123         struct cmd_showport_result *res = parsed_result;
7124         if (!strcmp(res->show, "clear")) {
7125                 if (!strcmp(res->what, "stats"))
7126                         nic_stats_clear(res->portnum);
7127                 else if (!strcmp(res->what, "xstats"))
7128                         nic_xstats_clear(res->portnum);
7129         } else if (!strcmp(res->what, "info"))
7130                 port_infos_display(res->portnum);
7131         else if (!strcmp(res->what, "stats"))
7132                 nic_stats_display(res->portnum);
7133         else if (!strcmp(res->what, "xstats"))
7134                 nic_xstats_display(res->portnum);
7135         else if (!strcmp(res->what, "fdir"))
7136                  fdir_get_infos(res->portnum);
7137         else if (!strcmp(res->what, "stat_qmap"))
7138                 nic_stats_mapping_display(res->portnum);
7139         else if (!strcmp(res->what, "dcb_tc"))
7140                 port_dcb_info_display(res->portnum);
7141         else if (!strcmp(res->what, "cap"))
7142                 port_offload_cap_display(res->portnum);
7143 }
7144
7145 cmdline_parse_token_string_t cmd_showport_show =
7146         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7147                                  "show#clear");
7148 cmdline_parse_token_string_t cmd_showport_port =
7149         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7150 cmdline_parse_token_string_t cmd_showport_what =
7151         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7152                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7153 cmdline_parse_token_num_t cmd_showport_portnum =
7154         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7155
7156 cmdline_parse_inst_t cmd_showport = {
7157         .f = cmd_showport_parsed,
7158         .data = NULL,
7159         .help_str = "show|clear port "
7160                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7161                 "<port_id>",
7162         .tokens = {
7163                 (void *)&cmd_showport_show,
7164                 (void *)&cmd_showport_port,
7165                 (void *)&cmd_showport_what,
7166                 (void *)&cmd_showport_portnum,
7167                 NULL,
7168         },
7169 };
7170
7171 /* *** SHOW QUEUE INFO *** */
7172 struct cmd_showqueue_result {
7173         cmdline_fixed_string_t show;
7174         cmdline_fixed_string_t type;
7175         cmdline_fixed_string_t what;
7176         uint16_t portnum;
7177         uint16_t queuenum;
7178 };
7179
7180 static void
7181 cmd_showqueue_parsed(void *parsed_result,
7182         __attribute__((unused)) struct cmdline *cl,
7183         __attribute__((unused)) void *data)
7184 {
7185         struct cmd_showqueue_result *res = parsed_result;
7186
7187         if (!strcmp(res->type, "rxq"))
7188                 rx_queue_infos_display(res->portnum, res->queuenum);
7189         else if (!strcmp(res->type, "txq"))
7190                 tx_queue_infos_display(res->portnum, res->queuenum);
7191 }
7192
7193 cmdline_parse_token_string_t cmd_showqueue_show =
7194         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7195 cmdline_parse_token_string_t cmd_showqueue_type =
7196         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7197 cmdline_parse_token_string_t cmd_showqueue_what =
7198         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7199 cmdline_parse_token_num_t cmd_showqueue_portnum =
7200         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7201 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7202         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7203
7204 cmdline_parse_inst_t cmd_showqueue = {
7205         .f = cmd_showqueue_parsed,
7206         .data = NULL,
7207         .help_str = "show rxq|txq info <port_id> <queue_id>",
7208         .tokens = {
7209                 (void *)&cmd_showqueue_show,
7210                 (void *)&cmd_showqueue_type,
7211                 (void *)&cmd_showqueue_what,
7212                 (void *)&cmd_showqueue_portnum,
7213                 (void *)&cmd_showqueue_queuenum,
7214                 NULL,
7215         },
7216 };
7217
7218 /* *** READ PORT REGISTER *** */
7219 struct cmd_read_reg_result {
7220         cmdline_fixed_string_t read;
7221         cmdline_fixed_string_t reg;
7222         portid_t port_id;
7223         uint32_t reg_off;
7224 };
7225
7226 static void
7227 cmd_read_reg_parsed(void *parsed_result,
7228                     __attribute__((unused)) struct cmdline *cl,
7229                     __attribute__((unused)) void *data)
7230 {
7231         struct cmd_read_reg_result *res = parsed_result;
7232         port_reg_display(res->port_id, res->reg_off);
7233 }
7234
7235 cmdline_parse_token_string_t cmd_read_reg_read =
7236         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7237 cmdline_parse_token_string_t cmd_read_reg_reg =
7238         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7239 cmdline_parse_token_num_t cmd_read_reg_port_id =
7240         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7241 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7242         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7243
7244 cmdline_parse_inst_t cmd_read_reg = {
7245         .f = cmd_read_reg_parsed,
7246         .data = NULL,
7247         .help_str = "read reg <port_id> <reg_off>",
7248         .tokens = {
7249                 (void *)&cmd_read_reg_read,
7250                 (void *)&cmd_read_reg_reg,
7251                 (void *)&cmd_read_reg_port_id,
7252                 (void *)&cmd_read_reg_reg_off,
7253                 NULL,
7254         },
7255 };
7256
7257 /* *** READ PORT REGISTER BIT FIELD *** */
7258 struct cmd_read_reg_bit_field_result {
7259         cmdline_fixed_string_t read;
7260         cmdline_fixed_string_t regfield;
7261         portid_t port_id;
7262         uint32_t reg_off;
7263         uint8_t bit1_pos;
7264         uint8_t bit2_pos;
7265 };
7266
7267 static void
7268 cmd_read_reg_bit_field_parsed(void *parsed_result,
7269                               __attribute__((unused)) struct cmdline *cl,
7270                               __attribute__((unused)) void *data)
7271 {
7272         struct cmd_read_reg_bit_field_result *res = parsed_result;
7273         port_reg_bit_field_display(res->port_id, res->reg_off,
7274                                    res->bit1_pos, res->bit2_pos);
7275 }
7276
7277 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7278         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7279                                  "read");
7280 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7281         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7282                                  regfield, "regfield");
7283 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7284         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7285                               UINT16);
7286 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7287         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7288                               UINT32);
7289 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7290         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7291                               UINT8);
7292 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7293         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7294                               UINT8);
7295
7296 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7297         .f = cmd_read_reg_bit_field_parsed,
7298         .data = NULL,
7299         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7300         "Read register bit field between bit_x and bit_y included",
7301         .tokens = {
7302                 (void *)&cmd_read_reg_bit_field_read,
7303                 (void *)&cmd_read_reg_bit_field_regfield,
7304                 (void *)&cmd_read_reg_bit_field_port_id,
7305                 (void *)&cmd_read_reg_bit_field_reg_off,
7306                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7307                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** READ PORT REGISTER BIT *** */
7313 struct cmd_read_reg_bit_result {
7314         cmdline_fixed_string_t read;
7315         cmdline_fixed_string_t regbit;
7316         portid_t port_id;
7317         uint32_t reg_off;
7318         uint8_t bit_pos;
7319 };
7320
7321 static void
7322 cmd_read_reg_bit_parsed(void *parsed_result,
7323                         __attribute__((unused)) struct cmdline *cl,
7324                         __attribute__((unused)) void *data)
7325 {
7326         struct cmd_read_reg_bit_result *res = parsed_result;
7327         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7328 }
7329
7330 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7331         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7332 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7333         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7334                                  regbit, "regbit");
7335 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7336         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7337 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7338         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7339 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7340         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7341
7342 cmdline_parse_inst_t cmd_read_reg_bit = {
7343         .f = cmd_read_reg_bit_parsed,
7344         .data = NULL,
7345         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7346         .tokens = {
7347                 (void *)&cmd_read_reg_bit_read,
7348                 (void *)&cmd_read_reg_bit_regbit,
7349                 (void *)&cmd_read_reg_bit_port_id,
7350                 (void *)&cmd_read_reg_bit_reg_off,
7351                 (void *)&cmd_read_reg_bit_bit_pos,
7352                 NULL,
7353         },
7354 };
7355
7356 /* *** WRITE PORT REGISTER *** */
7357 struct cmd_write_reg_result {
7358         cmdline_fixed_string_t write;
7359         cmdline_fixed_string_t reg;
7360         portid_t port_id;
7361         uint32_t reg_off;
7362         uint32_t value;
7363 };
7364
7365 static void
7366 cmd_write_reg_parsed(void *parsed_result,
7367                      __attribute__((unused)) struct cmdline *cl,
7368                      __attribute__((unused)) void *data)
7369 {
7370         struct cmd_write_reg_result *res = parsed_result;
7371         port_reg_set(res->port_id, res->reg_off, res->value);
7372 }
7373
7374 cmdline_parse_token_string_t cmd_write_reg_write =
7375         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7376 cmdline_parse_token_string_t cmd_write_reg_reg =
7377         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7378 cmdline_parse_token_num_t cmd_write_reg_port_id =
7379         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7380 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7381         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7382 cmdline_parse_token_num_t cmd_write_reg_value =
7383         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7384
7385 cmdline_parse_inst_t cmd_write_reg = {
7386         .f = cmd_write_reg_parsed,
7387         .data = NULL,
7388         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7389         .tokens = {
7390                 (void *)&cmd_write_reg_write,
7391                 (void *)&cmd_write_reg_reg,
7392                 (void *)&cmd_write_reg_port_id,
7393                 (void *)&cmd_write_reg_reg_off,
7394                 (void *)&cmd_write_reg_value,
7395                 NULL,
7396         },
7397 };
7398
7399 /* *** WRITE PORT REGISTER BIT FIELD *** */
7400 struct cmd_write_reg_bit_field_result {
7401         cmdline_fixed_string_t write;
7402         cmdline_fixed_string_t regfield;
7403         portid_t port_id;
7404         uint32_t reg_off;
7405         uint8_t bit1_pos;
7406         uint8_t bit2_pos;
7407         uint32_t value;
7408 };
7409
7410 static void
7411 cmd_write_reg_bit_field_parsed(void *parsed_result,
7412                                __attribute__((unused)) struct cmdline *cl,
7413                                __attribute__((unused)) void *data)
7414 {
7415         struct cmd_write_reg_bit_field_result *res = parsed_result;
7416         port_reg_bit_field_set(res->port_id, res->reg_off,
7417                           res->bit1_pos, res->bit2_pos, res->value);
7418 }
7419
7420 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7421         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7422                                  "write");
7423 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7424         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7425                                  regfield, "regfield");
7426 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7427         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7428                               UINT16);
7429 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7430         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7431                               UINT32);
7432 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7433         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7434                               UINT8);
7435 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7436         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7437                               UINT8);
7438 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7439         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7440                               UINT32);
7441
7442 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7443         .f = cmd_write_reg_bit_field_parsed,
7444         .data = NULL,
7445         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7446                 "<reg_value>: "
7447                 "Set register bit field between bit_x and bit_y included",
7448         .tokens = {
7449                 (void *)&cmd_write_reg_bit_field_write,
7450                 (void *)&cmd_write_reg_bit_field_regfield,
7451                 (void *)&cmd_write_reg_bit_field_port_id,
7452                 (void *)&cmd_write_reg_bit_field_reg_off,
7453                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7454                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7455                 (void *)&cmd_write_reg_bit_field_value,
7456                 NULL,
7457         },
7458 };
7459
7460 /* *** WRITE PORT REGISTER BIT *** */
7461 struct cmd_write_reg_bit_result {
7462         cmdline_fixed_string_t write;
7463         cmdline_fixed_string_t regbit;
7464         portid_t port_id;
7465         uint32_t reg_off;
7466         uint8_t bit_pos;
7467         uint8_t value;
7468 };
7469
7470 static void
7471 cmd_write_reg_bit_parsed(void *parsed_result,
7472                          __attribute__((unused)) struct cmdline *cl,
7473                          __attribute__((unused)) void *data)
7474 {
7475         struct cmd_write_reg_bit_result *res = parsed_result;
7476         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7477 }
7478
7479 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7480         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7481                                  "write");
7482 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7483         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7484                                  regbit, "regbit");
7485 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7486         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7487 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7488         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7489 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7490         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7491 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7492         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7493
7494 cmdline_parse_inst_t cmd_write_reg_bit = {
7495         .f = cmd_write_reg_bit_parsed,
7496         .data = NULL,
7497         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7498                 "0 <= bit_x <= 31",
7499         .tokens = {
7500                 (void *)&cmd_write_reg_bit_write,
7501                 (void *)&cmd_write_reg_bit_regbit,
7502                 (void *)&cmd_write_reg_bit_port_id,
7503                 (void *)&cmd_write_reg_bit_reg_off,
7504                 (void *)&cmd_write_reg_bit_bit_pos,
7505                 (void *)&cmd_write_reg_bit_value,
7506                 NULL,
7507         },
7508 };
7509
7510 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7511 struct cmd_read_rxd_txd_result {
7512         cmdline_fixed_string_t read;
7513         cmdline_fixed_string_t rxd_txd;
7514         portid_t port_id;
7515         uint16_t queue_id;
7516         uint16_t desc_id;
7517 };
7518
7519 static void
7520 cmd_read_rxd_txd_parsed(void *parsed_result,
7521                         __attribute__((unused)) struct cmdline *cl,
7522                         __attribute__((unused)) void *data)
7523 {
7524         struct cmd_read_rxd_txd_result *res = parsed_result;
7525
7526         if (!strcmp(res->rxd_txd, "rxd"))
7527                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7528         else if (!strcmp(res->rxd_txd, "txd"))
7529                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7530 }
7531
7532 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7533         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7534 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7535         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7536                                  "rxd#txd");
7537 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7538         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7539 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7540         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7541 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7542         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7543
7544 cmdline_parse_inst_t cmd_read_rxd_txd = {
7545         .f = cmd_read_rxd_txd_parsed,
7546         .data = NULL,
7547         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7548         .tokens = {
7549                 (void *)&cmd_read_rxd_txd_read,
7550                 (void *)&cmd_read_rxd_txd_rxd_txd,
7551                 (void *)&cmd_read_rxd_txd_port_id,
7552                 (void *)&cmd_read_rxd_txd_queue_id,
7553                 (void *)&cmd_read_rxd_txd_desc_id,
7554                 NULL,
7555         },
7556 };
7557
7558 /* *** QUIT *** */
7559 struct cmd_quit_result {
7560         cmdline_fixed_string_t quit;
7561 };
7562
7563 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7564                             struct cmdline *cl,
7565                             __attribute__((unused)) void *data)
7566 {
7567         pmd_test_exit();
7568         cmdline_quit(cl);
7569 }
7570
7571 cmdline_parse_token_string_t cmd_quit_quit =
7572         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7573
7574 cmdline_parse_inst_t cmd_quit = {
7575         .f = cmd_quit_parsed,
7576         .data = NULL,
7577         .help_str = "quit: Exit application",
7578         .tokens = {
7579                 (void *)&cmd_quit_quit,
7580                 NULL,
7581         },
7582 };
7583
7584 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7585 struct cmd_mac_addr_result {
7586         cmdline_fixed_string_t mac_addr_cmd;
7587         cmdline_fixed_string_t what;
7588         uint16_t port_num;
7589         struct ether_addr address;
7590 };
7591
7592 static void cmd_mac_addr_parsed(void *parsed_result,
7593                 __attribute__((unused)) struct cmdline *cl,
7594                 __attribute__((unused)) void *data)
7595 {
7596         struct cmd_mac_addr_result *res = parsed_result;
7597         int ret;
7598
7599         if (strcmp(res->what, "add") == 0)
7600                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7601         else if (strcmp(res->what, "set") == 0)
7602                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7603                                                        &res->address);
7604         else
7605                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7606
7607         /* check the return value and print it if is < 0 */
7608         if(ret < 0)
7609                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7610
7611 }
7612
7613 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7614         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7615                                 "mac_addr");
7616 cmdline_parse_token_string_t cmd_mac_addr_what =
7617         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7618                                 "add#remove#set");
7619 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7620                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7621                                         UINT16);
7622 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7623                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7624
7625 cmdline_parse_inst_t cmd_mac_addr = {
7626         .f = cmd_mac_addr_parsed,
7627         .data = (void *)0,
7628         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7629                         "Add/Remove/Set MAC address on port_id",
7630         .tokens = {
7631                 (void *)&cmd_mac_addr_cmd,
7632                 (void *)&cmd_mac_addr_what,
7633                 (void *)&cmd_mac_addr_portnum,
7634                 (void *)&cmd_mac_addr_addr,
7635                 NULL,
7636         },
7637 };
7638
7639 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7640 struct cmd_eth_peer_result {
7641         cmdline_fixed_string_t set;
7642         cmdline_fixed_string_t eth_peer;
7643         portid_t port_id;
7644         cmdline_fixed_string_t peer_addr;
7645 };
7646
7647 static void cmd_set_eth_peer_parsed(void *parsed_result,
7648                         __attribute__((unused)) struct cmdline *cl,
7649                         __attribute__((unused)) void *data)
7650 {
7651                 struct cmd_eth_peer_result *res = parsed_result;
7652
7653                 if (test_done == 0) {
7654                         printf("Please stop forwarding first\n");
7655                         return;
7656                 }
7657                 if (!strcmp(res->eth_peer, "eth-peer")) {
7658                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7659                         fwd_config_setup();
7660                 }
7661 }
7662 cmdline_parse_token_string_t cmd_eth_peer_set =
7663         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7664 cmdline_parse_token_string_t cmd_eth_peer =
7665         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7666 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7667         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7668 cmdline_parse_token_string_t cmd_eth_peer_addr =
7669         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
7670
7671 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
7672         .f = cmd_set_eth_peer_parsed,
7673         .data = NULL,
7674         .help_str = "set eth-peer <port_id> <peer_mac>",
7675         .tokens = {
7676                 (void *)&cmd_eth_peer_set,
7677                 (void *)&cmd_eth_peer,
7678                 (void *)&cmd_eth_peer_port_id,
7679                 (void *)&cmd_eth_peer_addr,
7680                 NULL,
7681         },
7682 };
7683
7684 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7685 struct cmd_set_qmap_result {
7686         cmdline_fixed_string_t set;
7687         cmdline_fixed_string_t qmap;
7688         cmdline_fixed_string_t what;
7689         portid_t port_id;
7690         uint16_t queue_id;
7691         uint8_t map_value;
7692 };
7693
7694 static void
7695 cmd_set_qmap_parsed(void *parsed_result,
7696                        __attribute__((unused)) struct cmdline *cl,
7697                        __attribute__((unused)) void *data)
7698 {
7699         struct cmd_set_qmap_result *res = parsed_result;
7700         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7701
7702         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7703 }
7704
7705 cmdline_parse_token_string_t cmd_setqmap_set =
7706         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7707                                  set, "set");
7708 cmdline_parse_token_string_t cmd_setqmap_qmap =
7709         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7710                                  qmap, "stat_qmap");
7711 cmdline_parse_token_string_t cmd_setqmap_what =
7712         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7713                                  what, "tx#rx");
7714 cmdline_parse_token_num_t cmd_setqmap_portid =
7715         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7716                               port_id, UINT16);
7717 cmdline_parse_token_num_t cmd_setqmap_queueid =
7718         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7719                               queue_id, UINT16);
7720 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7721         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7722                               map_value, UINT8);
7723
7724 cmdline_parse_inst_t cmd_set_qmap = {
7725         .f = cmd_set_qmap_parsed,
7726         .data = NULL,
7727         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7728                 "Set statistics mapping value on tx|rx queue_id of port_id",
7729         .tokens = {
7730                 (void *)&cmd_setqmap_set,
7731                 (void *)&cmd_setqmap_qmap,
7732                 (void *)&cmd_setqmap_what,
7733                 (void *)&cmd_setqmap_portid,
7734                 (void *)&cmd_setqmap_queueid,
7735                 (void *)&cmd_setqmap_mapvalue,
7736                 NULL,
7737         },
7738 };
7739
7740 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7741 struct cmd_set_xstats_hide_zero_result {
7742         cmdline_fixed_string_t keyword;
7743         cmdline_fixed_string_t name;
7744         cmdline_fixed_string_t on_off;
7745 };
7746
7747 static void
7748 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7749                         __attribute__((unused)) struct cmdline *cl,
7750                         __attribute__((unused)) void *data)
7751 {
7752         struct cmd_set_xstats_hide_zero_result *res;
7753         uint16_t on_off = 0;
7754
7755         res = parsed_result;
7756         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7757         set_xstats_hide_zero(on_off);
7758 }
7759
7760 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7761         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7762                                  keyword, "set");
7763 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7764         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7765                                  name, "xstats-hide-zero");
7766 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7767         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7768                                  on_off, "on#off");
7769
7770 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7771         .f = cmd_set_xstats_hide_zero_parsed,
7772         .data = NULL,
7773         .help_str = "set xstats-hide-zero on|off",
7774         .tokens = {
7775                 (void *)&cmd_set_xstats_hide_zero_keyword,
7776                 (void *)&cmd_set_xstats_hide_zero_name,
7777                 (void *)&cmd_set_xstats_hide_zero_on_off,
7778                 NULL,
7779         },
7780 };
7781
7782 /* *** CONFIGURE UNICAST HASH TABLE *** */
7783 struct cmd_set_uc_hash_table {
7784         cmdline_fixed_string_t set;
7785         cmdline_fixed_string_t port;
7786         portid_t port_id;
7787         cmdline_fixed_string_t what;
7788         struct ether_addr address;
7789         cmdline_fixed_string_t mode;
7790 };
7791
7792 static void
7793 cmd_set_uc_hash_parsed(void *parsed_result,
7794                        __attribute__((unused)) struct cmdline *cl,
7795                        __attribute__((unused)) void *data)
7796 {
7797         int ret=0;
7798         struct cmd_set_uc_hash_table *res = parsed_result;
7799
7800         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7801
7802         if (strcmp(res->what, "uta") == 0)
7803                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7804                                                 &res->address,(uint8_t)is_on);
7805         if (ret < 0)
7806                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7807
7808 }
7809
7810 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7811         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7812                                  set, "set");
7813 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7814         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7815                                  port, "port");
7816 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7817         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7818                               port_id, UINT16);
7819 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7820         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7821                                  what, "uta");
7822 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7823         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7824                                 address);
7825 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7826         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7827                                  mode, "on#off");
7828
7829 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7830         .f = cmd_set_uc_hash_parsed,
7831         .data = NULL,
7832         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7833         .tokens = {
7834                 (void *)&cmd_set_uc_hash_set,
7835                 (void *)&cmd_set_uc_hash_port,
7836                 (void *)&cmd_set_uc_hash_portid,
7837                 (void *)&cmd_set_uc_hash_what,
7838                 (void *)&cmd_set_uc_hash_mac,
7839                 (void *)&cmd_set_uc_hash_mode,
7840                 NULL,
7841         },
7842 };
7843
7844 struct cmd_set_uc_all_hash_table {
7845         cmdline_fixed_string_t set;
7846         cmdline_fixed_string_t port;
7847         portid_t port_id;
7848         cmdline_fixed_string_t what;
7849         cmdline_fixed_string_t value;
7850         cmdline_fixed_string_t mode;
7851 };
7852
7853 static void
7854 cmd_set_uc_all_hash_parsed(void *parsed_result,
7855                        __attribute__((unused)) struct cmdline *cl,
7856                        __attribute__((unused)) void *data)
7857 {
7858         int ret=0;
7859         struct cmd_set_uc_all_hash_table *res = parsed_result;
7860
7861         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7862
7863         if ((strcmp(res->what, "uta") == 0) &&
7864                 (strcmp(res->value, "all") == 0))
7865                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7866         if (ret < 0)
7867                 printf("bad unicast hash table parameter,"
7868                         "return code = %d \n", ret);
7869 }
7870
7871 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7872         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7873                                  set, "set");
7874 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7875         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7876                                  port, "port");
7877 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7878         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7879                               port_id, UINT16);
7880 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7881         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7882                                  what, "uta");
7883 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7884         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7885                                 value,"all");
7886 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7887         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7888                                  mode, "on#off");
7889
7890 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7891         .f = cmd_set_uc_all_hash_parsed,
7892         .data = NULL,
7893         .help_str = "set port <port_id> uta all on|off",
7894         .tokens = {
7895                 (void *)&cmd_set_uc_all_hash_set,
7896                 (void *)&cmd_set_uc_all_hash_port,
7897                 (void *)&cmd_set_uc_all_hash_portid,
7898                 (void *)&cmd_set_uc_all_hash_what,
7899                 (void *)&cmd_set_uc_all_hash_value,
7900                 (void *)&cmd_set_uc_all_hash_mode,
7901                 NULL,
7902         },
7903 };
7904
7905 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7906 struct cmd_set_vf_macvlan_filter {
7907         cmdline_fixed_string_t set;
7908         cmdline_fixed_string_t port;
7909         portid_t port_id;
7910         cmdline_fixed_string_t vf;
7911         uint8_t vf_id;
7912         struct ether_addr address;
7913         cmdline_fixed_string_t filter_type;
7914         cmdline_fixed_string_t mode;
7915 };
7916
7917 static void
7918 cmd_set_vf_macvlan_parsed(void *parsed_result,
7919                        __attribute__((unused)) struct cmdline *cl,
7920                        __attribute__((unused)) void *data)
7921 {
7922         int is_on, ret = 0;
7923         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7924         struct rte_eth_mac_filter filter;
7925
7926         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7927
7928         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7929
7930         /* set VF MAC filter */
7931         filter.is_vf = 1;
7932
7933         /* set VF ID */
7934         filter.dst_id = res->vf_id;
7935
7936         if (!strcmp(res->filter_type, "exact-mac"))
7937                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7938         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7939                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7940         else if (!strcmp(res->filter_type, "hashmac"))
7941                 filter.filter_type = RTE_MAC_HASH_MATCH;
7942         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7943                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7944
7945         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7946
7947         if (is_on)
7948                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7949                                         RTE_ETH_FILTER_MACVLAN,
7950                                         RTE_ETH_FILTER_ADD,
7951                                          &filter);
7952         else
7953                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7954                                         RTE_ETH_FILTER_MACVLAN,
7955                                         RTE_ETH_FILTER_DELETE,
7956                                         &filter);
7957
7958         if (ret < 0)
7959                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7960
7961 }
7962
7963 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7964         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7965                                  set, "set");
7966 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7967         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7968                                  port, "port");
7969 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7970         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7971                               port_id, UINT16);
7972 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7973         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7974                                  vf, "vf");
7975 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7976         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7977                                 vf_id, UINT8);
7978 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7979         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7980                                 address);
7981 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7982         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7983                                 filter_type, "exact-mac#exact-mac-vlan"
7984                                 "#hashmac#hashmac-vlan");
7985 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7986         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7987                                  mode, "on#off");
7988
7989 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7990         .f = cmd_set_vf_macvlan_parsed,
7991         .data = NULL,
7992         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7993                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7994                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7995                 "hash match rule: hash match of MAC and exact match of VLAN",
7996         .tokens = {
7997                 (void *)&cmd_set_vf_macvlan_set,
7998                 (void *)&cmd_set_vf_macvlan_port,
7999                 (void *)&cmd_set_vf_macvlan_portid,
8000                 (void *)&cmd_set_vf_macvlan_vf,
8001                 (void *)&cmd_set_vf_macvlan_vf_id,
8002                 (void *)&cmd_set_vf_macvlan_mac,
8003                 (void *)&cmd_set_vf_macvlan_filter_type,
8004                 (void *)&cmd_set_vf_macvlan_mode,
8005                 NULL,
8006         },
8007 };
8008
8009 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8010 struct cmd_set_vf_traffic {
8011         cmdline_fixed_string_t set;
8012         cmdline_fixed_string_t port;
8013         portid_t port_id;
8014         cmdline_fixed_string_t vf;
8015         uint8_t vf_id;
8016         cmdline_fixed_string_t what;
8017         cmdline_fixed_string_t mode;
8018 };
8019
8020 static void
8021 cmd_set_vf_traffic_parsed(void *parsed_result,
8022                        __attribute__((unused)) struct cmdline *cl,
8023                        __attribute__((unused)) void *data)
8024 {
8025         struct cmd_set_vf_traffic *res = parsed_result;
8026         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8027         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8028
8029         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8030 }
8031
8032 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8033         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8034                                  set, "set");
8035 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8037                                  port, "port");
8038 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8039         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8040                               port_id, UINT16);
8041 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8042         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8043                                  vf, "vf");
8044 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8045         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8046                               vf_id, UINT8);
8047 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8048         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8049                                  what, "tx#rx");
8050 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8051         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8052                                  mode, "on#off");
8053
8054 cmdline_parse_inst_t cmd_set_vf_traffic = {
8055         .f = cmd_set_vf_traffic_parsed,
8056         .data = NULL,
8057         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8058         .tokens = {
8059                 (void *)&cmd_setvf_traffic_set,
8060                 (void *)&cmd_setvf_traffic_port,
8061                 (void *)&cmd_setvf_traffic_portid,
8062                 (void *)&cmd_setvf_traffic_vf,
8063                 (void *)&cmd_setvf_traffic_vfid,
8064                 (void *)&cmd_setvf_traffic_what,
8065                 (void *)&cmd_setvf_traffic_mode,
8066                 NULL,
8067         },
8068 };
8069
8070 /* *** CONFIGURE VF RECEIVE MODE *** */
8071 struct cmd_set_vf_rxmode {
8072         cmdline_fixed_string_t set;
8073         cmdline_fixed_string_t port;
8074         portid_t port_id;
8075         cmdline_fixed_string_t vf;
8076         uint8_t vf_id;
8077         cmdline_fixed_string_t what;
8078         cmdline_fixed_string_t mode;
8079         cmdline_fixed_string_t on;
8080 };
8081
8082 static void
8083 cmd_set_vf_rxmode_parsed(void *parsed_result,
8084                        __attribute__((unused)) struct cmdline *cl,
8085                        __attribute__((unused)) void *data)
8086 {
8087         int ret = -ENOTSUP;
8088         uint16_t rx_mode = 0;
8089         struct cmd_set_vf_rxmode *res = parsed_result;
8090
8091         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8092         if (!strcmp(res->what,"rxmode")) {
8093                 if (!strcmp(res->mode, "AUPE"))
8094                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8095                 else if (!strcmp(res->mode, "ROPE"))
8096                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8097                 else if (!strcmp(res->mode, "BAM"))
8098                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8099                 else if (!strncmp(res->mode, "MPE",3))
8100                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8101         }
8102
8103         RTE_SET_USED(is_on);
8104
8105 #ifdef RTE_LIBRTE_IXGBE_PMD
8106         if (ret == -ENOTSUP)
8107                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8108                                                   rx_mode, (uint8_t)is_on);
8109 #endif
8110 #ifdef RTE_LIBRTE_BNXT_PMD
8111         if (ret == -ENOTSUP)
8112                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8113                                                  rx_mode, (uint8_t)is_on);
8114 #endif
8115         if (ret < 0)
8116                 printf("bad VF receive mode parameter, return code = %d \n",
8117                 ret);
8118 }
8119
8120 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8121         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8122                                  set, "set");
8123 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8124         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8125                                  port, "port");
8126 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8127         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8128                               port_id, UINT16);
8129 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8130         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8131                                  vf, "vf");
8132 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8133         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8134                               vf_id, UINT8);
8135 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8136         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8137                                  what, "rxmode");
8138 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8139         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8140                                  mode, "AUPE#ROPE#BAM#MPE");
8141 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8142         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8143                                  on, "on#off");
8144
8145 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8146         .f = cmd_set_vf_rxmode_parsed,
8147         .data = NULL,
8148         .help_str = "set port <port_id> vf <vf_id> rxmode "
8149                 "AUPE|ROPE|BAM|MPE on|off",
8150         .tokens = {
8151                 (void *)&cmd_set_vf_rxmode_set,
8152                 (void *)&cmd_set_vf_rxmode_port,
8153                 (void *)&cmd_set_vf_rxmode_portid,
8154                 (void *)&cmd_set_vf_rxmode_vf,
8155                 (void *)&cmd_set_vf_rxmode_vfid,
8156                 (void *)&cmd_set_vf_rxmode_what,
8157                 (void *)&cmd_set_vf_rxmode_mode,
8158                 (void *)&cmd_set_vf_rxmode_on,
8159                 NULL,
8160         },
8161 };
8162
8163 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8164 struct cmd_vf_mac_addr_result {
8165         cmdline_fixed_string_t mac_addr_cmd;
8166         cmdline_fixed_string_t what;
8167         cmdline_fixed_string_t port;
8168         uint16_t port_num;
8169         cmdline_fixed_string_t vf;
8170         uint8_t vf_num;
8171         struct ether_addr address;
8172 };
8173
8174 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8175                 __attribute__((unused)) struct cmdline *cl,
8176                 __attribute__((unused)) void *data)
8177 {
8178         struct cmd_vf_mac_addr_result *res = parsed_result;
8179         int ret = -ENOTSUP;
8180
8181         if (strcmp(res->what, "add") != 0)
8182                 return;
8183
8184 #ifdef RTE_LIBRTE_I40E_PMD
8185         if (ret == -ENOTSUP)
8186                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8187                                                    &res->address);
8188 #endif
8189 #ifdef RTE_LIBRTE_BNXT_PMD
8190         if (ret == -ENOTSUP)
8191                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8192                                                 res->vf_num);
8193 #endif
8194
8195         if(ret < 0)
8196                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8197
8198 }
8199
8200 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8201         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8202                                 mac_addr_cmd,"mac_addr");
8203 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8204         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8205                                 what,"add");
8206 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8207         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8208                                 port,"port");
8209 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8210         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8211                                 port_num, UINT16);
8212 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8213         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8214                                 vf,"vf");
8215 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8216         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8217                                 vf_num, UINT8);
8218 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8219         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8220                                 address);
8221
8222 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8223         .f = cmd_vf_mac_addr_parsed,
8224         .data = (void *)0,
8225         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8226                 "Add MAC address filtering for a VF on port_id",
8227         .tokens = {
8228                 (void *)&cmd_vf_mac_addr_cmd,
8229                 (void *)&cmd_vf_mac_addr_what,
8230                 (void *)&cmd_vf_mac_addr_port,
8231                 (void *)&cmd_vf_mac_addr_portnum,
8232                 (void *)&cmd_vf_mac_addr_vf,
8233                 (void *)&cmd_vf_mac_addr_vfnum,
8234                 (void *)&cmd_vf_mac_addr_addr,
8235                 NULL,
8236         },
8237 };
8238
8239 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8240 struct cmd_vf_rx_vlan_filter {
8241         cmdline_fixed_string_t rx_vlan;
8242         cmdline_fixed_string_t what;
8243         uint16_t vlan_id;
8244         cmdline_fixed_string_t port;
8245         portid_t port_id;
8246         cmdline_fixed_string_t vf;
8247         uint64_t vf_mask;
8248 };
8249
8250 static void
8251 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8252                           __attribute__((unused)) struct cmdline *cl,
8253                           __attribute__((unused)) void *data)
8254 {
8255         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8256         int ret = -ENOTSUP;
8257
8258         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8259
8260 #ifdef RTE_LIBRTE_IXGBE_PMD
8261         if (ret == -ENOTSUP)
8262                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8263                                 res->vlan_id, res->vf_mask, is_add);
8264 #endif
8265 #ifdef RTE_LIBRTE_I40E_PMD
8266         if (ret == -ENOTSUP)
8267                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8268                                 res->vlan_id, res->vf_mask, is_add);
8269 #endif
8270 #ifdef RTE_LIBRTE_BNXT_PMD
8271         if (ret == -ENOTSUP)
8272                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8273                                 res->vlan_id, res->vf_mask, is_add);
8274 #endif
8275
8276         switch (ret) {
8277         case 0:
8278                 break;
8279         case -EINVAL:
8280                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8281                                 res->vlan_id, res->vf_mask);
8282                 break;
8283         case -ENODEV:
8284                 printf("invalid port_id %d\n", res->port_id);
8285                 break;
8286         case -ENOTSUP:
8287                 printf("function not implemented or supported\n");
8288                 break;
8289         default:
8290                 printf("programming error: (%s)\n", strerror(-ret));
8291         }
8292 }
8293
8294 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8295         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8296                                  rx_vlan, "rx_vlan");
8297 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8298         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8299                                  what, "add#rm");
8300 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8301         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8302                               vlan_id, UINT16);
8303 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8304         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8305                                  port, "port");
8306 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8307         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8308                               port_id, UINT16);
8309 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8310         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8311                                  vf, "vf");
8312 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8313         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8314                               vf_mask, UINT64);
8315
8316 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8317         .f = cmd_vf_rx_vlan_filter_parsed,
8318         .data = NULL,
8319         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8320                 "(vf_mask = hexadecimal VF mask)",
8321         .tokens = {
8322                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8323                 (void *)&cmd_vf_rx_vlan_filter_what,
8324                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8325                 (void *)&cmd_vf_rx_vlan_filter_port,
8326                 (void *)&cmd_vf_rx_vlan_filter_portid,
8327                 (void *)&cmd_vf_rx_vlan_filter_vf,
8328                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8329                 NULL,
8330         },
8331 };
8332
8333 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8334 struct cmd_queue_rate_limit_result {
8335         cmdline_fixed_string_t set;
8336         cmdline_fixed_string_t port;
8337         uint16_t port_num;
8338         cmdline_fixed_string_t queue;
8339         uint8_t queue_num;
8340         cmdline_fixed_string_t rate;
8341         uint16_t rate_num;
8342 };
8343
8344 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8345                 __attribute__((unused)) struct cmdline *cl,
8346                 __attribute__((unused)) void *data)
8347 {
8348         struct cmd_queue_rate_limit_result *res = parsed_result;
8349         int ret = 0;
8350
8351         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8352                 && (strcmp(res->queue, "queue") == 0)
8353                 && (strcmp(res->rate, "rate") == 0))
8354                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8355                                         res->rate_num);
8356         if (ret < 0)
8357                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8358
8359 }
8360
8361 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8362         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8363                                 set, "set");
8364 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8365         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8366                                 port, "port");
8367 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8368         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8369                                 port_num, UINT16);
8370 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8371         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8372                                 queue, "queue");
8373 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8374         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8375                                 queue_num, UINT8);
8376 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8377         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8378                                 rate, "rate");
8379 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8380         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8381                                 rate_num, UINT16);
8382
8383 cmdline_parse_inst_t cmd_queue_rate_limit = {
8384         .f = cmd_queue_rate_limit_parsed,
8385         .data = (void *)0,
8386         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8387                 "Set rate limit for a queue on port_id",
8388         .tokens = {
8389                 (void *)&cmd_queue_rate_limit_set,
8390                 (void *)&cmd_queue_rate_limit_port,
8391                 (void *)&cmd_queue_rate_limit_portnum,
8392                 (void *)&cmd_queue_rate_limit_queue,
8393                 (void *)&cmd_queue_rate_limit_queuenum,
8394                 (void *)&cmd_queue_rate_limit_rate,
8395                 (void *)&cmd_queue_rate_limit_ratenum,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8401 struct cmd_vf_rate_limit_result {
8402         cmdline_fixed_string_t set;
8403         cmdline_fixed_string_t port;
8404         uint16_t port_num;
8405         cmdline_fixed_string_t vf;
8406         uint8_t vf_num;
8407         cmdline_fixed_string_t rate;
8408         uint16_t rate_num;
8409         cmdline_fixed_string_t q_msk;
8410         uint64_t q_msk_val;
8411 };
8412
8413 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8414                 __attribute__((unused)) struct cmdline *cl,
8415                 __attribute__((unused)) void *data)
8416 {
8417         struct cmd_vf_rate_limit_result *res = parsed_result;
8418         int ret = 0;
8419
8420         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8421                 && (strcmp(res->vf, "vf") == 0)
8422                 && (strcmp(res->rate, "rate") == 0)
8423                 && (strcmp(res->q_msk, "queue_mask") == 0))
8424                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8425                                         res->rate_num, res->q_msk_val);
8426         if (ret < 0)
8427                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8428
8429 }
8430
8431 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8432         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8433                                 set, "set");
8434 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8435         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8436                                 port, "port");
8437 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8438         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8439                                 port_num, UINT16);
8440 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8441         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8442                                 vf, "vf");
8443 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8444         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8445                                 vf_num, UINT8);
8446 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8447         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8448                                 rate, "rate");
8449 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8450         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8451                                 rate_num, UINT16);
8452 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8453         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8454                                 q_msk, "queue_mask");
8455 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8456         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8457                                 q_msk_val, UINT64);
8458
8459 cmdline_parse_inst_t cmd_vf_rate_limit = {
8460         .f = cmd_vf_rate_limit_parsed,
8461         .data = (void *)0,
8462         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8463                 "queue_mask <queue_mask_value>: "
8464                 "Set rate limit for queues of VF on port_id",
8465         .tokens = {
8466                 (void *)&cmd_vf_rate_limit_set,
8467                 (void *)&cmd_vf_rate_limit_port,
8468                 (void *)&cmd_vf_rate_limit_portnum,
8469                 (void *)&cmd_vf_rate_limit_vf,
8470                 (void *)&cmd_vf_rate_limit_vfnum,
8471                 (void *)&cmd_vf_rate_limit_rate,
8472                 (void *)&cmd_vf_rate_limit_ratenum,
8473                 (void *)&cmd_vf_rate_limit_q_msk,
8474                 (void *)&cmd_vf_rate_limit_q_msk_val,
8475                 NULL,
8476         },
8477 };
8478
8479 /* *** ADD TUNNEL FILTER OF A PORT *** */
8480 struct cmd_tunnel_filter_result {
8481         cmdline_fixed_string_t cmd;
8482         cmdline_fixed_string_t what;
8483         portid_t port_id;
8484         struct ether_addr outer_mac;
8485         struct ether_addr inner_mac;
8486         cmdline_ipaddr_t ip_value;
8487         uint16_t inner_vlan;
8488         cmdline_fixed_string_t tunnel_type;
8489         cmdline_fixed_string_t filter_type;
8490         uint32_t tenant_id;
8491         uint16_t queue_num;
8492 };
8493
8494 static void
8495 cmd_tunnel_filter_parsed(void *parsed_result,
8496                           __attribute__((unused)) struct cmdline *cl,
8497                           __attribute__((unused)) void *data)
8498 {
8499         struct cmd_tunnel_filter_result *res = parsed_result;
8500         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8501         int ret = 0;
8502
8503         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8504
8505         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8506         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8507         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8508
8509         if (res->ip_value.family == AF_INET) {
8510                 tunnel_filter_conf.ip_addr.ipv4_addr =
8511                         res->ip_value.addr.ipv4.s_addr;
8512                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8513         } else {
8514                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8515                         &(res->ip_value.addr.ipv6),
8516                         sizeof(struct in6_addr));
8517                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8518         }
8519
8520         if (!strcmp(res->filter_type, "imac-ivlan"))
8521                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8522         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8523                 tunnel_filter_conf.filter_type =
8524                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8525         else if (!strcmp(res->filter_type, "imac-tenid"))
8526                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8527         else if (!strcmp(res->filter_type, "imac"))
8528                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8529         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8530                 tunnel_filter_conf.filter_type =
8531                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8532         else if (!strcmp(res->filter_type, "oip"))
8533                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8534         else if (!strcmp(res->filter_type, "iip"))
8535                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8536         else {
8537                 printf("The filter type is not supported");
8538                 return;
8539         }
8540
8541         if (!strcmp(res->tunnel_type, "vxlan"))
8542                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8543         else if (!strcmp(res->tunnel_type, "nvgre"))
8544                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8545         else if (!strcmp(res->tunnel_type, "ipingre"))
8546                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8547         else {
8548                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8549                 return;
8550         }
8551
8552         tunnel_filter_conf.tenant_id = res->tenant_id;
8553         tunnel_filter_conf.queue_id = res->queue_num;
8554         if (!strcmp(res->what, "add"))
8555                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8556                                         RTE_ETH_FILTER_TUNNEL,
8557                                         RTE_ETH_FILTER_ADD,
8558                                         &tunnel_filter_conf);
8559         else
8560                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8561                                         RTE_ETH_FILTER_TUNNEL,
8562                                         RTE_ETH_FILTER_DELETE,
8563                                         &tunnel_filter_conf);
8564         if (ret < 0)
8565                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8566                                 strerror(-ret));
8567
8568 }
8569 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8570         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8571         cmd, "tunnel_filter");
8572 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8573         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8574         what, "add#rm");
8575 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8576         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8577         port_id, UINT16);
8578 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8579         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8580         outer_mac);
8581 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8582         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8583         inner_mac);
8584 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8585         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8586         inner_vlan, UINT16);
8587 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8588         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8589         ip_value);
8590 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8591         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8592         tunnel_type, "vxlan#nvgre#ipingre");
8593
8594 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8595         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8596         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8597                 "imac#omac-imac-tenid");
8598 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8599         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8600         tenant_id, UINT32);
8601 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8602         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8603         queue_num, UINT16);
8604
8605 cmdline_parse_inst_t cmd_tunnel_filter = {
8606         .f = cmd_tunnel_filter_parsed,
8607         .data = (void *)0,
8608         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8609                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8610                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8611                 "<queue_id>: Add/Rm tunnel filter of a port",
8612         .tokens = {
8613                 (void *)&cmd_tunnel_filter_cmd,
8614                 (void *)&cmd_tunnel_filter_what,
8615                 (void *)&cmd_tunnel_filter_port_id,
8616                 (void *)&cmd_tunnel_filter_outer_mac,
8617                 (void *)&cmd_tunnel_filter_inner_mac,
8618                 (void *)&cmd_tunnel_filter_ip_value,
8619                 (void *)&cmd_tunnel_filter_innner_vlan,
8620                 (void *)&cmd_tunnel_filter_tunnel_type,
8621                 (void *)&cmd_tunnel_filter_filter_type,
8622                 (void *)&cmd_tunnel_filter_tenant_id,
8623                 (void *)&cmd_tunnel_filter_queue_num,
8624                 NULL,
8625         },
8626 };
8627
8628 /* *** CONFIGURE TUNNEL UDP PORT *** */
8629 struct cmd_tunnel_udp_config {
8630         cmdline_fixed_string_t cmd;
8631         cmdline_fixed_string_t what;
8632         uint16_t udp_port;
8633         portid_t port_id;
8634 };
8635
8636 static void
8637 cmd_tunnel_udp_config_parsed(void *parsed_result,
8638                           __attribute__((unused)) struct cmdline *cl,
8639                           __attribute__((unused)) void *data)
8640 {
8641         struct cmd_tunnel_udp_config *res = parsed_result;
8642         struct rte_eth_udp_tunnel tunnel_udp;
8643         int ret;
8644
8645         tunnel_udp.udp_port = res->udp_port;
8646
8647         if (!strcmp(res->cmd, "rx_vxlan_port"))
8648                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8649
8650         if (!strcmp(res->what, "add"))
8651                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8652                                                       &tunnel_udp);
8653         else
8654                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8655                                                          &tunnel_udp);
8656
8657         if (ret < 0)
8658                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8659 }
8660
8661 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8662         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8663                                 cmd, "rx_vxlan_port");
8664 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8665         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8666                                 what, "add#rm");
8667 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8668         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8669                                 udp_port, UINT16);
8670 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8671         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8672                                 port_id, UINT16);
8673
8674 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8675         .f = cmd_tunnel_udp_config_parsed,
8676         .data = (void *)0,
8677         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8678                 "Add/Remove a tunneling UDP port filter",
8679         .tokens = {
8680                 (void *)&cmd_tunnel_udp_config_cmd,
8681                 (void *)&cmd_tunnel_udp_config_what,
8682                 (void *)&cmd_tunnel_udp_config_udp_port,
8683                 (void *)&cmd_tunnel_udp_config_port_id,
8684                 NULL,
8685         },
8686 };
8687
8688 struct cmd_config_tunnel_udp_port {
8689         cmdline_fixed_string_t port;
8690         cmdline_fixed_string_t config;
8691         portid_t port_id;
8692         cmdline_fixed_string_t udp_tunnel_port;
8693         cmdline_fixed_string_t action;
8694         cmdline_fixed_string_t tunnel_type;
8695         uint16_t udp_port;
8696 };
8697
8698 static void
8699 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
8700                                __attribute__((unused)) struct cmdline *cl,
8701                                __attribute__((unused)) void *data)
8702 {
8703         struct cmd_config_tunnel_udp_port *res = parsed_result;
8704         struct rte_eth_udp_tunnel tunnel_udp;
8705         int ret = 0;
8706
8707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8708                 return;
8709
8710         tunnel_udp.udp_port = res->udp_port;
8711
8712         if (!strcmp(res->tunnel_type, "vxlan")) {
8713                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8714         } else if (!strcmp(res->tunnel_type, "geneve")) {
8715                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
8716         } else {
8717                 printf("Invalid tunnel type\n");
8718                 return;
8719         }
8720
8721         if (!strcmp(res->action, "add"))
8722                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8723                                                       &tunnel_udp);
8724         else
8725                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8726                                                          &tunnel_udp);
8727
8728         if (ret < 0)
8729                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
8730 }
8731
8732 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
8733         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
8734                                  "port");
8735 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
8736         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
8737                                  "config");
8738 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
8739         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
8740                               UINT16);
8741 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
8742         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
8743                                  udp_tunnel_port,
8744                                  "udp_tunnel_port");
8745 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
8746         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
8747                                  "add#rm");
8748 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
8749         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
8750                                  "vxlan#geneve");
8751 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
8752         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
8753                               UINT16);
8754
8755 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
8756         .f = cmd_cfg_tunnel_udp_port_parsed,
8757         .data = NULL,
8758         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve <udp_port>",
8759         .tokens = {
8760                 (void *)&cmd_config_tunnel_udp_port_port,
8761                 (void *)&cmd_config_tunnel_udp_port_config,
8762                 (void *)&cmd_config_tunnel_udp_port_port_id,
8763                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
8764                 (void *)&cmd_config_tunnel_udp_port_action,
8765                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
8766                 (void *)&cmd_config_tunnel_udp_port_value,
8767                 NULL,
8768         },
8769 };
8770
8771 /* *** GLOBAL CONFIG *** */
8772 struct cmd_global_config_result {
8773         cmdline_fixed_string_t cmd;
8774         portid_t port_id;
8775         cmdline_fixed_string_t cfg_type;
8776         uint8_t len;
8777 };
8778
8779 static void
8780 cmd_global_config_parsed(void *parsed_result,
8781                          __attribute__((unused)) struct cmdline *cl,
8782                          __attribute__((unused)) void *data)
8783 {
8784         struct cmd_global_config_result *res = parsed_result;
8785         struct rte_eth_global_cfg conf;
8786         int ret;
8787
8788         memset(&conf, 0, sizeof(conf));
8789         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8790         conf.cfg.gre_key_len = res->len;
8791         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8792                                       RTE_ETH_FILTER_SET, &conf);
8793         if (ret != 0)
8794                 printf("Global config error\n");
8795 }
8796
8797 cmdline_parse_token_string_t cmd_global_config_cmd =
8798         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8799                 "global_config");
8800 cmdline_parse_token_num_t cmd_global_config_port_id =
8801         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8802                                UINT16);
8803 cmdline_parse_token_string_t cmd_global_config_type =
8804         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8805                 cfg_type, "gre-key-len");
8806 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8807         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8808                 len, UINT8);
8809
8810 cmdline_parse_inst_t cmd_global_config = {
8811         .f = cmd_global_config_parsed,
8812         .data = (void *)NULL,
8813         .help_str = "global_config <port_id> gre-key-len <key_len>",
8814         .tokens = {
8815                 (void *)&cmd_global_config_cmd,
8816                 (void *)&cmd_global_config_port_id,
8817                 (void *)&cmd_global_config_type,
8818                 (void *)&cmd_global_config_gre_key_len,
8819                 NULL,
8820         },
8821 };
8822
8823 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8824 struct cmd_set_mirror_mask_result {
8825         cmdline_fixed_string_t set;
8826         cmdline_fixed_string_t port;
8827         portid_t port_id;
8828         cmdline_fixed_string_t mirror;
8829         uint8_t rule_id;
8830         cmdline_fixed_string_t what;
8831         cmdline_fixed_string_t value;
8832         cmdline_fixed_string_t dstpool;
8833         uint8_t dstpool_id;
8834         cmdline_fixed_string_t on;
8835 };
8836
8837 cmdline_parse_token_string_t cmd_mirror_mask_set =
8838         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8839                                 set, "set");
8840 cmdline_parse_token_string_t cmd_mirror_mask_port =
8841         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8842                                 port, "port");
8843 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8844         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8845                                 port_id, UINT16);
8846 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8847         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8848                                 mirror, "mirror-rule");
8849 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8850         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8851                                 rule_id, UINT8);
8852 cmdline_parse_token_string_t cmd_mirror_mask_what =
8853         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8854                                 what, "pool-mirror-up#pool-mirror-down"
8855                                       "#vlan-mirror");
8856 cmdline_parse_token_string_t cmd_mirror_mask_value =
8857         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8858                                 value, NULL);
8859 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8860         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8861                                 dstpool, "dst-pool");
8862 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8863         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8864                                 dstpool_id, UINT8);
8865 cmdline_parse_token_string_t cmd_mirror_mask_on =
8866         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8867                                 on, "on#off");
8868
8869 static void
8870 cmd_set_mirror_mask_parsed(void *parsed_result,
8871                        __attribute__((unused)) struct cmdline *cl,
8872                        __attribute__((unused)) void *data)
8873 {
8874         int ret,nb_item,i;
8875         struct cmd_set_mirror_mask_result *res = parsed_result;
8876         struct rte_eth_mirror_conf mr_conf;
8877
8878         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8879
8880         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8881
8882         mr_conf.dst_pool = res->dstpool_id;
8883
8884         if (!strcmp(res->what, "pool-mirror-up")) {
8885                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8886                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8887         } else if (!strcmp(res->what, "pool-mirror-down")) {
8888                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8889                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8890         } else if (!strcmp(res->what, "vlan-mirror")) {
8891                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8892                 nb_item = parse_item_list(res->value, "vlan",
8893                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8894                 if (nb_item <= 0)
8895                         return;
8896
8897                 for (i = 0; i < nb_item; i++) {
8898                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8899                                 printf("Invalid vlan_id: must be < 4096\n");
8900                                 return;
8901                         }
8902
8903                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8904                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8905                 }
8906         }
8907
8908         if (!strcmp(res->on, "on"))
8909                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8910                                                 res->rule_id, 1);
8911         else
8912                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8913                                                 res->rule_id, 0);
8914         if (ret < 0)
8915                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8916 }
8917
8918 cmdline_parse_inst_t cmd_set_mirror_mask = {
8919                 .f = cmd_set_mirror_mask_parsed,
8920                 .data = NULL,
8921                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8922                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8923                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8924                 .tokens = {
8925                         (void *)&cmd_mirror_mask_set,
8926                         (void *)&cmd_mirror_mask_port,
8927                         (void *)&cmd_mirror_mask_portid,
8928                         (void *)&cmd_mirror_mask_mirror,
8929                         (void *)&cmd_mirror_mask_ruleid,
8930                         (void *)&cmd_mirror_mask_what,
8931                         (void *)&cmd_mirror_mask_value,
8932                         (void *)&cmd_mirror_mask_dstpool,
8933                         (void *)&cmd_mirror_mask_poolid,
8934                         (void *)&cmd_mirror_mask_on,
8935                         NULL,
8936                 },
8937 };
8938
8939 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8940 struct cmd_set_mirror_link_result {
8941         cmdline_fixed_string_t set;
8942         cmdline_fixed_string_t port;
8943         portid_t port_id;
8944         cmdline_fixed_string_t mirror;
8945         uint8_t rule_id;
8946         cmdline_fixed_string_t what;
8947         cmdline_fixed_string_t dstpool;
8948         uint8_t dstpool_id;
8949         cmdline_fixed_string_t on;
8950 };
8951
8952 cmdline_parse_token_string_t cmd_mirror_link_set =
8953         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8954                                  set, "set");
8955 cmdline_parse_token_string_t cmd_mirror_link_port =
8956         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8957                                 port, "port");
8958 cmdline_parse_token_num_t cmd_mirror_link_portid =
8959         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8960                                 port_id, UINT16);
8961 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8962         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8963                                 mirror, "mirror-rule");
8964 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8965         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8966                             rule_id, UINT8);
8967 cmdline_parse_token_string_t cmd_mirror_link_what =
8968         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8969                                 what, "uplink-mirror#downlink-mirror");
8970 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8971         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8972                                 dstpool, "dst-pool");
8973 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8974         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8975                                 dstpool_id, UINT8);
8976 cmdline_parse_token_string_t cmd_mirror_link_on =
8977         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8978                                 on, "on#off");
8979
8980 static void
8981 cmd_set_mirror_link_parsed(void *parsed_result,
8982                        __attribute__((unused)) struct cmdline *cl,
8983                        __attribute__((unused)) void *data)
8984 {
8985         int ret;
8986         struct cmd_set_mirror_link_result *res = parsed_result;
8987         struct rte_eth_mirror_conf mr_conf;
8988
8989         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8990         if (!strcmp(res->what, "uplink-mirror"))
8991                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8992         else
8993                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8994
8995         mr_conf.dst_pool = res->dstpool_id;
8996
8997         if (!strcmp(res->on, "on"))
8998                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8999                                                 res->rule_id, 1);
9000         else
9001                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9002                                                 res->rule_id, 0);
9003
9004         /* check the return value and print it if is < 0 */
9005         if (ret < 0)
9006                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9007
9008 }
9009
9010 cmdline_parse_inst_t cmd_set_mirror_link = {
9011                 .f = cmd_set_mirror_link_parsed,
9012                 .data = NULL,
9013                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9014                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9015                 .tokens = {
9016                         (void *)&cmd_mirror_link_set,
9017                         (void *)&cmd_mirror_link_port,
9018                         (void *)&cmd_mirror_link_portid,
9019                         (void *)&cmd_mirror_link_mirror,
9020                         (void *)&cmd_mirror_link_ruleid,
9021                         (void *)&cmd_mirror_link_what,
9022                         (void *)&cmd_mirror_link_dstpool,
9023                         (void *)&cmd_mirror_link_poolid,
9024                         (void *)&cmd_mirror_link_on,
9025                         NULL,
9026                 },
9027 };
9028
9029 /* *** RESET VM MIRROR RULE *** */
9030 struct cmd_rm_mirror_rule_result {
9031         cmdline_fixed_string_t reset;
9032         cmdline_fixed_string_t port;
9033         portid_t port_id;
9034         cmdline_fixed_string_t mirror;
9035         uint8_t rule_id;
9036 };
9037
9038 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9039         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9040                                  reset, "reset");
9041 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9042         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9043                                 port, "port");
9044 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9045         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9046                                 port_id, UINT16);
9047 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9048         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9049                                 mirror, "mirror-rule");
9050 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9051         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9052                                 rule_id, UINT8);
9053
9054 static void
9055 cmd_reset_mirror_rule_parsed(void *parsed_result,
9056                        __attribute__((unused)) struct cmdline *cl,
9057                        __attribute__((unused)) void *data)
9058 {
9059         int ret;
9060         struct cmd_set_mirror_link_result *res = parsed_result;
9061         /* check rule_id */
9062         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9063         if(ret < 0)
9064                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9065 }
9066
9067 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9068                 .f = cmd_reset_mirror_rule_parsed,
9069                 .data = NULL,
9070                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9071                 .tokens = {
9072                         (void *)&cmd_rm_mirror_rule_reset,
9073                         (void *)&cmd_rm_mirror_rule_port,
9074                         (void *)&cmd_rm_mirror_rule_portid,
9075                         (void *)&cmd_rm_mirror_rule_mirror,
9076                         (void *)&cmd_rm_mirror_rule_ruleid,
9077                         NULL,
9078                 },
9079 };
9080
9081 /* ******************************************************************************** */
9082
9083 struct cmd_dump_result {
9084         cmdline_fixed_string_t dump;
9085 };
9086
9087 static void
9088 dump_struct_sizes(void)
9089 {
9090 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9091         DUMP_SIZE(struct rte_mbuf);
9092         DUMP_SIZE(struct rte_mempool);
9093         DUMP_SIZE(struct rte_ring);
9094 #undef DUMP_SIZE
9095 }
9096
9097 static void cmd_dump_parsed(void *parsed_result,
9098                             __attribute__((unused)) struct cmdline *cl,
9099                             __attribute__((unused)) void *data)
9100 {
9101         struct cmd_dump_result *res = parsed_result;
9102
9103         if (!strcmp(res->dump, "dump_physmem"))
9104                 rte_dump_physmem_layout(stdout);
9105         else if (!strcmp(res->dump, "dump_memzone"))
9106                 rte_memzone_dump(stdout);
9107         else if (!strcmp(res->dump, "dump_struct_sizes"))
9108                 dump_struct_sizes();
9109         else if (!strcmp(res->dump, "dump_ring"))
9110                 rte_ring_list_dump(stdout);
9111         else if (!strcmp(res->dump, "dump_mempool"))
9112                 rte_mempool_list_dump(stdout);
9113         else if (!strcmp(res->dump, "dump_devargs"))
9114                 rte_devargs_dump(stdout);
9115         else if (!strcmp(res->dump, "dump_log_types"))
9116                 rte_log_dump(stdout);
9117 }
9118
9119 cmdline_parse_token_string_t cmd_dump_dump =
9120         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9121                 "dump_physmem#"
9122                 "dump_memzone#"
9123                 "dump_struct_sizes#"
9124                 "dump_ring#"
9125                 "dump_mempool#"
9126                 "dump_devargs#"
9127                 "dump_log_types");
9128
9129 cmdline_parse_inst_t cmd_dump = {
9130         .f = cmd_dump_parsed,  /* function to call */
9131         .data = NULL,      /* 2nd arg of func */
9132         .help_str = "Dump status",
9133         .tokens = {        /* token list, NULL terminated */
9134                 (void *)&cmd_dump_dump,
9135                 NULL,
9136         },
9137 };
9138
9139 /* ******************************************************************************** */
9140
9141 struct cmd_dump_one_result {
9142         cmdline_fixed_string_t dump;
9143         cmdline_fixed_string_t name;
9144 };
9145
9146 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9147                                 __attribute__((unused)) void *data)
9148 {
9149         struct cmd_dump_one_result *res = parsed_result;
9150
9151         if (!strcmp(res->dump, "dump_ring")) {
9152                 struct rte_ring *r;
9153                 r = rte_ring_lookup(res->name);
9154                 if (r == NULL) {
9155                         cmdline_printf(cl, "Cannot find ring\n");
9156                         return;
9157                 }
9158                 rte_ring_dump(stdout, r);
9159         } else if (!strcmp(res->dump, "dump_mempool")) {
9160                 struct rte_mempool *mp;
9161                 mp = rte_mempool_lookup(res->name);
9162                 if (mp == NULL) {
9163                         cmdline_printf(cl, "Cannot find mempool\n");
9164                         return;
9165                 }
9166                 rte_mempool_dump(stdout, mp);
9167         }
9168 }
9169
9170 cmdline_parse_token_string_t cmd_dump_one_dump =
9171         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9172                                  "dump_ring#dump_mempool");
9173
9174 cmdline_parse_token_string_t cmd_dump_one_name =
9175         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9176
9177 cmdline_parse_inst_t cmd_dump_one = {
9178         .f = cmd_dump_one_parsed,  /* function to call */
9179         .data = NULL,      /* 2nd arg of func */
9180         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9181         .tokens = {        /* token list, NULL terminated */
9182                 (void *)&cmd_dump_one_dump,
9183                 (void *)&cmd_dump_one_name,
9184                 NULL,
9185         },
9186 };
9187
9188 /* *** Add/Del syn filter *** */
9189 struct cmd_syn_filter_result {
9190         cmdline_fixed_string_t filter;
9191         portid_t port_id;
9192         cmdline_fixed_string_t ops;
9193         cmdline_fixed_string_t priority;
9194         cmdline_fixed_string_t high;
9195         cmdline_fixed_string_t queue;
9196         uint16_t queue_id;
9197 };
9198
9199 static void
9200 cmd_syn_filter_parsed(void *parsed_result,
9201                         __attribute__((unused)) struct cmdline *cl,
9202                         __attribute__((unused)) void *data)
9203 {
9204         struct cmd_syn_filter_result *res = parsed_result;
9205         struct rte_eth_syn_filter syn_filter;
9206         int ret = 0;
9207
9208         ret = rte_eth_dev_filter_supported(res->port_id,
9209                                         RTE_ETH_FILTER_SYN);
9210         if (ret < 0) {
9211                 printf("syn filter is not supported on port %u.\n",
9212                                 res->port_id);
9213                 return;
9214         }
9215
9216         memset(&syn_filter, 0, sizeof(syn_filter));
9217
9218         if (!strcmp(res->ops, "add")) {
9219                 if (!strcmp(res->high, "high"))
9220                         syn_filter.hig_pri = 1;
9221                 else
9222                         syn_filter.hig_pri = 0;
9223
9224                 syn_filter.queue = res->queue_id;
9225                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9226                                                 RTE_ETH_FILTER_SYN,
9227                                                 RTE_ETH_FILTER_ADD,
9228                                                 &syn_filter);
9229         } else
9230                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9231                                                 RTE_ETH_FILTER_SYN,
9232                                                 RTE_ETH_FILTER_DELETE,
9233                                                 &syn_filter);
9234
9235         if (ret < 0)
9236                 printf("syn filter programming error: (%s)\n",
9237                                 strerror(-ret));
9238 }
9239
9240 cmdline_parse_token_string_t cmd_syn_filter_filter =
9241         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9242         filter, "syn_filter");
9243 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9244         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9245         port_id, UINT16);
9246 cmdline_parse_token_string_t cmd_syn_filter_ops =
9247         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9248         ops, "add#del");
9249 cmdline_parse_token_string_t cmd_syn_filter_priority =
9250         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9251                                 priority, "priority");
9252 cmdline_parse_token_string_t cmd_syn_filter_high =
9253         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9254                                 high, "high#low");
9255 cmdline_parse_token_string_t cmd_syn_filter_queue =
9256         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9257                                 queue, "queue");
9258 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9259         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9260                                 queue_id, UINT16);
9261
9262 cmdline_parse_inst_t cmd_syn_filter = {
9263         .f = cmd_syn_filter_parsed,
9264         .data = NULL,
9265         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9266                 "<queue_id>: Add/Delete syn filter",
9267         .tokens = {
9268                 (void *)&cmd_syn_filter_filter,
9269                 (void *)&cmd_syn_filter_port_id,
9270                 (void *)&cmd_syn_filter_ops,
9271                 (void *)&cmd_syn_filter_priority,
9272                 (void *)&cmd_syn_filter_high,
9273                 (void *)&cmd_syn_filter_queue,
9274                 (void *)&cmd_syn_filter_queue_id,
9275                 NULL,
9276         },
9277 };
9278
9279 /* *** queue region set *** */
9280 struct cmd_queue_region_result {
9281         cmdline_fixed_string_t set;
9282         cmdline_fixed_string_t port;
9283         portid_t port_id;
9284         cmdline_fixed_string_t cmd;
9285         cmdline_fixed_string_t region;
9286         uint8_t  region_id;
9287         cmdline_fixed_string_t queue_start_index;
9288         uint8_t  queue_id;
9289         cmdline_fixed_string_t queue_num;
9290         uint8_t  queue_num_value;
9291 };
9292
9293 static void
9294 cmd_queue_region_parsed(void *parsed_result,
9295                         __attribute__((unused)) struct cmdline *cl,
9296                         __attribute__((unused)) void *data)
9297 {
9298         struct cmd_queue_region_result *res = parsed_result;
9299         int ret = -ENOTSUP;
9300 #ifdef RTE_LIBRTE_I40E_PMD
9301         struct rte_pmd_i40e_queue_region_conf region_conf;
9302         enum rte_pmd_i40e_queue_region_op op_type;
9303 #endif
9304
9305         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9306                 return;
9307
9308 #ifdef RTE_LIBRTE_I40E_PMD
9309         memset(&region_conf, 0, sizeof(region_conf));
9310         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9311         region_conf.region_id = res->region_id;
9312         region_conf.queue_num = res->queue_num_value;
9313         region_conf.queue_start_index = res->queue_id;
9314
9315         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9316                                 op_type, &region_conf);
9317 #endif
9318
9319         switch (ret) {
9320         case 0:
9321                 break;
9322         case -ENOTSUP:
9323                 printf("function not implemented or supported\n");
9324                 break;
9325         default:
9326                 printf("queue region config error: (%s)\n", strerror(-ret));
9327         }
9328 }
9329
9330 cmdline_parse_token_string_t cmd_queue_region_set =
9331 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9332                 set, "set");
9333 cmdline_parse_token_string_t cmd_queue_region_port =
9334         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9335 cmdline_parse_token_num_t cmd_queue_region_port_id =
9336         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9337                                 port_id, UINT16);
9338 cmdline_parse_token_string_t cmd_queue_region_cmd =
9339         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9340                                  cmd, "queue-region");
9341 cmdline_parse_token_string_t cmd_queue_region_id =
9342         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9343                                 region, "region_id");
9344 cmdline_parse_token_num_t cmd_queue_region_index =
9345         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9346                                 region_id, UINT8);
9347 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9348         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9349                                 queue_start_index, "queue_start_index");
9350 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9351         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9352                                 queue_id, UINT8);
9353 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9354         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9355                                 queue_num, "queue_num");
9356 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9357         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9358                                 queue_num_value, UINT8);
9359
9360 cmdline_parse_inst_t cmd_queue_region = {
9361         .f = cmd_queue_region_parsed,
9362         .data = NULL,
9363         .help_str = "set port <port_id> queue-region region_id <value> "
9364                 "queue_start_index <value> queue_num <value>: Set a queue region",
9365         .tokens = {
9366                 (void *)&cmd_queue_region_set,
9367                 (void *)&cmd_queue_region_port,
9368                 (void *)&cmd_queue_region_port_id,
9369                 (void *)&cmd_queue_region_cmd,
9370                 (void *)&cmd_queue_region_id,
9371                 (void *)&cmd_queue_region_index,
9372                 (void *)&cmd_queue_region_queue_start_index,
9373                 (void *)&cmd_queue_region_queue_id,
9374                 (void *)&cmd_queue_region_queue_num,
9375                 (void *)&cmd_queue_region_queue_num_value,
9376                 NULL,
9377         },
9378 };
9379
9380 /* *** queue region and flowtype set *** */
9381 struct cmd_region_flowtype_result {
9382         cmdline_fixed_string_t set;
9383         cmdline_fixed_string_t port;
9384         portid_t port_id;
9385         cmdline_fixed_string_t cmd;
9386         cmdline_fixed_string_t region;
9387         uint8_t  region_id;
9388         cmdline_fixed_string_t flowtype;
9389         uint8_t  flowtype_id;
9390 };
9391
9392 static void
9393 cmd_region_flowtype_parsed(void *parsed_result,
9394                         __attribute__((unused)) struct cmdline *cl,
9395                         __attribute__((unused)) void *data)
9396 {
9397         struct cmd_region_flowtype_result *res = parsed_result;
9398         int ret = -ENOTSUP;
9399 #ifdef RTE_LIBRTE_I40E_PMD
9400         struct rte_pmd_i40e_queue_region_conf region_conf;
9401         enum rte_pmd_i40e_queue_region_op op_type;
9402 #endif
9403
9404         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9405                 return;
9406
9407 #ifdef RTE_LIBRTE_I40E_PMD
9408         memset(&region_conf, 0, sizeof(region_conf));
9409
9410         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9411         region_conf.region_id = res->region_id;
9412         region_conf.hw_flowtype = res->flowtype_id;
9413
9414         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9415                         op_type, &region_conf);
9416 #endif
9417
9418         switch (ret) {
9419         case 0:
9420                 break;
9421         case -ENOTSUP:
9422                 printf("function not implemented or supported\n");
9423                 break;
9424         default:
9425                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9426         }
9427 }
9428
9429 cmdline_parse_token_string_t cmd_region_flowtype_set =
9430 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9431                                 set, "set");
9432 cmdline_parse_token_string_t cmd_region_flowtype_port =
9433         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9434                                 port, "port");
9435 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9436         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9437                                 port_id, UINT16);
9438 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9439         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9440                                 cmd, "queue-region");
9441 cmdline_parse_token_string_t cmd_region_flowtype_index =
9442         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9443                                 region, "region_id");
9444 cmdline_parse_token_num_t cmd_region_flowtype_id =
9445         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9446                                 region_id, UINT8);
9447 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9448         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9449                                 flowtype, "flowtype");
9450 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9451         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9452                                 flowtype_id, UINT8);
9453 cmdline_parse_inst_t cmd_region_flowtype = {
9454         .f = cmd_region_flowtype_parsed,
9455         .data = NULL,
9456         .help_str = "set port <port_id> queue-region region_id <value> "
9457                 "flowtype <value>: Set a flowtype region index",
9458         .tokens = {
9459                 (void *)&cmd_region_flowtype_set,
9460                 (void *)&cmd_region_flowtype_port,
9461                 (void *)&cmd_region_flowtype_port_index,
9462                 (void *)&cmd_region_flowtype_cmd,
9463                 (void *)&cmd_region_flowtype_index,
9464                 (void *)&cmd_region_flowtype_id,
9465                 (void *)&cmd_region_flowtype_flow_index,
9466                 (void *)&cmd_region_flowtype_flow_id,
9467                 NULL,
9468         },
9469 };
9470
9471 /* *** User Priority (UP) to queue region (region_id) set *** */
9472 struct cmd_user_priority_region_result {
9473         cmdline_fixed_string_t set;
9474         cmdline_fixed_string_t port;
9475         portid_t port_id;
9476         cmdline_fixed_string_t cmd;
9477         cmdline_fixed_string_t user_priority;
9478         uint8_t  user_priority_id;
9479         cmdline_fixed_string_t region;
9480         uint8_t  region_id;
9481 };
9482
9483 static void
9484 cmd_user_priority_region_parsed(void *parsed_result,
9485                         __attribute__((unused)) struct cmdline *cl,
9486                         __attribute__((unused)) void *data)
9487 {
9488         struct cmd_user_priority_region_result *res = parsed_result;
9489         int ret = -ENOTSUP;
9490 #ifdef RTE_LIBRTE_I40E_PMD
9491         struct rte_pmd_i40e_queue_region_conf region_conf;
9492         enum rte_pmd_i40e_queue_region_op op_type;
9493 #endif
9494
9495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9496                 return;
9497
9498 #ifdef RTE_LIBRTE_I40E_PMD
9499         memset(&region_conf, 0, sizeof(region_conf));
9500         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9501         region_conf.user_priority = res->user_priority_id;
9502         region_conf.region_id = res->region_id;
9503
9504         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9505                                 op_type, &region_conf);
9506 #endif
9507
9508         switch (ret) {
9509         case 0:
9510                 break;
9511         case -ENOTSUP:
9512                 printf("function not implemented or supported\n");
9513                 break;
9514         default:
9515                 printf("user_priority region config error: (%s)\n",
9516                                 strerror(-ret));
9517         }
9518 }
9519
9520 cmdline_parse_token_string_t cmd_user_priority_region_set =
9521         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9522                                 set, "set");
9523 cmdline_parse_token_string_t cmd_user_priority_region_port =
9524         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9525                                 port, "port");
9526 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9527         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9528                                 port_id, UINT16);
9529 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9530         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9531                                 cmd, "queue-region");
9532 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9533         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9534                                 user_priority, "UP");
9535 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9536         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9537                                 user_priority_id, UINT8);
9538 cmdline_parse_token_string_t cmd_user_priority_region_region =
9539         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9540                                 region, "region_id");
9541 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9542         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9543                                 region_id, UINT8);
9544
9545 cmdline_parse_inst_t cmd_user_priority_region = {
9546         .f = cmd_user_priority_region_parsed,
9547         .data = NULL,
9548         .help_str = "set port <port_id> queue-region UP <value> "
9549                 "region_id <value>: Set the mapping of User Priority (UP) "
9550                 "to queue region (region_id) ",
9551         .tokens = {
9552                 (void *)&cmd_user_priority_region_set,
9553                 (void *)&cmd_user_priority_region_port,
9554                 (void *)&cmd_user_priority_region_port_index,
9555                 (void *)&cmd_user_priority_region_cmd,
9556                 (void *)&cmd_user_priority_region_UP,
9557                 (void *)&cmd_user_priority_region_UP_id,
9558                 (void *)&cmd_user_priority_region_region,
9559                 (void *)&cmd_user_priority_region_region_id,
9560                 NULL,
9561         },
9562 };
9563
9564 /* *** flush all queue region related configuration *** */
9565 struct cmd_flush_queue_region_result {
9566         cmdline_fixed_string_t set;
9567         cmdline_fixed_string_t port;
9568         portid_t port_id;
9569         cmdline_fixed_string_t cmd;
9570         cmdline_fixed_string_t flush;
9571         cmdline_fixed_string_t what;
9572 };
9573
9574 static void
9575 cmd_flush_queue_region_parsed(void *parsed_result,
9576                         __attribute__((unused)) struct cmdline *cl,
9577                         __attribute__((unused)) void *data)
9578 {
9579         struct cmd_flush_queue_region_result *res = parsed_result;
9580         int ret = -ENOTSUP;
9581 #ifdef RTE_LIBRTE_I40E_PMD
9582         struct rte_pmd_i40e_queue_region_conf region_conf;
9583         enum rte_pmd_i40e_queue_region_op op_type;
9584 #endif
9585
9586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9587                 return;
9588
9589 #ifdef RTE_LIBRTE_I40E_PMD
9590         memset(&region_conf, 0, sizeof(region_conf));
9591
9592         if (strcmp(res->what, "on") == 0)
9593                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9594         else
9595                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9596
9597         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9598                                 op_type, &region_conf);
9599 #endif
9600
9601         switch (ret) {
9602         case 0:
9603                 break;
9604         case -ENOTSUP:
9605                 printf("function not implemented or supported\n");
9606                 break;
9607         default:
9608                 printf("queue region config flush error: (%s)\n",
9609                                 strerror(-ret));
9610         }
9611 }
9612
9613 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9614         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9615                                 set, "set");
9616 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9617         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9618                                 port, "port");
9619 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9620         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9621                                 port_id, UINT16);
9622 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9623         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9624                                 cmd, "queue-region");
9625 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9626         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9627                                 flush, "flush");
9628 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9629         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9630                                 what, "on#off");
9631
9632 cmdline_parse_inst_t cmd_flush_queue_region = {
9633         .f = cmd_flush_queue_region_parsed,
9634         .data = NULL,
9635         .help_str = "set port <port_id> queue-region flush on|off"
9636                 ": flush all queue region related configuration",
9637         .tokens = {
9638                 (void *)&cmd_flush_queue_region_set,
9639                 (void *)&cmd_flush_queue_region_port,
9640                 (void *)&cmd_flush_queue_region_port_index,
9641                 (void *)&cmd_flush_queue_region_cmd,
9642                 (void *)&cmd_flush_queue_region_flush,
9643                 (void *)&cmd_flush_queue_region_what,
9644                 NULL,
9645         },
9646 };
9647
9648 /* *** get all queue region related configuration info *** */
9649 struct cmd_show_queue_region_info {
9650         cmdline_fixed_string_t show;
9651         cmdline_fixed_string_t port;
9652         portid_t port_id;
9653         cmdline_fixed_string_t cmd;
9654 };
9655
9656 static void
9657 cmd_show_queue_region_info_parsed(void *parsed_result,
9658                         __attribute__((unused)) struct cmdline *cl,
9659                         __attribute__((unused)) void *data)
9660 {
9661         struct cmd_show_queue_region_info *res = parsed_result;
9662         int ret = -ENOTSUP;
9663 #ifdef RTE_LIBRTE_I40E_PMD
9664         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9665         enum rte_pmd_i40e_queue_region_op op_type;
9666 #endif
9667
9668         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9669                 return;
9670
9671 #ifdef RTE_LIBRTE_I40E_PMD
9672         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9673
9674         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9675
9676         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9677                                         op_type, &rte_pmd_regions);
9678
9679         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9680 #endif
9681
9682         switch (ret) {
9683         case 0:
9684                 break;
9685         case -ENOTSUP:
9686                 printf("function not implemented or supported\n");
9687                 break;
9688         default:
9689                 printf("queue region config info show error: (%s)\n",
9690                                 strerror(-ret));
9691         }
9692 }
9693
9694 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9695 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9696                                 show, "show");
9697 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9698         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9699                                 port, "port");
9700 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9701         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9702                                 port_id, UINT16);
9703 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9704         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9705                                 cmd, "queue-region");
9706
9707 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9708         .f = cmd_show_queue_region_info_parsed,
9709         .data = NULL,
9710         .help_str = "show port <port_id> queue-region"
9711                 ": show all queue region related configuration info",
9712         .tokens = {
9713                 (void *)&cmd_show_queue_region_info_get,
9714                 (void *)&cmd_show_queue_region_info_port,
9715                 (void *)&cmd_show_queue_region_info_port_index,
9716                 (void *)&cmd_show_queue_region_info_cmd,
9717                 NULL,
9718         },
9719 };
9720
9721 /* *** ADD/REMOVE A 2tuple FILTER *** */
9722 struct cmd_2tuple_filter_result {
9723         cmdline_fixed_string_t filter;
9724         portid_t port_id;
9725         cmdline_fixed_string_t ops;
9726         cmdline_fixed_string_t dst_port;
9727         uint16_t dst_port_value;
9728         cmdline_fixed_string_t protocol;
9729         uint8_t protocol_value;
9730         cmdline_fixed_string_t mask;
9731         uint8_t  mask_value;
9732         cmdline_fixed_string_t tcp_flags;
9733         uint8_t tcp_flags_value;
9734         cmdline_fixed_string_t priority;
9735         uint8_t  priority_value;
9736         cmdline_fixed_string_t queue;
9737         uint16_t  queue_id;
9738 };
9739
9740 static void
9741 cmd_2tuple_filter_parsed(void *parsed_result,
9742                         __attribute__((unused)) struct cmdline *cl,
9743                         __attribute__((unused)) void *data)
9744 {
9745         struct rte_eth_ntuple_filter filter;
9746         struct cmd_2tuple_filter_result *res = parsed_result;
9747         int ret = 0;
9748
9749         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9750         if (ret < 0) {
9751                 printf("ntuple filter is not supported on port %u.\n",
9752                         res->port_id);
9753                 return;
9754         }
9755
9756         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9757
9758         filter.flags = RTE_2TUPLE_FLAGS;
9759         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9760         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9761         filter.proto = res->protocol_value;
9762         filter.priority = res->priority_value;
9763         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9764                 printf("nonzero tcp_flags is only meaningful"
9765                         " when protocol is TCP.\n");
9766                 return;
9767         }
9768         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9769                 printf("invalid TCP flags.\n");
9770                 return;
9771         }
9772
9773         if (res->tcp_flags_value != 0) {
9774                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9775                 filter.tcp_flags = res->tcp_flags_value;
9776         }
9777
9778         /* need convert to big endian. */
9779         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9780         filter.queue = res->queue_id;
9781
9782         if (!strcmp(res->ops, "add"))
9783                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9784                                 RTE_ETH_FILTER_NTUPLE,
9785                                 RTE_ETH_FILTER_ADD,
9786                                 &filter);
9787         else
9788                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9789                                 RTE_ETH_FILTER_NTUPLE,
9790                                 RTE_ETH_FILTER_DELETE,
9791                                 &filter);
9792         if (ret < 0)
9793                 printf("2tuple filter programming error: (%s)\n",
9794                         strerror(-ret));
9795
9796 }
9797
9798 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9799         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9800                                  filter, "2tuple_filter");
9801 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9802         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9803                                 port_id, UINT16);
9804 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9805         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9806                                  ops, "add#del");
9807 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9808         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9809                                 dst_port, "dst_port");
9810 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9811         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9812                                 dst_port_value, UINT16);
9813 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9814         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9815                                 protocol, "protocol");
9816 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9817         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9818                                 protocol_value, UINT8);
9819 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9820         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9821                                 mask, "mask");
9822 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9823         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9824                                 mask_value, INT8);
9825 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9826         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9827                                 tcp_flags, "tcp_flags");
9828 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9829         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9830                                 tcp_flags_value, UINT8);
9831 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9832         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9833                                 priority, "priority");
9834 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9835         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9836                                 priority_value, UINT8);
9837 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9838         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9839                                 queue, "queue");
9840 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9841         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9842                                 queue_id, UINT16);
9843
9844 cmdline_parse_inst_t cmd_2tuple_filter = {
9845         .f = cmd_2tuple_filter_parsed,
9846         .data = NULL,
9847         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9848                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9849                 "<queue_id>: Add a 2tuple filter",
9850         .tokens = {
9851                 (void *)&cmd_2tuple_filter_filter,
9852                 (void *)&cmd_2tuple_filter_port_id,
9853                 (void *)&cmd_2tuple_filter_ops,
9854                 (void *)&cmd_2tuple_filter_dst_port,
9855                 (void *)&cmd_2tuple_filter_dst_port_value,
9856                 (void *)&cmd_2tuple_filter_protocol,
9857                 (void *)&cmd_2tuple_filter_protocol_value,
9858                 (void *)&cmd_2tuple_filter_mask,
9859                 (void *)&cmd_2tuple_filter_mask_value,
9860                 (void *)&cmd_2tuple_filter_tcp_flags,
9861                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9862                 (void *)&cmd_2tuple_filter_priority,
9863                 (void *)&cmd_2tuple_filter_priority_value,
9864                 (void *)&cmd_2tuple_filter_queue,
9865                 (void *)&cmd_2tuple_filter_queue_id,
9866                 NULL,
9867         },
9868 };
9869
9870 /* *** ADD/REMOVE A 5tuple FILTER *** */
9871 struct cmd_5tuple_filter_result {
9872         cmdline_fixed_string_t filter;
9873         portid_t port_id;
9874         cmdline_fixed_string_t ops;
9875         cmdline_fixed_string_t dst_ip;
9876         cmdline_ipaddr_t dst_ip_value;
9877         cmdline_fixed_string_t src_ip;
9878         cmdline_ipaddr_t src_ip_value;
9879         cmdline_fixed_string_t dst_port;
9880         uint16_t dst_port_value;
9881         cmdline_fixed_string_t src_port;
9882         uint16_t src_port_value;
9883         cmdline_fixed_string_t protocol;
9884         uint8_t protocol_value;
9885         cmdline_fixed_string_t mask;
9886         uint8_t  mask_value;
9887         cmdline_fixed_string_t tcp_flags;
9888         uint8_t tcp_flags_value;
9889         cmdline_fixed_string_t priority;
9890         uint8_t  priority_value;
9891         cmdline_fixed_string_t queue;
9892         uint16_t  queue_id;
9893 };
9894
9895 static void
9896 cmd_5tuple_filter_parsed(void *parsed_result,
9897                         __attribute__((unused)) struct cmdline *cl,
9898                         __attribute__((unused)) void *data)
9899 {
9900         struct rte_eth_ntuple_filter filter;
9901         struct cmd_5tuple_filter_result *res = parsed_result;
9902         int ret = 0;
9903
9904         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9905         if (ret < 0) {
9906                 printf("ntuple filter is not supported on port %u.\n",
9907                         res->port_id);
9908                 return;
9909         }
9910
9911         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9912
9913         filter.flags = RTE_5TUPLE_FLAGS;
9914         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9915         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9916         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9917         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9918         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9919         filter.proto = res->protocol_value;
9920         filter.priority = res->priority_value;
9921         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9922                 printf("nonzero tcp_flags is only meaningful"
9923                         " when protocol is TCP.\n");
9924                 return;
9925         }
9926         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9927                 printf("invalid TCP flags.\n");
9928                 return;
9929         }
9930
9931         if (res->tcp_flags_value != 0) {
9932                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9933                 filter.tcp_flags = res->tcp_flags_value;
9934         }
9935
9936         if (res->dst_ip_value.family == AF_INET)
9937                 /* no need to convert, already big endian. */
9938                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9939         else {
9940                 if (filter.dst_ip_mask == 0) {
9941                         printf("can not support ipv6 involved compare.\n");
9942                         return;
9943                 }
9944                 filter.dst_ip = 0;
9945         }
9946
9947         if (res->src_ip_value.family == AF_INET)
9948                 /* no need to convert, already big endian. */
9949                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9950         else {
9951                 if (filter.src_ip_mask == 0) {
9952                         printf("can not support ipv6 involved compare.\n");
9953                         return;
9954                 }
9955                 filter.src_ip = 0;
9956         }
9957         /* need convert to big endian. */
9958         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9959         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9960         filter.queue = res->queue_id;
9961
9962         if (!strcmp(res->ops, "add"))
9963                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9964                                 RTE_ETH_FILTER_NTUPLE,
9965                                 RTE_ETH_FILTER_ADD,
9966                                 &filter);
9967         else
9968                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9969                                 RTE_ETH_FILTER_NTUPLE,
9970                                 RTE_ETH_FILTER_DELETE,
9971                                 &filter);
9972         if (ret < 0)
9973                 printf("5tuple filter programming error: (%s)\n",
9974                         strerror(-ret));
9975 }
9976
9977 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9978         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9979                                  filter, "5tuple_filter");
9980 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9981         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9982                                 port_id, UINT16);
9983 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9984         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9985                                  ops, "add#del");
9986 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9987         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9988                                 dst_ip, "dst_ip");
9989 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9990         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9991                                 dst_ip_value);
9992 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9993         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9994                                 src_ip, "src_ip");
9995 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9996         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9997                                 src_ip_value);
9998 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9999         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10000                                 dst_port, "dst_port");
10001 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10002         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10003                                 dst_port_value, UINT16);
10004 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10005         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10006                                 src_port, "src_port");
10007 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10008         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10009                                 src_port_value, UINT16);
10010 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10011         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10012                                 protocol, "protocol");
10013 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10014         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10015                                 protocol_value, UINT8);
10016 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10017         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10018                                 mask, "mask");
10019 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10020         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10021                                 mask_value, INT8);
10022 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10023         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10024                                 tcp_flags, "tcp_flags");
10025 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10026         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10027                                 tcp_flags_value, UINT8);
10028 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10029         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10030                                 priority, "priority");
10031 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10032         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10033                                 priority_value, UINT8);
10034 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10035         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10036                                 queue, "queue");
10037 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10038         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10039                                 queue_id, UINT16);
10040
10041 cmdline_parse_inst_t cmd_5tuple_filter = {
10042         .f = cmd_5tuple_filter_parsed,
10043         .data = NULL,
10044         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10045                 "src_ip <value> dst_port <value> src_port <value> "
10046                 "protocol <value>  mask <value> tcp_flags <value> "
10047                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10048         .tokens = {
10049                 (void *)&cmd_5tuple_filter_filter,
10050                 (void *)&cmd_5tuple_filter_port_id,
10051                 (void *)&cmd_5tuple_filter_ops,
10052                 (void *)&cmd_5tuple_filter_dst_ip,
10053                 (void *)&cmd_5tuple_filter_dst_ip_value,
10054                 (void *)&cmd_5tuple_filter_src_ip,
10055                 (void *)&cmd_5tuple_filter_src_ip_value,
10056                 (void *)&cmd_5tuple_filter_dst_port,
10057                 (void *)&cmd_5tuple_filter_dst_port_value,
10058                 (void *)&cmd_5tuple_filter_src_port,
10059                 (void *)&cmd_5tuple_filter_src_port_value,
10060                 (void *)&cmd_5tuple_filter_protocol,
10061                 (void *)&cmd_5tuple_filter_protocol_value,
10062                 (void *)&cmd_5tuple_filter_mask,
10063                 (void *)&cmd_5tuple_filter_mask_value,
10064                 (void *)&cmd_5tuple_filter_tcp_flags,
10065                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10066                 (void *)&cmd_5tuple_filter_priority,
10067                 (void *)&cmd_5tuple_filter_priority_value,
10068                 (void *)&cmd_5tuple_filter_queue,
10069                 (void *)&cmd_5tuple_filter_queue_id,
10070                 NULL,
10071         },
10072 };
10073
10074 /* *** ADD/REMOVE A flex FILTER *** */
10075 struct cmd_flex_filter_result {
10076         cmdline_fixed_string_t filter;
10077         cmdline_fixed_string_t ops;
10078         portid_t port_id;
10079         cmdline_fixed_string_t len;
10080         uint8_t len_value;
10081         cmdline_fixed_string_t bytes;
10082         cmdline_fixed_string_t bytes_value;
10083         cmdline_fixed_string_t mask;
10084         cmdline_fixed_string_t mask_value;
10085         cmdline_fixed_string_t priority;
10086         uint8_t priority_value;
10087         cmdline_fixed_string_t queue;
10088         uint16_t queue_id;
10089 };
10090
10091 static int xdigit2val(unsigned char c)
10092 {
10093         int val;
10094         if (isdigit(c))
10095                 val = c - '0';
10096         else if (isupper(c))
10097                 val = c - 'A' + 10;
10098         else
10099                 val = c - 'a' + 10;
10100         return val;
10101 }
10102
10103 static void
10104 cmd_flex_filter_parsed(void *parsed_result,
10105                           __attribute__((unused)) struct cmdline *cl,
10106                           __attribute__((unused)) void *data)
10107 {
10108         int ret = 0;
10109         struct rte_eth_flex_filter filter;
10110         struct cmd_flex_filter_result *res = parsed_result;
10111         char *bytes_ptr, *mask_ptr;
10112         uint16_t len, i, j = 0;
10113         char c;
10114         int val;
10115         uint8_t byte = 0;
10116
10117         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10118                 printf("the len exceed the max length 128\n");
10119                 return;
10120         }
10121         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10122         filter.len = res->len_value;
10123         filter.priority = res->priority_value;
10124         filter.queue = res->queue_id;
10125         bytes_ptr = res->bytes_value;
10126         mask_ptr = res->mask_value;
10127
10128          /* translate bytes string to array. */
10129         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10130                 (bytes_ptr[1] == 'X')))
10131                 bytes_ptr += 2;
10132         len = strnlen(bytes_ptr, res->len_value * 2);
10133         if (len == 0 || (len % 8 != 0)) {
10134                 printf("please check len and bytes input\n");
10135                 return;
10136         }
10137         for (i = 0; i < len; i++) {
10138                 c = bytes_ptr[i];
10139                 if (isxdigit(c) == 0) {
10140                         /* invalid characters. */
10141                         printf("invalid input\n");
10142                         return;
10143                 }
10144                 val = xdigit2val(c);
10145                 if (i % 2) {
10146                         byte |= val;
10147                         filter.bytes[j] = byte;
10148                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10149                         j++;
10150                         byte = 0;
10151                 } else
10152                         byte |= val << 4;
10153         }
10154         printf("\n");
10155          /* translate mask string to uint8_t array. */
10156         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10157                 (mask_ptr[1] == 'X')))
10158                 mask_ptr += 2;
10159         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10160         if (len == 0) {
10161                 printf("invalid input\n");
10162                 return;
10163         }
10164         j = 0;
10165         byte = 0;
10166         for (i = 0; i < len; i++) {
10167                 c = mask_ptr[i];
10168                 if (isxdigit(c) == 0) {
10169                         /* invalid characters. */
10170                         printf("invalid input\n");
10171                         return;
10172                 }
10173                 val = xdigit2val(c);
10174                 if (i % 2) {
10175                         byte |= val;
10176                         filter.mask[j] = byte;
10177                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10178                         j++;
10179                         byte = 0;
10180                 } else
10181                         byte |= val << 4;
10182         }
10183         printf("\n");
10184
10185         if (!strcmp(res->ops, "add"))
10186                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10187                                 RTE_ETH_FILTER_FLEXIBLE,
10188                                 RTE_ETH_FILTER_ADD,
10189                                 &filter);
10190         else
10191                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10192                                 RTE_ETH_FILTER_FLEXIBLE,
10193                                 RTE_ETH_FILTER_DELETE,
10194                                 &filter);
10195
10196         if (ret < 0)
10197                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10198 }
10199
10200 cmdline_parse_token_string_t cmd_flex_filter_filter =
10201         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10202                                 filter, "flex_filter");
10203 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10204         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10205                                 port_id, UINT16);
10206 cmdline_parse_token_string_t cmd_flex_filter_ops =
10207         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10208                                 ops, "add#del");
10209 cmdline_parse_token_string_t cmd_flex_filter_len =
10210         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10211                                 len, "len");
10212 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10213         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10214                                 len_value, UINT8);
10215 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10216         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10217                                 bytes, "bytes");
10218 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10219         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10220                                 bytes_value, NULL);
10221 cmdline_parse_token_string_t cmd_flex_filter_mask =
10222         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10223                                 mask, "mask");
10224 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10225         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10226                                 mask_value, NULL);
10227 cmdline_parse_token_string_t cmd_flex_filter_priority =
10228         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10229                                 priority, "priority");
10230 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10231         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10232                                 priority_value, UINT8);
10233 cmdline_parse_token_string_t cmd_flex_filter_queue =
10234         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10235                                 queue, "queue");
10236 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10237         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10238                                 queue_id, UINT16);
10239 cmdline_parse_inst_t cmd_flex_filter = {
10240         .f = cmd_flex_filter_parsed,
10241         .data = NULL,
10242         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10243                 "<value> mask <value> priority <value> queue <queue_id>: "
10244                 "Add/Del a flex filter",
10245         .tokens = {
10246                 (void *)&cmd_flex_filter_filter,
10247                 (void *)&cmd_flex_filter_port_id,
10248                 (void *)&cmd_flex_filter_ops,
10249                 (void *)&cmd_flex_filter_len,
10250                 (void *)&cmd_flex_filter_len_value,
10251                 (void *)&cmd_flex_filter_bytes,
10252                 (void *)&cmd_flex_filter_bytes_value,
10253                 (void *)&cmd_flex_filter_mask,
10254                 (void *)&cmd_flex_filter_mask_value,
10255                 (void *)&cmd_flex_filter_priority,
10256                 (void *)&cmd_flex_filter_priority_value,
10257                 (void *)&cmd_flex_filter_queue,
10258                 (void *)&cmd_flex_filter_queue_id,
10259                 NULL,
10260         },
10261 };
10262
10263 /* *** Filters Control *** */
10264
10265 /* *** deal with ethertype filter *** */
10266 struct cmd_ethertype_filter_result {
10267         cmdline_fixed_string_t filter;
10268         portid_t port_id;
10269         cmdline_fixed_string_t ops;
10270         cmdline_fixed_string_t mac;
10271         struct ether_addr mac_addr;
10272         cmdline_fixed_string_t ethertype;
10273         uint16_t ethertype_value;
10274         cmdline_fixed_string_t drop;
10275         cmdline_fixed_string_t queue;
10276         uint16_t  queue_id;
10277 };
10278
10279 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10280         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10281                                  filter, "ethertype_filter");
10282 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10283         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10284                               port_id, UINT16);
10285 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10286         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10287                                  ops, "add#del");
10288 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10289         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10290                                  mac, "mac_addr#mac_ignr");
10291 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10292         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10293                                      mac_addr);
10294 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10295         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10296                                  ethertype, "ethertype");
10297 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10298         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10299                               ethertype_value, UINT16);
10300 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10301         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10302                                  drop, "drop#fwd");
10303 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10304         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10305                                  queue, "queue");
10306 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10307         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10308                               queue_id, UINT16);
10309
10310 static void
10311 cmd_ethertype_filter_parsed(void *parsed_result,
10312                           __attribute__((unused)) struct cmdline *cl,
10313                           __attribute__((unused)) void *data)
10314 {
10315         struct cmd_ethertype_filter_result *res = parsed_result;
10316         struct rte_eth_ethertype_filter filter;
10317         int ret = 0;
10318
10319         ret = rte_eth_dev_filter_supported(res->port_id,
10320                         RTE_ETH_FILTER_ETHERTYPE);
10321         if (ret < 0) {
10322                 printf("ethertype filter is not supported on port %u.\n",
10323                         res->port_id);
10324                 return;
10325         }
10326
10327         memset(&filter, 0, sizeof(filter));
10328         if (!strcmp(res->mac, "mac_addr")) {
10329                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10330                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10331                         sizeof(struct ether_addr));
10332         }
10333         if (!strcmp(res->drop, "drop"))
10334                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10335         filter.ether_type = res->ethertype_value;
10336         filter.queue = res->queue_id;
10337
10338         if (!strcmp(res->ops, "add"))
10339                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10340                                 RTE_ETH_FILTER_ETHERTYPE,
10341                                 RTE_ETH_FILTER_ADD,
10342                                 &filter);
10343         else
10344                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10345                                 RTE_ETH_FILTER_ETHERTYPE,
10346                                 RTE_ETH_FILTER_DELETE,
10347                                 &filter);
10348         if (ret < 0)
10349                 printf("ethertype filter programming error: (%s)\n",
10350                         strerror(-ret));
10351 }
10352
10353 cmdline_parse_inst_t cmd_ethertype_filter = {
10354         .f = cmd_ethertype_filter_parsed,
10355         .data = NULL,
10356         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10357                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10358                 "Add or delete an ethertype filter entry",
10359         .tokens = {
10360                 (void *)&cmd_ethertype_filter_filter,
10361                 (void *)&cmd_ethertype_filter_port_id,
10362                 (void *)&cmd_ethertype_filter_ops,
10363                 (void *)&cmd_ethertype_filter_mac,
10364                 (void *)&cmd_ethertype_filter_mac_addr,
10365                 (void *)&cmd_ethertype_filter_ethertype,
10366                 (void *)&cmd_ethertype_filter_ethertype_value,
10367                 (void *)&cmd_ethertype_filter_drop,
10368                 (void *)&cmd_ethertype_filter_queue,
10369                 (void *)&cmd_ethertype_filter_queue_id,
10370                 NULL,
10371         },
10372 };
10373
10374 /* *** deal with flow director filter *** */
10375 struct cmd_flow_director_result {
10376         cmdline_fixed_string_t flow_director_filter;
10377         portid_t port_id;
10378         cmdline_fixed_string_t mode;
10379         cmdline_fixed_string_t mode_value;
10380         cmdline_fixed_string_t ops;
10381         cmdline_fixed_string_t flow;
10382         cmdline_fixed_string_t flow_type;
10383         cmdline_fixed_string_t ether;
10384         uint16_t ether_type;
10385         cmdline_fixed_string_t src;
10386         cmdline_ipaddr_t ip_src;
10387         uint16_t port_src;
10388         cmdline_fixed_string_t dst;
10389         cmdline_ipaddr_t ip_dst;
10390         uint16_t port_dst;
10391         cmdline_fixed_string_t verify_tag;
10392         uint32_t verify_tag_value;
10393         cmdline_fixed_string_t tos;
10394         uint8_t tos_value;
10395         cmdline_fixed_string_t proto;
10396         uint8_t proto_value;
10397         cmdline_fixed_string_t ttl;
10398         uint8_t ttl_value;
10399         cmdline_fixed_string_t vlan;
10400         uint16_t vlan_value;
10401         cmdline_fixed_string_t flexbytes;
10402         cmdline_fixed_string_t flexbytes_value;
10403         cmdline_fixed_string_t pf_vf;
10404         cmdline_fixed_string_t drop;
10405         cmdline_fixed_string_t queue;
10406         uint16_t  queue_id;
10407         cmdline_fixed_string_t fd_id;
10408         uint32_t  fd_id_value;
10409         cmdline_fixed_string_t mac;
10410         struct ether_addr mac_addr;
10411         cmdline_fixed_string_t tunnel;
10412         cmdline_fixed_string_t tunnel_type;
10413         cmdline_fixed_string_t tunnel_id;
10414         uint32_t tunnel_id_value;
10415         cmdline_fixed_string_t packet;
10416         char filepath[];
10417 };
10418
10419 static inline int
10420 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10421 {
10422         char s[256];
10423         const char *p, *p0 = q_arg;
10424         char *end;
10425         unsigned long int_fld;
10426         char *str_fld[max_num];
10427         int i;
10428         unsigned size;
10429         int ret = -1;
10430
10431         p = strchr(p0, '(');
10432         if (p == NULL)
10433                 return -1;
10434         ++p;
10435         p0 = strchr(p, ')');
10436         if (p0 == NULL)
10437                 return -1;
10438
10439         size = p0 - p;
10440         if (size >= sizeof(s))
10441                 return -1;
10442
10443         snprintf(s, sizeof(s), "%.*s", size, p);
10444         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10445         if (ret < 0 || ret > max_num)
10446                 return -1;
10447         for (i = 0; i < ret; i++) {
10448                 errno = 0;
10449                 int_fld = strtoul(str_fld[i], &end, 0);
10450                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10451                         return -1;
10452                 flexbytes[i] = (uint8_t)int_fld;
10453         }
10454         return ret;
10455 }
10456
10457 static uint16_t
10458 str2flowtype(char *string)
10459 {
10460         uint8_t i = 0;
10461         static const struct {
10462                 char str[32];
10463                 uint16_t type;
10464         } flowtype_str[] = {
10465                 {"raw", RTE_ETH_FLOW_RAW},
10466                 {"ipv4", RTE_ETH_FLOW_IPV4},
10467                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10468                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10469                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10470                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10471                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10472                 {"ipv6", RTE_ETH_FLOW_IPV6},
10473                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10474                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10475                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10476                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10477                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10478                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10479         };
10480
10481         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10482                 if (!strcmp(flowtype_str[i].str, string))
10483                         return flowtype_str[i].type;
10484         }
10485
10486         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10487                 return (uint16_t)atoi(string);
10488
10489         return RTE_ETH_FLOW_UNKNOWN;
10490 }
10491
10492 static enum rte_eth_fdir_tunnel_type
10493 str2fdir_tunneltype(char *string)
10494 {
10495         uint8_t i = 0;
10496
10497         static const struct {
10498                 char str[32];
10499                 enum rte_eth_fdir_tunnel_type type;
10500         } tunneltype_str[] = {
10501                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10502                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10503         };
10504
10505         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10506                 if (!strcmp(tunneltype_str[i].str, string))
10507                         return tunneltype_str[i].type;
10508         }
10509         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10510 }
10511
10512 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10513 do { \
10514         if ((ip_addr).family == AF_INET) \
10515                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10516         else { \
10517                 printf("invalid parameter.\n"); \
10518                 return; \
10519         } \
10520 } while (0)
10521
10522 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10523 do { \
10524         if ((ip_addr).family == AF_INET6) \
10525                 rte_memcpy(&(ip), \
10526                                  &((ip_addr).addr.ipv6), \
10527                                  sizeof(struct in6_addr)); \
10528         else { \
10529                 printf("invalid parameter.\n"); \
10530                 return; \
10531         } \
10532 } while (0)
10533
10534 static void
10535 cmd_flow_director_filter_parsed(void *parsed_result,
10536                           __attribute__((unused)) struct cmdline *cl,
10537                           __attribute__((unused)) void *data)
10538 {
10539         struct cmd_flow_director_result *res = parsed_result;
10540         struct rte_eth_fdir_filter entry;
10541         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10542         char *end;
10543         unsigned long vf_id;
10544         int ret = 0;
10545
10546         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10547         if (ret < 0) {
10548                 printf("flow director is not supported on port %u.\n",
10549                         res->port_id);
10550                 return;
10551         }
10552         memset(flexbytes, 0, sizeof(flexbytes));
10553         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10554
10555         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10556                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10557                         printf("Please set mode to MAC-VLAN.\n");
10558                         return;
10559                 }
10560         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10561                 if (strcmp(res->mode_value, "Tunnel")) {
10562                         printf("Please set mode to Tunnel.\n");
10563                         return;
10564                 }
10565         } else {
10566                 if (!strcmp(res->mode_value, "raw")) {
10567 #ifdef RTE_LIBRTE_I40E_PMD
10568                         struct rte_pmd_i40e_flow_type_mapping
10569                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10570                         struct rte_pmd_i40e_pkt_template_conf conf;
10571                         uint16_t flow_type = str2flowtype(res->flow_type);
10572                         uint16_t i, port = res->port_id;
10573                         uint8_t add;
10574
10575                         memset(&conf, 0, sizeof(conf));
10576
10577                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10578                                 printf("Invalid flow type specified.\n");
10579                                 return;
10580                         }
10581                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10582                                                                  mapping);
10583                         if (ret)
10584                                 return;
10585                         if (mapping[flow_type].pctype == 0ULL) {
10586                                 printf("Invalid flow type specified.\n");
10587                                 return;
10588                         }
10589                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10590                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10591                                         conf.input.pctype = i;
10592                                         break;
10593                                 }
10594                         }
10595
10596                         conf.input.packet = open_file(res->filepath,
10597                                                 &conf.input.length);
10598                         if (!conf.input.packet)
10599                                 return;
10600                         if (!strcmp(res->drop, "drop"))
10601                                 conf.action.behavior =
10602                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10603                         else
10604                                 conf.action.behavior =
10605                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10606                         conf.action.report_status =
10607                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10608                         conf.action.rx_queue = res->queue_id;
10609                         conf.soft_id = res->fd_id_value;
10610                         add  = strcmp(res->ops, "del") ? 1 : 0;
10611                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10612                                                                         &conf,
10613                                                                         add);
10614                         if (ret < 0)
10615                                 printf("flow director config error: (%s)\n",
10616                                        strerror(-ret));
10617                         close_file(conf.input.packet);
10618 #endif
10619                         return;
10620                 } else if (strcmp(res->mode_value, "IP")) {
10621                         printf("Please set mode to IP or raw.\n");
10622                         return;
10623                 }
10624                 entry.input.flow_type = str2flowtype(res->flow_type);
10625         }
10626
10627         ret = parse_flexbytes(res->flexbytes_value,
10628                                         flexbytes,
10629                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10630         if (ret < 0) {
10631                 printf("error: Cannot parse flexbytes input.\n");
10632                 return;
10633         }
10634
10635         switch (entry.input.flow_type) {
10636         case RTE_ETH_FLOW_FRAG_IPV4:
10637         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10638                 entry.input.flow.ip4_flow.proto = res->proto_value;
10639                 /* fall-through */
10640         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10641         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10642                 IPV4_ADDR_TO_UINT(res->ip_dst,
10643                         entry.input.flow.ip4_flow.dst_ip);
10644                 IPV4_ADDR_TO_UINT(res->ip_src,
10645                         entry.input.flow.ip4_flow.src_ip);
10646                 entry.input.flow.ip4_flow.tos = res->tos_value;
10647                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10648                 /* need convert to big endian. */
10649                 entry.input.flow.udp4_flow.dst_port =
10650                                 rte_cpu_to_be_16(res->port_dst);
10651                 entry.input.flow.udp4_flow.src_port =
10652                                 rte_cpu_to_be_16(res->port_src);
10653                 break;
10654         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10655                 IPV4_ADDR_TO_UINT(res->ip_dst,
10656                         entry.input.flow.sctp4_flow.ip.dst_ip);
10657                 IPV4_ADDR_TO_UINT(res->ip_src,
10658                         entry.input.flow.sctp4_flow.ip.src_ip);
10659                 entry.input.flow.ip4_flow.tos = res->tos_value;
10660                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10661                 /* need convert to big endian. */
10662                 entry.input.flow.sctp4_flow.dst_port =
10663                                 rte_cpu_to_be_16(res->port_dst);
10664                 entry.input.flow.sctp4_flow.src_port =
10665                                 rte_cpu_to_be_16(res->port_src);
10666                 entry.input.flow.sctp4_flow.verify_tag =
10667                                 rte_cpu_to_be_32(res->verify_tag_value);
10668                 break;
10669         case RTE_ETH_FLOW_FRAG_IPV6:
10670         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10671                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10672                 /* fall-through */
10673         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10674         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10675                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10676                         entry.input.flow.ipv6_flow.dst_ip);
10677                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10678                         entry.input.flow.ipv6_flow.src_ip);
10679                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10680                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10681                 /* need convert to big endian. */
10682                 entry.input.flow.udp6_flow.dst_port =
10683                                 rte_cpu_to_be_16(res->port_dst);
10684                 entry.input.flow.udp6_flow.src_port =
10685                                 rte_cpu_to_be_16(res->port_src);
10686                 break;
10687         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10688                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10689                         entry.input.flow.sctp6_flow.ip.dst_ip);
10690                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10691                         entry.input.flow.sctp6_flow.ip.src_ip);
10692                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10693                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10694                 /* need convert to big endian. */
10695                 entry.input.flow.sctp6_flow.dst_port =
10696                                 rte_cpu_to_be_16(res->port_dst);
10697                 entry.input.flow.sctp6_flow.src_port =
10698                                 rte_cpu_to_be_16(res->port_src);
10699                 entry.input.flow.sctp6_flow.verify_tag =
10700                                 rte_cpu_to_be_32(res->verify_tag_value);
10701                 break;
10702         case RTE_ETH_FLOW_L2_PAYLOAD:
10703                 entry.input.flow.l2_flow.ether_type =
10704                         rte_cpu_to_be_16(res->ether_type);
10705                 break;
10706         default:
10707                 break;
10708         }
10709
10710         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10711                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10712                                  &res->mac_addr,
10713                                  sizeof(struct ether_addr));
10714
10715         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10716                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10717                                  &res->mac_addr,
10718                                  sizeof(struct ether_addr));
10719                 entry.input.flow.tunnel_flow.tunnel_type =
10720                         str2fdir_tunneltype(res->tunnel_type);
10721                 entry.input.flow.tunnel_flow.tunnel_id =
10722                         rte_cpu_to_be_32(res->tunnel_id_value);
10723         }
10724
10725         rte_memcpy(entry.input.flow_ext.flexbytes,
10726                    flexbytes,
10727                    RTE_ETH_FDIR_MAX_FLEXLEN);
10728
10729         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10730
10731         entry.action.flex_off = 0;  /*use 0 by default */
10732         if (!strcmp(res->drop, "drop"))
10733                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10734         else
10735                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10736
10737         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10738             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10739                 if (!strcmp(res->pf_vf, "pf"))
10740                         entry.input.flow_ext.is_vf = 0;
10741                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10742                         struct rte_eth_dev_info dev_info;
10743
10744                         memset(&dev_info, 0, sizeof(dev_info));
10745                         rte_eth_dev_info_get(res->port_id, &dev_info);
10746                         errno = 0;
10747                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10748                         if (errno != 0 || *end != '\0' ||
10749                             vf_id >= dev_info.max_vfs) {
10750                                 printf("invalid parameter %s.\n", res->pf_vf);
10751                                 return;
10752                         }
10753                         entry.input.flow_ext.is_vf = 1;
10754                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10755                 } else {
10756                         printf("invalid parameter %s.\n", res->pf_vf);
10757                         return;
10758                 }
10759         }
10760
10761         /* set to report FD ID by default */
10762         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10763         entry.action.rx_queue = res->queue_id;
10764         entry.soft_id = res->fd_id_value;
10765         if (!strcmp(res->ops, "add"))
10766                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10767                                              RTE_ETH_FILTER_ADD, &entry);
10768         else if (!strcmp(res->ops, "del"))
10769                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10770                                              RTE_ETH_FILTER_DELETE, &entry);
10771         else
10772                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10773                                              RTE_ETH_FILTER_UPDATE, &entry);
10774         if (ret < 0)
10775                 printf("flow director programming error: (%s)\n",
10776                         strerror(-ret));
10777 }
10778
10779 cmdline_parse_token_string_t cmd_flow_director_filter =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10781                                  flow_director_filter, "flow_director_filter");
10782 cmdline_parse_token_num_t cmd_flow_director_port_id =
10783         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10784                               port_id, UINT16);
10785 cmdline_parse_token_string_t cmd_flow_director_ops =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10787                                  ops, "add#del#update");
10788 cmdline_parse_token_string_t cmd_flow_director_flow =
10789         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10790                                  flow, "flow");
10791 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10793                 flow_type, NULL);
10794 cmdline_parse_token_string_t cmd_flow_director_ether =
10795         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10796                                  ether, "ether");
10797 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10798         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10799                               ether_type, UINT16);
10800 cmdline_parse_token_string_t cmd_flow_director_src =
10801         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10802                                  src, "src");
10803 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10804         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10805                                  ip_src);
10806 cmdline_parse_token_num_t cmd_flow_director_port_src =
10807         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10808                               port_src, UINT16);
10809 cmdline_parse_token_string_t cmd_flow_director_dst =
10810         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10811                                  dst, "dst");
10812 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10813         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10814                                  ip_dst);
10815 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10816         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10817                               port_dst, UINT16);
10818 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10820                                   verify_tag, "verify_tag");
10821 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10822         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10823                               verify_tag_value, UINT32);
10824 cmdline_parse_token_string_t cmd_flow_director_tos =
10825         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10826                                  tos, "tos");
10827 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10828         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10829                               tos_value, UINT8);
10830 cmdline_parse_token_string_t cmd_flow_director_proto =
10831         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10832                                  proto, "proto");
10833 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10834         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10835                               proto_value, UINT8);
10836 cmdline_parse_token_string_t cmd_flow_director_ttl =
10837         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10838                                  ttl, "ttl");
10839 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10840         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10841                               ttl_value, UINT8);
10842 cmdline_parse_token_string_t cmd_flow_director_vlan =
10843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10844                                  vlan, "vlan");
10845 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10846         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10847                               vlan_value, UINT16);
10848 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10849         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10850                                  flexbytes, "flexbytes");
10851 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10853                               flexbytes_value, NULL);
10854 cmdline_parse_token_string_t cmd_flow_director_drop =
10855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10856                                  drop, "drop#fwd");
10857 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10858         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10859                               pf_vf, NULL);
10860 cmdline_parse_token_string_t cmd_flow_director_queue =
10861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10862                                  queue, "queue");
10863 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10864         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10865                               queue_id, UINT16);
10866 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10868                                  fd_id, "fd_id");
10869 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10870         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10871                               fd_id_value, UINT32);
10872
10873 cmdline_parse_token_string_t cmd_flow_director_mode =
10874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10875                                  mode, "mode");
10876 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10877         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10878                                  mode_value, "IP");
10879 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10880         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10881                                  mode_value, "MAC-VLAN");
10882 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10883         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10884                                  mode_value, "Tunnel");
10885 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10887                                  mode_value, "raw");
10888 cmdline_parse_token_string_t cmd_flow_director_mac =
10889         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10890                                  mac, "mac");
10891 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10892         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10893                                     mac_addr);
10894 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10896                                  tunnel, "tunnel");
10897 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10898         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10899                                  tunnel_type, "NVGRE#VxLAN");
10900 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10902                                  tunnel_id, "tunnel-id");
10903 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10904         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10905                               tunnel_id_value, UINT32);
10906 cmdline_parse_token_string_t cmd_flow_director_packet =
10907         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10908                                  packet, "packet");
10909 cmdline_parse_token_string_t cmd_flow_director_filepath =
10910         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10911                                  filepath, NULL);
10912
10913 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10914         .f = cmd_flow_director_filter_parsed,
10915         .data = NULL,
10916         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10917                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10918                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10919                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10920                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10921                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10922                 "fd_id <fd_id_value>: "
10923                 "Add or delete an ip flow director entry on NIC",
10924         .tokens = {
10925                 (void *)&cmd_flow_director_filter,
10926                 (void *)&cmd_flow_director_port_id,
10927                 (void *)&cmd_flow_director_mode,
10928                 (void *)&cmd_flow_director_mode_ip,
10929                 (void *)&cmd_flow_director_ops,
10930                 (void *)&cmd_flow_director_flow,
10931                 (void *)&cmd_flow_director_flow_type,
10932                 (void *)&cmd_flow_director_src,
10933                 (void *)&cmd_flow_director_ip_src,
10934                 (void *)&cmd_flow_director_dst,
10935                 (void *)&cmd_flow_director_ip_dst,
10936                 (void *)&cmd_flow_director_tos,
10937                 (void *)&cmd_flow_director_tos_value,
10938                 (void *)&cmd_flow_director_proto,
10939                 (void *)&cmd_flow_director_proto_value,
10940                 (void *)&cmd_flow_director_ttl,
10941                 (void *)&cmd_flow_director_ttl_value,
10942                 (void *)&cmd_flow_director_vlan,
10943                 (void *)&cmd_flow_director_vlan_value,
10944                 (void *)&cmd_flow_director_flexbytes,
10945                 (void *)&cmd_flow_director_flexbytes_value,
10946                 (void *)&cmd_flow_director_drop,
10947                 (void *)&cmd_flow_director_pf_vf,
10948                 (void *)&cmd_flow_director_queue,
10949                 (void *)&cmd_flow_director_queue_id,
10950                 (void *)&cmd_flow_director_fd_id,
10951                 (void *)&cmd_flow_director_fd_id_value,
10952                 NULL,
10953         },
10954 };
10955
10956 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10957         .f = cmd_flow_director_filter_parsed,
10958         .data = NULL,
10959         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10960                 "director entry on NIC",
10961         .tokens = {
10962                 (void *)&cmd_flow_director_filter,
10963                 (void *)&cmd_flow_director_port_id,
10964                 (void *)&cmd_flow_director_mode,
10965                 (void *)&cmd_flow_director_mode_ip,
10966                 (void *)&cmd_flow_director_ops,
10967                 (void *)&cmd_flow_director_flow,
10968                 (void *)&cmd_flow_director_flow_type,
10969                 (void *)&cmd_flow_director_src,
10970                 (void *)&cmd_flow_director_ip_src,
10971                 (void *)&cmd_flow_director_port_src,
10972                 (void *)&cmd_flow_director_dst,
10973                 (void *)&cmd_flow_director_ip_dst,
10974                 (void *)&cmd_flow_director_port_dst,
10975                 (void *)&cmd_flow_director_tos,
10976                 (void *)&cmd_flow_director_tos_value,
10977                 (void *)&cmd_flow_director_ttl,
10978                 (void *)&cmd_flow_director_ttl_value,
10979                 (void *)&cmd_flow_director_vlan,
10980                 (void *)&cmd_flow_director_vlan_value,
10981                 (void *)&cmd_flow_director_flexbytes,
10982                 (void *)&cmd_flow_director_flexbytes_value,
10983                 (void *)&cmd_flow_director_drop,
10984                 (void *)&cmd_flow_director_pf_vf,
10985                 (void *)&cmd_flow_director_queue,
10986                 (void *)&cmd_flow_director_queue_id,
10987                 (void *)&cmd_flow_director_fd_id,
10988                 (void *)&cmd_flow_director_fd_id_value,
10989                 NULL,
10990         },
10991 };
10992
10993 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10994         .f = cmd_flow_director_filter_parsed,
10995         .data = NULL,
10996         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10997                 "director entry on NIC",
10998         .tokens = {
10999                 (void *)&cmd_flow_director_filter,
11000                 (void *)&cmd_flow_director_port_id,
11001                 (void *)&cmd_flow_director_mode,
11002                 (void *)&cmd_flow_director_mode_ip,
11003                 (void *)&cmd_flow_director_ops,
11004                 (void *)&cmd_flow_director_flow,
11005                 (void *)&cmd_flow_director_flow_type,
11006                 (void *)&cmd_flow_director_src,
11007                 (void *)&cmd_flow_director_ip_src,
11008                 (void *)&cmd_flow_director_port_src,
11009                 (void *)&cmd_flow_director_dst,
11010                 (void *)&cmd_flow_director_ip_dst,
11011                 (void *)&cmd_flow_director_port_dst,
11012                 (void *)&cmd_flow_director_verify_tag,
11013                 (void *)&cmd_flow_director_verify_tag_value,
11014                 (void *)&cmd_flow_director_tos,
11015                 (void *)&cmd_flow_director_tos_value,
11016                 (void *)&cmd_flow_director_ttl,
11017                 (void *)&cmd_flow_director_ttl_value,
11018                 (void *)&cmd_flow_director_vlan,
11019                 (void *)&cmd_flow_director_vlan_value,
11020                 (void *)&cmd_flow_director_flexbytes,
11021                 (void *)&cmd_flow_director_flexbytes_value,
11022                 (void *)&cmd_flow_director_drop,
11023                 (void *)&cmd_flow_director_pf_vf,
11024                 (void *)&cmd_flow_director_queue,
11025                 (void *)&cmd_flow_director_queue_id,
11026                 (void *)&cmd_flow_director_fd_id,
11027                 (void *)&cmd_flow_director_fd_id_value,
11028                 NULL,
11029         },
11030 };
11031
11032 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11033         .f = cmd_flow_director_filter_parsed,
11034         .data = NULL,
11035         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11036                 "director entry on NIC",
11037         .tokens = {
11038                 (void *)&cmd_flow_director_filter,
11039                 (void *)&cmd_flow_director_port_id,
11040                 (void *)&cmd_flow_director_mode,
11041                 (void *)&cmd_flow_director_mode_ip,
11042                 (void *)&cmd_flow_director_ops,
11043                 (void *)&cmd_flow_director_flow,
11044                 (void *)&cmd_flow_director_flow_type,
11045                 (void *)&cmd_flow_director_ether,
11046                 (void *)&cmd_flow_director_ether_type,
11047                 (void *)&cmd_flow_director_flexbytes,
11048                 (void *)&cmd_flow_director_flexbytes_value,
11049                 (void *)&cmd_flow_director_drop,
11050                 (void *)&cmd_flow_director_pf_vf,
11051                 (void *)&cmd_flow_director_queue,
11052                 (void *)&cmd_flow_director_queue_id,
11053                 (void *)&cmd_flow_director_fd_id,
11054                 (void *)&cmd_flow_director_fd_id_value,
11055                 NULL,
11056         },
11057 };
11058
11059 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11060         .f = cmd_flow_director_filter_parsed,
11061         .data = NULL,
11062         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11063                 "director entry on NIC",
11064         .tokens = {
11065                 (void *)&cmd_flow_director_filter,
11066                 (void *)&cmd_flow_director_port_id,
11067                 (void *)&cmd_flow_director_mode,
11068                 (void *)&cmd_flow_director_mode_mac_vlan,
11069                 (void *)&cmd_flow_director_ops,
11070                 (void *)&cmd_flow_director_mac,
11071                 (void *)&cmd_flow_director_mac_addr,
11072                 (void *)&cmd_flow_director_vlan,
11073                 (void *)&cmd_flow_director_vlan_value,
11074                 (void *)&cmd_flow_director_flexbytes,
11075                 (void *)&cmd_flow_director_flexbytes_value,
11076                 (void *)&cmd_flow_director_drop,
11077                 (void *)&cmd_flow_director_queue,
11078                 (void *)&cmd_flow_director_queue_id,
11079                 (void *)&cmd_flow_director_fd_id,
11080                 (void *)&cmd_flow_director_fd_id_value,
11081                 NULL,
11082         },
11083 };
11084
11085 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11086         .f = cmd_flow_director_filter_parsed,
11087         .data = NULL,
11088         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11089                 "director entry on NIC",
11090         .tokens = {
11091                 (void *)&cmd_flow_director_filter,
11092                 (void *)&cmd_flow_director_port_id,
11093                 (void *)&cmd_flow_director_mode,
11094                 (void *)&cmd_flow_director_mode_tunnel,
11095                 (void *)&cmd_flow_director_ops,
11096                 (void *)&cmd_flow_director_mac,
11097                 (void *)&cmd_flow_director_mac_addr,
11098                 (void *)&cmd_flow_director_vlan,
11099                 (void *)&cmd_flow_director_vlan_value,
11100                 (void *)&cmd_flow_director_tunnel,
11101                 (void *)&cmd_flow_director_tunnel_type,
11102                 (void *)&cmd_flow_director_tunnel_id,
11103                 (void *)&cmd_flow_director_tunnel_id_value,
11104                 (void *)&cmd_flow_director_flexbytes,
11105                 (void *)&cmd_flow_director_flexbytes_value,
11106                 (void *)&cmd_flow_director_drop,
11107                 (void *)&cmd_flow_director_queue,
11108                 (void *)&cmd_flow_director_queue_id,
11109                 (void *)&cmd_flow_director_fd_id,
11110                 (void *)&cmd_flow_director_fd_id_value,
11111                 NULL,
11112         },
11113 };
11114
11115 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11116         .f = cmd_flow_director_filter_parsed,
11117         .data = NULL,
11118         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11119                 "director entry on NIC",
11120         .tokens = {
11121                 (void *)&cmd_flow_director_filter,
11122                 (void *)&cmd_flow_director_port_id,
11123                 (void *)&cmd_flow_director_mode,
11124                 (void *)&cmd_flow_director_mode_raw,
11125                 (void *)&cmd_flow_director_ops,
11126                 (void *)&cmd_flow_director_flow,
11127                 (void *)&cmd_flow_director_flow_type,
11128                 (void *)&cmd_flow_director_drop,
11129                 (void *)&cmd_flow_director_queue,
11130                 (void *)&cmd_flow_director_queue_id,
11131                 (void *)&cmd_flow_director_fd_id,
11132                 (void *)&cmd_flow_director_fd_id_value,
11133                 (void *)&cmd_flow_director_packet,
11134                 (void *)&cmd_flow_director_filepath,
11135                 NULL,
11136         },
11137 };
11138
11139 struct cmd_flush_flow_director_result {
11140         cmdline_fixed_string_t flush_flow_director;
11141         portid_t port_id;
11142 };
11143
11144 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11145         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11146                                  flush_flow_director, "flush_flow_director");
11147 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11148         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11149                               port_id, UINT16);
11150
11151 static void
11152 cmd_flush_flow_director_parsed(void *parsed_result,
11153                           __attribute__((unused)) struct cmdline *cl,
11154                           __attribute__((unused)) void *data)
11155 {
11156         struct cmd_flow_director_result *res = parsed_result;
11157         int ret = 0;
11158
11159         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11160         if (ret < 0) {
11161                 printf("flow director is not supported on port %u.\n",
11162                         res->port_id);
11163                 return;
11164         }
11165
11166         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11167                         RTE_ETH_FILTER_FLUSH, NULL);
11168         if (ret < 0)
11169                 printf("flow director table flushing error: (%s)\n",
11170                         strerror(-ret));
11171 }
11172
11173 cmdline_parse_inst_t cmd_flush_flow_director = {
11174         .f = cmd_flush_flow_director_parsed,
11175         .data = NULL,
11176         .help_str = "flush_flow_director <port_id>: "
11177                 "Flush all flow director entries of a device on NIC",
11178         .tokens = {
11179                 (void *)&cmd_flush_flow_director_flush,
11180                 (void *)&cmd_flush_flow_director_port_id,
11181                 NULL,
11182         },
11183 };
11184
11185 /* *** deal with flow director mask *** */
11186 struct cmd_flow_director_mask_result {
11187         cmdline_fixed_string_t flow_director_mask;
11188         portid_t port_id;
11189         cmdline_fixed_string_t mode;
11190         cmdline_fixed_string_t mode_value;
11191         cmdline_fixed_string_t vlan;
11192         uint16_t vlan_mask;
11193         cmdline_fixed_string_t src_mask;
11194         cmdline_ipaddr_t ipv4_src;
11195         cmdline_ipaddr_t ipv6_src;
11196         uint16_t port_src;
11197         cmdline_fixed_string_t dst_mask;
11198         cmdline_ipaddr_t ipv4_dst;
11199         cmdline_ipaddr_t ipv6_dst;
11200         uint16_t port_dst;
11201         cmdline_fixed_string_t mac;
11202         uint8_t mac_addr_byte_mask;
11203         cmdline_fixed_string_t tunnel_id;
11204         uint32_t tunnel_id_mask;
11205         cmdline_fixed_string_t tunnel_type;
11206         uint8_t tunnel_type_mask;
11207 };
11208
11209 static void
11210 cmd_flow_director_mask_parsed(void *parsed_result,
11211                           __attribute__((unused)) struct cmdline *cl,
11212                           __attribute__((unused)) void *data)
11213 {
11214         struct cmd_flow_director_mask_result *res = parsed_result;
11215         struct rte_eth_fdir_masks *mask;
11216         struct rte_port *port;
11217
11218         port = &ports[res->port_id];
11219         /** Check if the port is not started **/
11220         if (port->port_status != RTE_PORT_STOPPED) {
11221                 printf("Please stop port %d first\n", res->port_id);
11222                 return;
11223         }
11224
11225         mask = &port->dev_conf.fdir_conf.mask;
11226
11227         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11228                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11229                         printf("Please set mode to MAC-VLAN.\n");
11230                         return;
11231                 }
11232
11233                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11234         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11235                 if (strcmp(res->mode_value, "Tunnel")) {
11236                         printf("Please set mode to Tunnel.\n");
11237                         return;
11238                 }
11239
11240                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11241                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11242                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11243                 mask->tunnel_type_mask = res->tunnel_type_mask;
11244         } else {
11245                 if (strcmp(res->mode_value, "IP")) {
11246                         printf("Please set mode to IP.\n");
11247                         return;
11248                 }
11249
11250                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11251                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11252                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11253                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11254                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11255                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11256                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11257         }
11258
11259         cmd_reconfig_device_queue(res->port_id, 1, 1);
11260 }
11261
11262 cmdline_parse_token_string_t cmd_flow_director_mask =
11263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11264                                  flow_director_mask, "flow_director_mask");
11265 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11266         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11267                               port_id, UINT16);
11268 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11270                                  vlan, "vlan");
11271 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11272         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11273                               vlan_mask, UINT16);
11274 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11276                                  src_mask, "src_mask");
11277 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11278         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11279                                  ipv4_src);
11280 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11281         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11282                                  ipv6_src);
11283 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11284         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11285                               port_src, UINT16);
11286 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11288                                  dst_mask, "dst_mask");
11289 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11290         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11291                                  ipv4_dst);
11292 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11293         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11294                                  ipv6_dst);
11295 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11296         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11297                               port_dst, UINT16);
11298
11299 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11300         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11301                                  mode, "mode");
11302 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11304                                  mode_value, "IP");
11305 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11307                                  mode_value, "MAC-VLAN");
11308 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11310                                  mode_value, "Tunnel");
11311 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11313                                  mac, "mac");
11314 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11315         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11316                               mac_addr_byte_mask, UINT8);
11317 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11319                                  tunnel_type, "tunnel-type");
11320 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11321         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11322                               tunnel_type_mask, UINT8);
11323 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11324         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11325                                  tunnel_id, "tunnel-id");
11326 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11327         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11328                               tunnel_id_mask, UINT32);
11329
11330 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11331         .f = cmd_flow_director_mask_parsed,
11332         .data = NULL,
11333         .help_str = "flow_director_mask ... : "
11334                 "Set IP mode flow director's mask on NIC",
11335         .tokens = {
11336                 (void *)&cmd_flow_director_mask,
11337                 (void *)&cmd_flow_director_mask_port_id,
11338                 (void *)&cmd_flow_director_mask_mode,
11339                 (void *)&cmd_flow_director_mask_mode_ip,
11340                 (void *)&cmd_flow_director_mask_vlan,
11341                 (void *)&cmd_flow_director_mask_vlan_value,
11342                 (void *)&cmd_flow_director_mask_src,
11343                 (void *)&cmd_flow_director_mask_ipv4_src,
11344                 (void *)&cmd_flow_director_mask_ipv6_src,
11345                 (void *)&cmd_flow_director_mask_port_src,
11346                 (void *)&cmd_flow_director_mask_dst,
11347                 (void *)&cmd_flow_director_mask_ipv4_dst,
11348                 (void *)&cmd_flow_director_mask_ipv6_dst,
11349                 (void *)&cmd_flow_director_mask_port_dst,
11350                 NULL,
11351         },
11352 };
11353
11354 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11355         .f = cmd_flow_director_mask_parsed,
11356         .data = NULL,
11357         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11358                 "flow director's mask on NIC",
11359         .tokens = {
11360                 (void *)&cmd_flow_director_mask,
11361                 (void *)&cmd_flow_director_mask_port_id,
11362                 (void *)&cmd_flow_director_mask_mode,
11363                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11364                 (void *)&cmd_flow_director_mask_vlan,
11365                 (void *)&cmd_flow_director_mask_vlan_value,
11366                 NULL,
11367         },
11368 };
11369
11370 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11371         .f = cmd_flow_director_mask_parsed,
11372         .data = NULL,
11373         .help_str = "flow_director_mask ... : Set tunnel mode "
11374                 "flow director's mask on NIC",
11375         .tokens = {
11376                 (void *)&cmd_flow_director_mask,
11377                 (void *)&cmd_flow_director_mask_port_id,
11378                 (void *)&cmd_flow_director_mask_mode,
11379                 (void *)&cmd_flow_director_mask_mode_tunnel,
11380                 (void *)&cmd_flow_director_mask_vlan,
11381                 (void *)&cmd_flow_director_mask_vlan_value,
11382                 (void *)&cmd_flow_director_mask_mac,
11383                 (void *)&cmd_flow_director_mask_mac_value,
11384                 (void *)&cmd_flow_director_mask_tunnel_type,
11385                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11386                 (void *)&cmd_flow_director_mask_tunnel_id,
11387                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11388                 NULL,
11389         },
11390 };
11391
11392 /* *** deal with flow director mask on flexible payload *** */
11393 struct cmd_flow_director_flex_mask_result {
11394         cmdline_fixed_string_t flow_director_flexmask;
11395         portid_t port_id;
11396         cmdline_fixed_string_t flow;
11397         cmdline_fixed_string_t flow_type;
11398         cmdline_fixed_string_t mask;
11399 };
11400
11401 static void
11402 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11403                           __attribute__((unused)) struct cmdline *cl,
11404                           __attribute__((unused)) void *data)
11405 {
11406         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11407         struct rte_eth_fdir_info fdir_info;
11408         struct rte_eth_fdir_flex_mask flex_mask;
11409         struct rte_port *port;
11410         uint64_t flow_type_mask;
11411         uint16_t i;
11412         int ret;
11413
11414         port = &ports[res->port_id];
11415         /** Check if the port is not started **/
11416         if (port->port_status != RTE_PORT_STOPPED) {
11417                 printf("Please stop port %d first\n", res->port_id);
11418                 return;
11419         }
11420
11421         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11422         ret = parse_flexbytes(res->mask,
11423                         flex_mask.mask,
11424                         RTE_ETH_FDIR_MAX_FLEXLEN);
11425         if (ret < 0) {
11426                 printf("error: Cannot parse mask input.\n");
11427                 return;
11428         }
11429
11430         memset(&fdir_info, 0, sizeof(fdir_info));
11431         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11432                                 RTE_ETH_FILTER_INFO, &fdir_info);
11433         if (ret < 0) {
11434                 printf("Cannot get FDir filter info\n");
11435                 return;
11436         }
11437
11438         if (!strcmp(res->flow_type, "none")) {
11439                 /* means don't specify the flow type */
11440                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11441                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11442                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11443                                0, sizeof(struct rte_eth_fdir_flex_mask));
11444                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11445                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11446                                  &flex_mask,
11447                                  sizeof(struct rte_eth_fdir_flex_mask));
11448                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11449                 return;
11450         }
11451         flow_type_mask = fdir_info.flow_types_mask[0];
11452         if (!strcmp(res->flow_type, "all")) {
11453                 if (!flow_type_mask) {
11454                         printf("No flow type supported\n");
11455                         return;
11456                 }
11457                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11458                         if (flow_type_mask & (1ULL << i)) {
11459                                 flex_mask.flow_type = i;
11460                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11461                         }
11462                 }
11463                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11464                 return;
11465         }
11466         flex_mask.flow_type = str2flowtype(res->flow_type);
11467         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11468                 printf("Flow type %s not supported on port %d\n",
11469                                 res->flow_type, res->port_id);
11470                 return;
11471         }
11472         fdir_set_flex_mask(res->port_id, &flex_mask);
11473         cmd_reconfig_device_queue(res->port_id, 1, 1);
11474 }
11475
11476 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11477         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11478                                  flow_director_flexmask,
11479                                  "flow_director_flex_mask");
11480 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11481         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11482                               port_id, UINT16);
11483 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11484         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11485                                  flow, "flow");
11486 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11487         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11488                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11489                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11490 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11492                                  mask, NULL);
11493
11494 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11495         .f = cmd_flow_director_flex_mask_parsed,
11496         .data = NULL,
11497         .help_str = "flow_director_flex_mask ... : "
11498                 "Set flow director's flex mask on NIC",
11499         .tokens = {
11500                 (void *)&cmd_flow_director_flexmask,
11501                 (void *)&cmd_flow_director_flexmask_port_id,
11502                 (void *)&cmd_flow_director_flexmask_flow,
11503                 (void *)&cmd_flow_director_flexmask_flow_type,
11504                 (void *)&cmd_flow_director_flexmask_mask,
11505                 NULL,
11506         },
11507 };
11508
11509 /* *** deal with flow director flexible payload configuration *** */
11510 struct cmd_flow_director_flexpayload_result {
11511         cmdline_fixed_string_t flow_director_flexpayload;
11512         portid_t port_id;
11513         cmdline_fixed_string_t payload_layer;
11514         cmdline_fixed_string_t payload_cfg;
11515 };
11516
11517 static inline int
11518 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11519 {
11520         char s[256];
11521         const char *p, *p0 = q_arg;
11522         char *end;
11523         unsigned long int_fld;
11524         char *str_fld[max_num];
11525         int i;
11526         unsigned size;
11527         int ret = -1;
11528
11529         p = strchr(p0, '(');
11530         if (p == NULL)
11531                 return -1;
11532         ++p;
11533         p0 = strchr(p, ')');
11534         if (p0 == NULL)
11535                 return -1;
11536
11537         size = p0 - p;
11538         if (size >= sizeof(s))
11539                 return -1;
11540
11541         snprintf(s, sizeof(s), "%.*s", size, p);
11542         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11543         if (ret < 0 || ret > max_num)
11544                 return -1;
11545         for (i = 0; i < ret; i++) {
11546                 errno = 0;
11547                 int_fld = strtoul(str_fld[i], &end, 0);
11548                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11549                         return -1;
11550                 offsets[i] = (uint16_t)int_fld;
11551         }
11552         return ret;
11553 }
11554
11555 static void
11556 cmd_flow_director_flxpld_parsed(void *parsed_result,
11557                           __attribute__((unused)) struct cmdline *cl,
11558                           __attribute__((unused)) void *data)
11559 {
11560         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11561         struct rte_eth_flex_payload_cfg flex_cfg;
11562         struct rte_port *port;
11563         int ret = 0;
11564
11565         port = &ports[res->port_id];
11566         /** Check if the port is not started **/
11567         if (port->port_status != RTE_PORT_STOPPED) {
11568                 printf("Please stop port %d first\n", res->port_id);
11569                 return;
11570         }
11571
11572         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11573
11574         if (!strcmp(res->payload_layer, "raw"))
11575                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11576         else if (!strcmp(res->payload_layer, "l2"))
11577                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11578         else if (!strcmp(res->payload_layer, "l3"))
11579                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11580         else if (!strcmp(res->payload_layer, "l4"))
11581                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11582
11583         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11584                             RTE_ETH_FDIR_MAX_FLEXLEN);
11585         if (ret < 0) {
11586                 printf("error: Cannot parse flex payload input.\n");
11587                 return;
11588         }
11589
11590         fdir_set_flex_payload(res->port_id, &flex_cfg);
11591         cmd_reconfig_device_queue(res->port_id, 1, 1);
11592 }
11593
11594 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11595         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11596                                  flow_director_flexpayload,
11597                                  "flow_director_flex_payload");
11598 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11599         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11600                               port_id, UINT16);
11601 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11603                                  payload_layer, "raw#l2#l3#l4");
11604 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11606                                  payload_cfg, NULL);
11607
11608 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11609         .f = cmd_flow_director_flxpld_parsed,
11610         .data = NULL,
11611         .help_str = "flow_director_flexpayload ... : "
11612                 "Set flow director's flex payload on NIC",
11613         .tokens = {
11614                 (void *)&cmd_flow_director_flexpayload,
11615                 (void *)&cmd_flow_director_flexpayload_port_id,
11616                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11617                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11618                 NULL,
11619         },
11620 };
11621
11622 /* Generic flow interface command. */
11623 extern cmdline_parse_inst_t cmd_flow;
11624
11625 /* *** Classification Filters Control *** */
11626 /* *** Get symmetric hash enable per port *** */
11627 struct cmd_get_sym_hash_ena_per_port_result {
11628         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11629         portid_t port_id;
11630 };
11631
11632 static void
11633 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11634                                  __rte_unused struct cmdline *cl,
11635                                  __rte_unused void *data)
11636 {
11637         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11638         struct rte_eth_hash_filter_info info;
11639         int ret;
11640
11641         if (rte_eth_dev_filter_supported(res->port_id,
11642                                 RTE_ETH_FILTER_HASH) < 0) {
11643                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11644                                                         res->port_id);
11645                 return;
11646         }
11647
11648         memset(&info, 0, sizeof(info));
11649         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11650         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11651                                                 RTE_ETH_FILTER_GET, &info);
11652
11653         if (ret < 0) {
11654                 printf("Cannot get symmetric hash enable per port "
11655                                         "on port %u\n", res->port_id);
11656                 return;
11657         }
11658
11659         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11660                                 "enabled" : "disabled", res->port_id);
11661 }
11662
11663 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11664         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11665                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
11666 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
11667         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11668                 port_id, UINT16);
11669
11670 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
11671         .f = cmd_get_sym_hash_per_port_parsed,
11672         .data = NULL,
11673         .help_str = "get_sym_hash_ena_per_port <port_id>",
11674         .tokens = {
11675                 (void *)&cmd_get_sym_hash_ena_per_port_all,
11676                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
11677                 NULL,
11678         },
11679 };
11680
11681 /* *** Set symmetric hash enable per port *** */
11682 struct cmd_set_sym_hash_ena_per_port_result {
11683         cmdline_fixed_string_t set_sym_hash_ena_per_port;
11684         cmdline_fixed_string_t enable;
11685         portid_t port_id;
11686 };
11687
11688 static void
11689 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
11690                                  __rte_unused struct cmdline *cl,
11691                                  __rte_unused void *data)
11692 {
11693         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
11694         struct rte_eth_hash_filter_info info;
11695         int ret;
11696
11697         if (rte_eth_dev_filter_supported(res->port_id,
11698                                 RTE_ETH_FILTER_HASH) < 0) {
11699                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11700                                                         res->port_id);
11701                 return;
11702         }
11703
11704         memset(&info, 0, sizeof(info));
11705         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11706         if (!strcmp(res->enable, "enable"))
11707                 info.info.enable = 1;
11708         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11709                                         RTE_ETH_FILTER_SET, &info);
11710         if (ret < 0) {
11711                 printf("Cannot set symmetric hash enable per port on "
11712                                         "port %u\n", res->port_id);
11713                 return;
11714         }
11715         printf("Symmetric hash has been set to %s on port %u\n",
11716                                         res->enable, res->port_id);
11717 }
11718
11719 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11720         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11721                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11722 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11723         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11724                 port_id, UINT16);
11725 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11726         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11727                 enable, "enable#disable");
11728
11729 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11730         .f = cmd_set_sym_hash_per_port_parsed,
11731         .data = NULL,
11732         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11733         .tokens = {
11734                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11735                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11736                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11737                 NULL,
11738         },
11739 };
11740
11741 /* Get global config of hash function */
11742 struct cmd_get_hash_global_config_result {
11743         cmdline_fixed_string_t get_hash_global_config;
11744         portid_t port_id;
11745 };
11746
11747 static char *
11748 flowtype_to_str(uint16_t ftype)
11749 {
11750         uint16_t i;
11751         static struct {
11752                 char str[16];
11753                 uint16_t ftype;
11754         } ftype_table[] = {
11755                 {"ipv4", RTE_ETH_FLOW_IPV4},
11756                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11757                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11758                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11759                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11760                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11761                 {"ipv6", RTE_ETH_FLOW_IPV6},
11762                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11763                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11764                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11765                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11766                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11767                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11768                 {"port", RTE_ETH_FLOW_PORT},
11769                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11770                 {"geneve", RTE_ETH_FLOW_GENEVE},
11771                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11772         };
11773
11774         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11775                 if (ftype_table[i].ftype == ftype)
11776                         return ftype_table[i].str;
11777         }
11778
11779         return NULL;
11780 }
11781
11782 static void
11783 cmd_get_hash_global_config_parsed(void *parsed_result,
11784                                   __rte_unused struct cmdline *cl,
11785                                   __rte_unused void *data)
11786 {
11787         struct cmd_get_hash_global_config_result *res = parsed_result;
11788         struct rte_eth_hash_filter_info info;
11789         uint32_t idx, offset;
11790         uint16_t i;
11791         char *str;
11792         int ret;
11793
11794         if (rte_eth_dev_filter_supported(res->port_id,
11795                         RTE_ETH_FILTER_HASH) < 0) {
11796                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11797                                                         res->port_id);
11798                 return;
11799         }
11800
11801         memset(&info, 0, sizeof(info));
11802         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11803         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11804                                         RTE_ETH_FILTER_GET, &info);
11805         if (ret < 0) {
11806                 printf("Cannot get hash global configurations by port %d\n",
11807                                                         res->port_id);
11808                 return;
11809         }
11810
11811         switch (info.info.global_conf.hash_func) {
11812         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11813                 printf("Hash function is Toeplitz\n");
11814                 break;
11815         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11816                 printf("Hash function is Simple XOR\n");
11817                 break;
11818         default:
11819                 printf("Unknown hash function\n");
11820                 break;
11821         }
11822
11823         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11824                 idx = i / UINT64_BIT;
11825                 offset = i % UINT64_BIT;
11826                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11827                                                 (1ULL << offset)))
11828                         continue;
11829                 str = flowtype_to_str(i);
11830                 if (!str)
11831                         continue;
11832                 printf("Symmetric hash is %s globally for flow type %s "
11833                                                         "by port %d\n",
11834                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11835                         (1ULL << offset)) ? "enabled" : "disabled"), str,
11836                                                         res->port_id);
11837         }
11838 }
11839
11840 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11841         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11842                 get_hash_global_config, "get_hash_global_config");
11843 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11844         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11845                 port_id, UINT16);
11846
11847 cmdline_parse_inst_t cmd_get_hash_global_config = {
11848         .f = cmd_get_hash_global_config_parsed,
11849         .data = NULL,
11850         .help_str = "get_hash_global_config <port_id>",
11851         .tokens = {
11852                 (void *)&cmd_get_hash_global_config_all,
11853                 (void *)&cmd_get_hash_global_config_port_id,
11854                 NULL,
11855         },
11856 };
11857
11858 /* Set global config of hash function */
11859 struct cmd_set_hash_global_config_result {
11860         cmdline_fixed_string_t set_hash_global_config;
11861         portid_t port_id;
11862         cmdline_fixed_string_t hash_func;
11863         cmdline_fixed_string_t flow_type;
11864         cmdline_fixed_string_t enable;
11865 };
11866
11867 static void
11868 cmd_set_hash_global_config_parsed(void *parsed_result,
11869                                   __rte_unused struct cmdline *cl,
11870                                   __rte_unused void *data)
11871 {
11872         struct cmd_set_hash_global_config_result *res = parsed_result;
11873         struct rte_eth_hash_filter_info info;
11874         uint32_t ftype, idx, offset;
11875         int ret;
11876
11877         if (rte_eth_dev_filter_supported(res->port_id,
11878                                 RTE_ETH_FILTER_HASH) < 0) {
11879                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11880                                                         res->port_id);
11881                 return;
11882         }
11883         memset(&info, 0, sizeof(info));
11884         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11885         if (!strcmp(res->hash_func, "toeplitz"))
11886                 info.info.global_conf.hash_func =
11887                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11888         else if (!strcmp(res->hash_func, "simple_xor"))
11889                 info.info.global_conf.hash_func =
11890                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11891         else if (!strcmp(res->hash_func, "default"))
11892                 info.info.global_conf.hash_func =
11893                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11894
11895         ftype = str2flowtype(res->flow_type);
11896         idx = ftype / UINT64_BIT;
11897         offset = ftype % UINT64_BIT;
11898         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
11899         if (!strcmp(res->enable, "enable"))
11900                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11901                                                 (1ULL << offset);
11902         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11903                                         RTE_ETH_FILTER_SET, &info);
11904         if (ret < 0)
11905                 printf("Cannot set global hash configurations by port %d\n",
11906                                                         res->port_id);
11907         else
11908                 printf("Global hash configurations have been set "
11909                         "succcessfully by port %d\n", res->port_id);
11910 }
11911
11912 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11913         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11914                 set_hash_global_config, "set_hash_global_config");
11915 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11916         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11917                 port_id, UINT16);
11918 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11919         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11920                 hash_func, "toeplitz#simple_xor#default");
11921 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11922         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11923                 flow_type,
11924                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11925                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11926 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11927         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11928                 enable, "enable#disable");
11929
11930 cmdline_parse_inst_t cmd_set_hash_global_config = {
11931         .f = cmd_set_hash_global_config_parsed,
11932         .data = NULL,
11933         .help_str = "set_hash_global_config <port_id> "
11934                 "toeplitz|simple_xor|default "
11935                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11936                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11937                 "l2_payload enable|disable",
11938         .tokens = {
11939                 (void *)&cmd_set_hash_global_config_all,
11940                 (void *)&cmd_set_hash_global_config_port_id,
11941                 (void *)&cmd_set_hash_global_config_hash_func,
11942                 (void *)&cmd_set_hash_global_config_flow_type,
11943                 (void *)&cmd_set_hash_global_config_enable,
11944                 NULL,
11945         },
11946 };
11947
11948 /* Set hash input set */
11949 struct cmd_set_hash_input_set_result {
11950         cmdline_fixed_string_t set_hash_input_set;
11951         portid_t port_id;
11952         cmdline_fixed_string_t flow_type;
11953         cmdline_fixed_string_t inset_field;
11954         cmdline_fixed_string_t select;
11955 };
11956
11957 static enum rte_eth_input_set_field
11958 str2inset(char *string)
11959 {
11960         uint16_t i;
11961
11962         static const struct {
11963                 char str[32];
11964                 enum rte_eth_input_set_field inset;
11965         } inset_table[] = {
11966                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11967                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11968                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11969                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11970                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11971                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11972                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11973                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11974                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11975                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11976                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11977                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11978                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11979                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11980                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11981                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11982                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11983                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11984                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11985                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11986                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11987                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11988                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11989                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11990                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11991                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11992                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11993                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11994                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11995                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11996                 {"none", RTE_ETH_INPUT_SET_NONE},
11997         };
11998
11999         for (i = 0; i < RTE_DIM(inset_table); i++) {
12000                 if (!strcmp(string, inset_table[i].str))
12001                         return inset_table[i].inset;
12002         }
12003
12004         return RTE_ETH_INPUT_SET_UNKNOWN;
12005 }
12006
12007 static void
12008 cmd_set_hash_input_set_parsed(void *parsed_result,
12009                               __rte_unused struct cmdline *cl,
12010                               __rte_unused void *data)
12011 {
12012         struct cmd_set_hash_input_set_result *res = parsed_result;
12013         struct rte_eth_hash_filter_info info;
12014
12015         memset(&info, 0, sizeof(info));
12016         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12017         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12018         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12019         info.info.input_set_conf.inset_size = 1;
12020         if (!strcmp(res->select, "select"))
12021                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12022         else if (!strcmp(res->select, "add"))
12023                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12024         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12025                                 RTE_ETH_FILTER_SET, &info);
12026 }
12027
12028 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12029         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12030                 set_hash_input_set, "set_hash_input_set");
12031 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12032         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12033                 port_id, UINT16);
12034 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12035         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12036                 flow_type, NULL);
12037 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12038         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12039                 inset_field,
12040                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12041                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12042                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12043                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12044                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12045                 "fld-8th#none");
12046 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12047         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12048                 select, "select#add");
12049
12050 cmdline_parse_inst_t cmd_set_hash_input_set = {
12051         .f = cmd_set_hash_input_set_parsed,
12052         .data = NULL,
12053         .help_str = "set_hash_input_set <port_id> "
12054         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12055         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12056         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12057         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12058         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12059         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12060         "fld-7th|fld-8th|none select|add",
12061         .tokens = {
12062                 (void *)&cmd_set_hash_input_set_cmd,
12063                 (void *)&cmd_set_hash_input_set_port_id,
12064                 (void *)&cmd_set_hash_input_set_flow_type,
12065                 (void *)&cmd_set_hash_input_set_field,
12066                 (void *)&cmd_set_hash_input_set_select,
12067                 NULL,
12068         },
12069 };
12070
12071 /* Set flow director input set */
12072 struct cmd_set_fdir_input_set_result {
12073         cmdline_fixed_string_t set_fdir_input_set;
12074         portid_t port_id;
12075         cmdline_fixed_string_t flow_type;
12076         cmdline_fixed_string_t inset_field;
12077         cmdline_fixed_string_t select;
12078 };
12079
12080 static void
12081 cmd_set_fdir_input_set_parsed(void *parsed_result,
12082         __rte_unused struct cmdline *cl,
12083         __rte_unused void *data)
12084 {
12085         struct cmd_set_fdir_input_set_result *res = parsed_result;
12086         struct rte_eth_fdir_filter_info info;
12087
12088         memset(&info, 0, sizeof(info));
12089         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12090         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12091         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12092         info.info.input_set_conf.inset_size = 1;
12093         if (!strcmp(res->select, "select"))
12094                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12095         else if (!strcmp(res->select, "add"))
12096                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12097         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12098                 RTE_ETH_FILTER_SET, &info);
12099 }
12100
12101 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12102         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12103         set_fdir_input_set, "set_fdir_input_set");
12104 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12105         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12106         port_id, UINT16);
12107 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12108         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12109         flow_type,
12110         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12111         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12112 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12113         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12114         inset_field,
12115         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12116         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12117         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12118         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12119         "sctp-veri-tag#none");
12120 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12121         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12122         select, "select#add");
12123
12124 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12125         .f = cmd_set_fdir_input_set_parsed,
12126         .data = NULL,
12127         .help_str = "set_fdir_input_set <port_id> "
12128         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12129         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12130         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12131         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12132         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12133         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12134         "sctp-veri-tag|none select|add",
12135         .tokens = {
12136                 (void *)&cmd_set_fdir_input_set_cmd,
12137                 (void *)&cmd_set_fdir_input_set_port_id,
12138                 (void *)&cmd_set_fdir_input_set_flow_type,
12139                 (void *)&cmd_set_fdir_input_set_field,
12140                 (void *)&cmd_set_fdir_input_set_select,
12141                 NULL,
12142         },
12143 };
12144
12145 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12146 struct cmd_mcast_addr_result {
12147         cmdline_fixed_string_t mcast_addr_cmd;
12148         cmdline_fixed_string_t what;
12149         uint16_t port_num;
12150         struct ether_addr mc_addr;
12151 };
12152
12153 static void cmd_mcast_addr_parsed(void *parsed_result,
12154                 __attribute__((unused)) struct cmdline *cl,
12155                 __attribute__((unused)) void *data)
12156 {
12157         struct cmd_mcast_addr_result *res = parsed_result;
12158
12159         if (!is_multicast_ether_addr(&res->mc_addr)) {
12160                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12161                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12162                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12163                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12164                 return;
12165         }
12166         if (strcmp(res->what, "add") == 0)
12167                 mcast_addr_add(res->port_num, &res->mc_addr);
12168         else
12169                 mcast_addr_remove(res->port_num, &res->mc_addr);
12170 }
12171
12172 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12173         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12174                                  mcast_addr_cmd, "mcast_addr");
12175 cmdline_parse_token_string_t cmd_mcast_addr_what =
12176         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12177                                  "add#remove");
12178 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12179         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12180 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12181         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12182
12183 cmdline_parse_inst_t cmd_mcast_addr = {
12184         .f = cmd_mcast_addr_parsed,
12185         .data = (void *)0,
12186         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12187                 "Add/Remove multicast MAC address on port_id",
12188         .tokens = {
12189                 (void *)&cmd_mcast_addr_cmd,
12190                 (void *)&cmd_mcast_addr_what,
12191                 (void *)&cmd_mcast_addr_portnum,
12192                 (void *)&cmd_mcast_addr_addr,
12193                 NULL,
12194         },
12195 };
12196
12197 /* l2 tunnel config
12198  * only support E-tag now.
12199  */
12200
12201 /* Ether type config */
12202 struct cmd_config_l2_tunnel_eth_type_result {
12203         cmdline_fixed_string_t port;
12204         cmdline_fixed_string_t config;
12205         cmdline_fixed_string_t all;
12206         portid_t id;
12207         cmdline_fixed_string_t l2_tunnel;
12208         cmdline_fixed_string_t l2_tunnel_type;
12209         cmdline_fixed_string_t eth_type;
12210         uint16_t eth_type_val;
12211 };
12212
12213 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12214         TOKEN_STRING_INITIALIZER
12215                 (struct cmd_config_l2_tunnel_eth_type_result,
12216                  port, "port");
12217 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12218         TOKEN_STRING_INITIALIZER
12219                 (struct cmd_config_l2_tunnel_eth_type_result,
12220                  config, "config");
12221 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12222         TOKEN_STRING_INITIALIZER
12223                 (struct cmd_config_l2_tunnel_eth_type_result,
12224                  all, "all");
12225 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12226         TOKEN_NUM_INITIALIZER
12227                 (struct cmd_config_l2_tunnel_eth_type_result,
12228                  id, UINT16);
12229 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12230         TOKEN_STRING_INITIALIZER
12231                 (struct cmd_config_l2_tunnel_eth_type_result,
12232                  l2_tunnel, "l2-tunnel");
12233 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12234         TOKEN_STRING_INITIALIZER
12235                 (struct cmd_config_l2_tunnel_eth_type_result,
12236                  l2_tunnel_type, "E-tag");
12237 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12238         TOKEN_STRING_INITIALIZER
12239                 (struct cmd_config_l2_tunnel_eth_type_result,
12240                  eth_type, "ether-type");
12241 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12242         TOKEN_NUM_INITIALIZER
12243                 (struct cmd_config_l2_tunnel_eth_type_result,
12244                  eth_type_val, UINT16);
12245
12246 static enum rte_eth_tunnel_type
12247 str2fdir_l2_tunnel_type(char *string)
12248 {
12249         uint32_t i = 0;
12250
12251         static const struct {
12252                 char str[32];
12253                 enum rte_eth_tunnel_type type;
12254         } l2_tunnel_type_str[] = {
12255                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12256         };
12257
12258         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12259                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12260                         return l2_tunnel_type_str[i].type;
12261         }
12262         return RTE_TUNNEL_TYPE_NONE;
12263 }
12264
12265 /* ether type config for all ports */
12266 static void
12267 cmd_config_l2_tunnel_eth_type_all_parsed
12268         (void *parsed_result,
12269          __attribute__((unused)) struct cmdline *cl,
12270          __attribute__((unused)) void *data)
12271 {
12272         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12273         struct rte_eth_l2_tunnel_conf entry;
12274         portid_t pid;
12275
12276         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12277         entry.ether_type = res->eth_type_val;
12278
12279         RTE_ETH_FOREACH_DEV(pid) {
12280                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12281         }
12282 }
12283
12284 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12285         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12286         .data = NULL,
12287         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12288         .tokens = {
12289                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12290                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12291                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12292                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12293                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12294                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12295                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12296                 NULL,
12297         },
12298 };
12299
12300 /* ether type config for a specific port */
12301 static void
12302 cmd_config_l2_tunnel_eth_type_specific_parsed(
12303         void *parsed_result,
12304         __attribute__((unused)) struct cmdline *cl,
12305         __attribute__((unused)) void *data)
12306 {
12307         struct cmd_config_l2_tunnel_eth_type_result *res =
12308                  parsed_result;
12309         struct rte_eth_l2_tunnel_conf entry;
12310
12311         if (port_id_is_invalid(res->id, ENABLED_WARN))
12312                 return;
12313
12314         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12315         entry.ether_type = res->eth_type_val;
12316
12317         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12318 }
12319
12320 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12321         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12322         .data = NULL,
12323         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12324         .tokens = {
12325                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12326                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12327                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12328                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12329                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12330                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12331                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12332                 NULL,
12333         },
12334 };
12335
12336 /* Enable/disable l2 tunnel */
12337 struct cmd_config_l2_tunnel_en_dis_result {
12338         cmdline_fixed_string_t port;
12339         cmdline_fixed_string_t config;
12340         cmdline_fixed_string_t all;
12341         portid_t id;
12342         cmdline_fixed_string_t l2_tunnel;
12343         cmdline_fixed_string_t l2_tunnel_type;
12344         cmdline_fixed_string_t en_dis;
12345 };
12346
12347 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12348         TOKEN_STRING_INITIALIZER
12349                 (struct cmd_config_l2_tunnel_en_dis_result,
12350                  port, "port");
12351 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12352         TOKEN_STRING_INITIALIZER
12353                 (struct cmd_config_l2_tunnel_en_dis_result,
12354                  config, "config");
12355 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12356         TOKEN_STRING_INITIALIZER
12357                 (struct cmd_config_l2_tunnel_en_dis_result,
12358                  all, "all");
12359 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12360         TOKEN_NUM_INITIALIZER
12361                 (struct cmd_config_l2_tunnel_en_dis_result,
12362                  id, UINT16);
12363 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12364         TOKEN_STRING_INITIALIZER
12365                 (struct cmd_config_l2_tunnel_en_dis_result,
12366                  l2_tunnel, "l2-tunnel");
12367 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12368         TOKEN_STRING_INITIALIZER
12369                 (struct cmd_config_l2_tunnel_en_dis_result,
12370                  l2_tunnel_type, "E-tag");
12371 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12372         TOKEN_STRING_INITIALIZER
12373                 (struct cmd_config_l2_tunnel_en_dis_result,
12374                  en_dis, "enable#disable");
12375
12376 /* enable/disable l2 tunnel for all ports */
12377 static void
12378 cmd_config_l2_tunnel_en_dis_all_parsed(
12379         void *parsed_result,
12380         __attribute__((unused)) struct cmdline *cl,
12381         __attribute__((unused)) void *data)
12382 {
12383         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12384         struct rte_eth_l2_tunnel_conf entry;
12385         portid_t pid;
12386         uint8_t en;
12387
12388         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12389
12390         if (!strcmp("enable", res->en_dis))
12391                 en = 1;
12392         else
12393                 en = 0;
12394
12395         RTE_ETH_FOREACH_DEV(pid) {
12396                 rte_eth_dev_l2_tunnel_offload_set(pid,
12397                                                   &entry,
12398                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12399                                                   en);
12400         }
12401 }
12402
12403 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12404         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12405         .data = NULL,
12406         .help_str = "port config all l2-tunnel E-tag enable|disable",
12407         .tokens = {
12408                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12409                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12410                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12411                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12412                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12413                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12414                 NULL,
12415         },
12416 };
12417
12418 /* enable/disable l2 tunnel for a port */
12419 static void
12420 cmd_config_l2_tunnel_en_dis_specific_parsed(
12421         void *parsed_result,
12422         __attribute__((unused)) struct cmdline *cl,
12423         __attribute__((unused)) void *data)
12424 {
12425         struct cmd_config_l2_tunnel_en_dis_result *res =
12426                 parsed_result;
12427         struct rte_eth_l2_tunnel_conf entry;
12428
12429         if (port_id_is_invalid(res->id, ENABLED_WARN))
12430                 return;
12431
12432         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12433
12434         if (!strcmp("enable", res->en_dis))
12435                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12436                                                   &entry,
12437                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12438                                                   1);
12439         else
12440                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12441                                                   &entry,
12442                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12443                                                   0);
12444 }
12445
12446 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12447         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12448         .data = NULL,
12449         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12450         .tokens = {
12451                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12452                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12453                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12454                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12455                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12456                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12457                 NULL,
12458         },
12459 };
12460
12461 /* E-tag configuration */
12462
12463 /* Common result structure for all E-tag configuration */
12464 struct cmd_config_e_tag_result {
12465         cmdline_fixed_string_t e_tag;
12466         cmdline_fixed_string_t set;
12467         cmdline_fixed_string_t insertion;
12468         cmdline_fixed_string_t stripping;
12469         cmdline_fixed_string_t forwarding;
12470         cmdline_fixed_string_t filter;
12471         cmdline_fixed_string_t add;
12472         cmdline_fixed_string_t del;
12473         cmdline_fixed_string_t on;
12474         cmdline_fixed_string_t off;
12475         cmdline_fixed_string_t on_off;
12476         cmdline_fixed_string_t port_tag_id;
12477         uint32_t port_tag_id_val;
12478         cmdline_fixed_string_t e_tag_id;
12479         uint16_t e_tag_id_val;
12480         cmdline_fixed_string_t dst_pool;
12481         uint8_t dst_pool_val;
12482         cmdline_fixed_string_t port;
12483         portid_t port_id;
12484         cmdline_fixed_string_t vf;
12485         uint8_t vf_id;
12486 };
12487
12488 /* Common CLI fields for all E-tag configuration */
12489 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12490         TOKEN_STRING_INITIALIZER
12491                 (struct cmd_config_e_tag_result,
12492                  e_tag, "E-tag");
12493 cmdline_parse_token_string_t cmd_config_e_tag_set =
12494         TOKEN_STRING_INITIALIZER
12495                 (struct cmd_config_e_tag_result,
12496                  set, "set");
12497 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12498         TOKEN_STRING_INITIALIZER
12499                 (struct cmd_config_e_tag_result,
12500                  insertion, "insertion");
12501 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12502         TOKEN_STRING_INITIALIZER
12503                 (struct cmd_config_e_tag_result,
12504                  stripping, "stripping");
12505 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12506         TOKEN_STRING_INITIALIZER
12507                 (struct cmd_config_e_tag_result,
12508                  forwarding, "forwarding");
12509 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12510         TOKEN_STRING_INITIALIZER
12511                 (struct cmd_config_e_tag_result,
12512                  filter, "filter");
12513 cmdline_parse_token_string_t cmd_config_e_tag_add =
12514         TOKEN_STRING_INITIALIZER
12515                 (struct cmd_config_e_tag_result,
12516                  add, "add");
12517 cmdline_parse_token_string_t cmd_config_e_tag_del =
12518         TOKEN_STRING_INITIALIZER
12519                 (struct cmd_config_e_tag_result,
12520                  del, "del");
12521 cmdline_parse_token_string_t cmd_config_e_tag_on =
12522         TOKEN_STRING_INITIALIZER
12523                 (struct cmd_config_e_tag_result,
12524                  on, "on");
12525 cmdline_parse_token_string_t cmd_config_e_tag_off =
12526         TOKEN_STRING_INITIALIZER
12527                 (struct cmd_config_e_tag_result,
12528                  off, "off");
12529 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12530         TOKEN_STRING_INITIALIZER
12531                 (struct cmd_config_e_tag_result,
12532                  on_off, "on#off");
12533 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12534         TOKEN_STRING_INITIALIZER
12535                 (struct cmd_config_e_tag_result,
12536                  port_tag_id, "port-tag-id");
12537 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12538         TOKEN_NUM_INITIALIZER
12539                 (struct cmd_config_e_tag_result,
12540                  port_tag_id_val, UINT32);
12541 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12542         TOKEN_STRING_INITIALIZER
12543                 (struct cmd_config_e_tag_result,
12544                  e_tag_id, "e-tag-id");
12545 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12546         TOKEN_NUM_INITIALIZER
12547                 (struct cmd_config_e_tag_result,
12548                  e_tag_id_val, UINT16);
12549 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12550         TOKEN_STRING_INITIALIZER
12551                 (struct cmd_config_e_tag_result,
12552                  dst_pool, "dst-pool");
12553 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12554         TOKEN_NUM_INITIALIZER
12555                 (struct cmd_config_e_tag_result,
12556                  dst_pool_val, UINT8);
12557 cmdline_parse_token_string_t cmd_config_e_tag_port =
12558         TOKEN_STRING_INITIALIZER
12559                 (struct cmd_config_e_tag_result,
12560                  port, "port");
12561 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12562         TOKEN_NUM_INITIALIZER
12563                 (struct cmd_config_e_tag_result,
12564                  port_id, UINT16);
12565 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12566         TOKEN_STRING_INITIALIZER
12567                 (struct cmd_config_e_tag_result,
12568                  vf, "vf");
12569 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12570         TOKEN_NUM_INITIALIZER
12571                 (struct cmd_config_e_tag_result,
12572                  vf_id, UINT8);
12573
12574 /* E-tag insertion configuration */
12575 static void
12576 cmd_config_e_tag_insertion_en_parsed(
12577         void *parsed_result,
12578         __attribute__((unused)) struct cmdline *cl,
12579         __attribute__((unused)) void *data)
12580 {
12581         struct cmd_config_e_tag_result *res =
12582                 parsed_result;
12583         struct rte_eth_l2_tunnel_conf entry;
12584
12585         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12586                 return;
12587
12588         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12589         entry.tunnel_id = res->port_tag_id_val;
12590         entry.vf_id = res->vf_id;
12591         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12592                                           &entry,
12593                                           ETH_L2_TUNNEL_INSERTION_MASK,
12594                                           1);
12595 }
12596
12597 static void
12598 cmd_config_e_tag_insertion_dis_parsed(
12599         void *parsed_result,
12600         __attribute__((unused)) struct cmdline *cl,
12601         __attribute__((unused)) void *data)
12602 {
12603         struct cmd_config_e_tag_result *res =
12604                 parsed_result;
12605         struct rte_eth_l2_tunnel_conf entry;
12606
12607         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12608                 return;
12609
12610         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12611         entry.vf_id = res->vf_id;
12612
12613         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12614                                           &entry,
12615                                           ETH_L2_TUNNEL_INSERTION_MASK,
12616                                           0);
12617 }
12618
12619 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12620         .f = cmd_config_e_tag_insertion_en_parsed,
12621         .data = NULL,
12622         .help_str = "E-tag ... : E-tag insertion enable",
12623         .tokens = {
12624                 (void *)&cmd_config_e_tag_e_tag,
12625                 (void *)&cmd_config_e_tag_set,
12626                 (void *)&cmd_config_e_tag_insertion,
12627                 (void *)&cmd_config_e_tag_on,
12628                 (void *)&cmd_config_e_tag_port_tag_id,
12629                 (void *)&cmd_config_e_tag_port_tag_id_val,
12630                 (void *)&cmd_config_e_tag_port,
12631                 (void *)&cmd_config_e_tag_port_id,
12632                 (void *)&cmd_config_e_tag_vf,
12633                 (void *)&cmd_config_e_tag_vf_id,
12634                 NULL,
12635         },
12636 };
12637
12638 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12639         .f = cmd_config_e_tag_insertion_dis_parsed,
12640         .data = NULL,
12641         .help_str = "E-tag ... : E-tag insertion disable",
12642         .tokens = {
12643                 (void *)&cmd_config_e_tag_e_tag,
12644                 (void *)&cmd_config_e_tag_set,
12645                 (void *)&cmd_config_e_tag_insertion,
12646                 (void *)&cmd_config_e_tag_off,
12647                 (void *)&cmd_config_e_tag_port,
12648                 (void *)&cmd_config_e_tag_port_id,
12649                 (void *)&cmd_config_e_tag_vf,
12650                 (void *)&cmd_config_e_tag_vf_id,
12651                 NULL,
12652         },
12653 };
12654
12655 /* E-tag stripping configuration */
12656 static void
12657 cmd_config_e_tag_stripping_parsed(
12658         void *parsed_result,
12659         __attribute__((unused)) struct cmdline *cl,
12660         __attribute__((unused)) void *data)
12661 {
12662         struct cmd_config_e_tag_result *res =
12663                 parsed_result;
12664         struct rte_eth_l2_tunnel_conf entry;
12665
12666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12667                 return;
12668
12669         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12670
12671         if (!strcmp(res->on_off, "on"))
12672                 rte_eth_dev_l2_tunnel_offload_set
12673                         (res->port_id,
12674                          &entry,
12675                          ETH_L2_TUNNEL_STRIPPING_MASK,
12676                          1);
12677         else
12678                 rte_eth_dev_l2_tunnel_offload_set
12679                         (res->port_id,
12680                          &entry,
12681                          ETH_L2_TUNNEL_STRIPPING_MASK,
12682                          0);
12683 }
12684
12685 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12686         .f = cmd_config_e_tag_stripping_parsed,
12687         .data = NULL,
12688         .help_str = "E-tag ... : E-tag stripping enable/disable",
12689         .tokens = {
12690                 (void *)&cmd_config_e_tag_e_tag,
12691                 (void *)&cmd_config_e_tag_set,
12692                 (void *)&cmd_config_e_tag_stripping,
12693                 (void *)&cmd_config_e_tag_on_off,
12694                 (void *)&cmd_config_e_tag_port,
12695                 (void *)&cmd_config_e_tag_port_id,
12696                 NULL,
12697         },
12698 };
12699
12700 /* E-tag forwarding configuration */
12701 static void
12702 cmd_config_e_tag_forwarding_parsed(
12703         void *parsed_result,
12704         __attribute__((unused)) struct cmdline *cl,
12705         __attribute__((unused)) void *data)
12706 {
12707         struct cmd_config_e_tag_result *res = parsed_result;
12708         struct rte_eth_l2_tunnel_conf entry;
12709
12710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12711                 return;
12712
12713         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12714
12715         if (!strcmp(res->on_off, "on"))
12716                 rte_eth_dev_l2_tunnel_offload_set
12717                         (res->port_id,
12718                          &entry,
12719                          ETH_L2_TUNNEL_FORWARDING_MASK,
12720                          1);
12721         else
12722                 rte_eth_dev_l2_tunnel_offload_set
12723                         (res->port_id,
12724                          &entry,
12725                          ETH_L2_TUNNEL_FORWARDING_MASK,
12726                          0);
12727 }
12728
12729 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12730         .f = cmd_config_e_tag_forwarding_parsed,
12731         .data = NULL,
12732         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12733         .tokens = {
12734                 (void *)&cmd_config_e_tag_e_tag,
12735                 (void *)&cmd_config_e_tag_set,
12736                 (void *)&cmd_config_e_tag_forwarding,
12737                 (void *)&cmd_config_e_tag_on_off,
12738                 (void *)&cmd_config_e_tag_port,
12739                 (void *)&cmd_config_e_tag_port_id,
12740                 NULL,
12741         },
12742 };
12743
12744 /* E-tag filter configuration */
12745 static void
12746 cmd_config_e_tag_filter_add_parsed(
12747         void *parsed_result,
12748         __attribute__((unused)) struct cmdline *cl,
12749         __attribute__((unused)) void *data)
12750 {
12751         struct cmd_config_e_tag_result *res = parsed_result;
12752         struct rte_eth_l2_tunnel_conf entry;
12753         int ret = 0;
12754
12755         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12756                 return;
12757
12758         if (res->e_tag_id_val > 0x3fff) {
12759                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12760                 return;
12761         }
12762
12763         ret = rte_eth_dev_filter_supported(res->port_id,
12764                                            RTE_ETH_FILTER_L2_TUNNEL);
12765         if (ret < 0) {
12766                 printf("E-tag filter is not supported on port %u.\n",
12767                        res->port_id);
12768                 return;
12769         }
12770
12771         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12772         entry.tunnel_id = res->e_tag_id_val;
12773         entry.pool = res->dst_pool_val;
12774
12775         ret = rte_eth_dev_filter_ctrl(res->port_id,
12776                                       RTE_ETH_FILTER_L2_TUNNEL,
12777                                       RTE_ETH_FILTER_ADD,
12778                                       &entry);
12779         if (ret < 0)
12780                 printf("E-tag filter programming error: (%s)\n",
12781                        strerror(-ret));
12782 }
12783
12784 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12785         .f = cmd_config_e_tag_filter_add_parsed,
12786         .data = NULL,
12787         .help_str = "E-tag ... : E-tag filter add",
12788         .tokens = {
12789                 (void *)&cmd_config_e_tag_e_tag,
12790                 (void *)&cmd_config_e_tag_set,
12791                 (void *)&cmd_config_e_tag_filter,
12792                 (void *)&cmd_config_e_tag_add,
12793                 (void *)&cmd_config_e_tag_e_tag_id,
12794                 (void *)&cmd_config_e_tag_e_tag_id_val,
12795                 (void *)&cmd_config_e_tag_dst_pool,
12796                 (void *)&cmd_config_e_tag_dst_pool_val,
12797                 (void *)&cmd_config_e_tag_port,
12798                 (void *)&cmd_config_e_tag_port_id,
12799                 NULL,
12800         },
12801 };
12802
12803 static void
12804 cmd_config_e_tag_filter_del_parsed(
12805         void *parsed_result,
12806         __attribute__((unused)) struct cmdline *cl,
12807         __attribute__((unused)) void *data)
12808 {
12809         struct cmd_config_e_tag_result *res = parsed_result;
12810         struct rte_eth_l2_tunnel_conf entry;
12811         int ret = 0;
12812
12813         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12814                 return;
12815
12816         if (res->e_tag_id_val > 0x3fff) {
12817                 printf("e-tag-id must be less than 0x3fff.\n");
12818                 return;
12819         }
12820
12821         ret = rte_eth_dev_filter_supported(res->port_id,
12822                                            RTE_ETH_FILTER_L2_TUNNEL);
12823         if (ret < 0) {
12824                 printf("E-tag filter is not supported on port %u.\n",
12825                        res->port_id);
12826                 return;
12827         }
12828
12829         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12830         entry.tunnel_id = res->e_tag_id_val;
12831
12832         ret = rte_eth_dev_filter_ctrl(res->port_id,
12833                                       RTE_ETH_FILTER_L2_TUNNEL,
12834                                       RTE_ETH_FILTER_DELETE,
12835                                       &entry);
12836         if (ret < 0)
12837                 printf("E-tag filter programming error: (%s)\n",
12838                        strerror(-ret));
12839 }
12840
12841 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12842         .f = cmd_config_e_tag_filter_del_parsed,
12843         .data = NULL,
12844         .help_str = "E-tag ... : E-tag filter delete",
12845         .tokens = {
12846                 (void *)&cmd_config_e_tag_e_tag,
12847                 (void *)&cmd_config_e_tag_set,
12848                 (void *)&cmd_config_e_tag_filter,
12849                 (void *)&cmd_config_e_tag_del,
12850                 (void *)&cmd_config_e_tag_e_tag_id,
12851                 (void *)&cmd_config_e_tag_e_tag_id_val,
12852                 (void *)&cmd_config_e_tag_port,
12853                 (void *)&cmd_config_e_tag_port_id,
12854                 NULL,
12855         },
12856 };
12857
12858 /* vf vlan anti spoof configuration */
12859
12860 /* Common result structure for vf vlan anti spoof */
12861 struct cmd_vf_vlan_anti_spoof_result {
12862         cmdline_fixed_string_t set;
12863         cmdline_fixed_string_t vf;
12864         cmdline_fixed_string_t vlan;
12865         cmdline_fixed_string_t antispoof;
12866         portid_t port_id;
12867         uint32_t vf_id;
12868         cmdline_fixed_string_t on_off;
12869 };
12870
12871 /* Common CLI fields for vf vlan anti spoof enable disable */
12872 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12873         TOKEN_STRING_INITIALIZER
12874                 (struct cmd_vf_vlan_anti_spoof_result,
12875                  set, "set");
12876 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_vf_vlan_anti_spoof_result,
12879                  vf, "vf");
12880 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_vf_vlan_anti_spoof_result,
12883                  vlan, "vlan");
12884 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_vf_vlan_anti_spoof_result,
12887                  antispoof, "antispoof");
12888 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12889         TOKEN_NUM_INITIALIZER
12890                 (struct cmd_vf_vlan_anti_spoof_result,
12891                  port_id, UINT16);
12892 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12893         TOKEN_NUM_INITIALIZER
12894                 (struct cmd_vf_vlan_anti_spoof_result,
12895                  vf_id, UINT32);
12896 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12897         TOKEN_STRING_INITIALIZER
12898                 (struct cmd_vf_vlan_anti_spoof_result,
12899                  on_off, "on#off");
12900
12901 static void
12902 cmd_set_vf_vlan_anti_spoof_parsed(
12903         void *parsed_result,
12904         __attribute__((unused)) struct cmdline *cl,
12905         __attribute__((unused)) void *data)
12906 {
12907         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12908         int ret = -ENOTSUP;
12909
12910         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12911
12912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12913                 return;
12914
12915 #ifdef RTE_LIBRTE_IXGBE_PMD
12916         if (ret == -ENOTSUP)
12917                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12918                                 res->vf_id, is_on);
12919 #endif
12920 #ifdef RTE_LIBRTE_I40E_PMD
12921         if (ret == -ENOTSUP)
12922                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12923                                 res->vf_id, is_on);
12924 #endif
12925 #ifdef RTE_LIBRTE_BNXT_PMD
12926         if (ret == -ENOTSUP)
12927                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12928                                 res->vf_id, is_on);
12929 #endif
12930
12931         switch (ret) {
12932         case 0:
12933                 break;
12934         case -EINVAL:
12935                 printf("invalid vf_id %d\n", res->vf_id);
12936                 break;
12937         case -ENODEV:
12938                 printf("invalid port_id %d\n", res->port_id);
12939                 break;
12940         case -ENOTSUP:
12941                 printf("function not implemented\n");
12942                 break;
12943         default:
12944                 printf("programming error: (%s)\n", strerror(-ret));
12945         }
12946 }
12947
12948 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12949         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12950         .data = NULL,
12951         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12952         .tokens = {
12953                 (void *)&cmd_vf_vlan_anti_spoof_set,
12954                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12955                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12956                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12957                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12958                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12959                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12960                 NULL,
12961         },
12962 };
12963
12964 /* vf mac anti spoof configuration */
12965
12966 /* Common result structure for vf mac anti spoof */
12967 struct cmd_vf_mac_anti_spoof_result {
12968         cmdline_fixed_string_t set;
12969         cmdline_fixed_string_t vf;
12970         cmdline_fixed_string_t mac;
12971         cmdline_fixed_string_t antispoof;
12972         portid_t port_id;
12973         uint32_t vf_id;
12974         cmdline_fixed_string_t on_off;
12975 };
12976
12977 /* Common CLI fields for vf mac anti spoof enable disable */
12978 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12979         TOKEN_STRING_INITIALIZER
12980                 (struct cmd_vf_mac_anti_spoof_result,
12981                  set, "set");
12982 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12983         TOKEN_STRING_INITIALIZER
12984                 (struct cmd_vf_mac_anti_spoof_result,
12985                  vf, "vf");
12986 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12987         TOKEN_STRING_INITIALIZER
12988                 (struct cmd_vf_mac_anti_spoof_result,
12989                  mac, "mac");
12990 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12991         TOKEN_STRING_INITIALIZER
12992                 (struct cmd_vf_mac_anti_spoof_result,
12993                  antispoof, "antispoof");
12994 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12995         TOKEN_NUM_INITIALIZER
12996                 (struct cmd_vf_mac_anti_spoof_result,
12997                  port_id, UINT16);
12998 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12999         TOKEN_NUM_INITIALIZER
13000                 (struct cmd_vf_mac_anti_spoof_result,
13001                  vf_id, UINT32);
13002 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13003         TOKEN_STRING_INITIALIZER
13004                 (struct cmd_vf_mac_anti_spoof_result,
13005                  on_off, "on#off");
13006
13007 static void
13008 cmd_set_vf_mac_anti_spoof_parsed(
13009         void *parsed_result,
13010         __attribute__((unused)) struct cmdline *cl,
13011         __attribute__((unused)) void *data)
13012 {
13013         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13014         int ret = -ENOTSUP;
13015
13016         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13017
13018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13019                 return;
13020
13021 #ifdef RTE_LIBRTE_IXGBE_PMD
13022         if (ret == -ENOTSUP)
13023                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13024                         res->vf_id, is_on);
13025 #endif
13026 #ifdef RTE_LIBRTE_I40E_PMD
13027         if (ret == -ENOTSUP)
13028                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13029                         res->vf_id, is_on);
13030 #endif
13031 #ifdef RTE_LIBRTE_BNXT_PMD
13032         if (ret == -ENOTSUP)
13033                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13034                         res->vf_id, is_on);
13035 #endif
13036
13037         switch (ret) {
13038         case 0:
13039                 break;
13040         case -EINVAL:
13041                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13042                 break;
13043         case -ENODEV:
13044                 printf("invalid port_id %d\n", res->port_id);
13045                 break;
13046         case -ENOTSUP:
13047                 printf("function not implemented\n");
13048                 break;
13049         default:
13050                 printf("programming error: (%s)\n", strerror(-ret));
13051         }
13052 }
13053
13054 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13055         .f = cmd_set_vf_mac_anti_spoof_parsed,
13056         .data = NULL,
13057         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13058         .tokens = {
13059                 (void *)&cmd_vf_mac_anti_spoof_set,
13060                 (void *)&cmd_vf_mac_anti_spoof_vf,
13061                 (void *)&cmd_vf_mac_anti_spoof_mac,
13062                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13063                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13064                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13065                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13066                 NULL,
13067         },
13068 };
13069
13070 /* vf vlan strip queue configuration */
13071
13072 /* Common result structure for vf mac anti spoof */
13073 struct cmd_vf_vlan_stripq_result {
13074         cmdline_fixed_string_t set;
13075         cmdline_fixed_string_t vf;
13076         cmdline_fixed_string_t vlan;
13077         cmdline_fixed_string_t stripq;
13078         portid_t port_id;
13079         uint16_t vf_id;
13080         cmdline_fixed_string_t on_off;
13081 };
13082
13083 /* Common CLI fields for vf vlan strip enable disable */
13084 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_vf_vlan_stripq_result,
13087                  set, "set");
13088 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_vf_vlan_stripq_result,
13091                  vf, "vf");
13092 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_vf_vlan_stripq_result,
13095                  vlan, "vlan");
13096 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13097         TOKEN_STRING_INITIALIZER
13098                 (struct cmd_vf_vlan_stripq_result,
13099                  stripq, "stripq");
13100 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13101         TOKEN_NUM_INITIALIZER
13102                 (struct cmd_vf_vlan_stripq_result,
13103                  port_id, UINT16);
13104 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13105         TOKEN_NUM_INITIALIZER
13106                 (struct cmd_vf_vlan_stripq_result,
13107                  vf_id, UINT16);
13108 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13109         TOKEN_STRING_INITIALIZER
13110                 (struct cmd_vf_vlan_stripq_result,
13111                  on_off, "on#off");
13112
13113 static void
13114 cmd_set_vf_vlan_stripq_parsed(
13115         void *parsed_result,
13116         __attribute__((unused)) struct cmdline *cl,
13117         __attribute__((unused)) void *data)
13118 {
13119         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13120         int ret = -ENOTSUP;
13121
13122         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13123
13124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13125                 return;
13126
13127 #ifdef RTE_LIBRTE_IXGBE_PMD
13128         if (ret == -ENOTSUP)
13129                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13130                         res->vf_id, is_on);
13131 #endif
13132 #ifdef RTE_LIBRTE_I40E_PMD
13133         if (ret == -ENOTSUP)
13134                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13135                         res->vf_id, is_on);
13136 #endif
13137 #ifdef RTE_LIBRTE_BNXT_PMD
13138         if (ret == -ENOTSUP)
13139                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13140                         res->vf_id, is_on);
13141 #endif
13142
13143         switch (ret) {
13144         case 0:
13145                 break;
13146         case -EINVAL:
13147                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13148                 break;
13149         case -ENODEV:
13150                 printf("invalid port_id %d\n", res->port_id);
13151                 break;
13152         case -ENOTSUP:
13153                 printf("function not implemented\n");
13154                 break;
13155         default:
13156                 printf("programming error: (%s)\n", strerror(-ret));
13157         }
13158 }
13159
13160 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13161         .f = cmd_set_vf_vlan_stripq_parsed,
13162         .data = NULL,
13163         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13164         .tokens = {
13165                 (void *)&cmd_vf_vlan_stripq_set,
13166                 (void *)&cmd_vf_vlan_stripq_vf,
13167                 (void *)&cmd_vf_vlan_stripq_vlan,
13168                 (void *)&cmd_vf_vlan_stripq_stripq,
13169                 (void *)&cmd_vf_vlan_stripq_port_id,
13170                 (void *)&cmd_vf_vlan_stripq_vf_id,
13171                 (void *)&cmd_vf_vlan_stripq_on_off,
13172                 NULL,
13173         },
13174 };
13175
13176 /* vf vlan insert configuration */
13177
13178 /* Common result structure for vf vlan insert */
13179 struct cmd_vf_vlan_insert_result {
13180         cmdline_fixed_string_t set;
13181         cmdline_fixed_string_t vf;
13182         cmdline_fixed_string_t vlan;
13183         cmdline_fixed_string_t insert;
13184         portid_t port_id;
13185         uint16_t vf_id;
13186         uint16_t vlan_id;
13187 };
13188
13189 /* Common CLI fields for vf vlan insert enable disable */
13190 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13191         TOKEN_STRING_INITIALIZER
13192                 (struct cmd_vf_vlan_insert_result,
13193                  set, "set");
13194 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13195         TOKEN_STRING_INITIALIZER
13196                 (struct cmd_vf_vlan_insert_result,
13197                  vf, "vf");
13198 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13199         TOKEN_STRING_INITIALIZER
13200                 (struct cmd_vf_vlan_insert_result,
13201                  vlan, "vlan");
13202 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13203         TOKEN_STRING_INITIALIZER
13204                 (struct cmd_vf_vlan_insert_result,
13205                  insert, "insert");
13206 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13207         TOKEN_NUM_INITIALIZER
13208                 (struct cmd_vf_vlan_insert_result,
13209                  port_id, UINT16);
13210 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13211         TOKEN_NUM_INITIALIZER
13212                 (struct cmd_vf_vlan_insert_result,
13213                  vf_id, UINT16);
13214 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13215         TOKEN_NUM_INITIALIZER
13216                 (struct cmd_vf_vlan_insert_result,
13217                  vlan_id, UINT16);
13218
13219 static void
13220 cmd_set_vf_vlan_insert_parsed(
13221         void *parsed_result,
13222         __attribute__((unused)) struct cmdline *cl,
13223         __attribute__((unused)) void *data)
13224 {
13225         struct cmd_vf_vlan_insert_result *res = parsed_result;
13226         int ret = -ENOTSUP;
13227
13228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13229                 return;
13230
13231 #ifdef RTE_LIBRTE_IXGBE_PMD
13232         if (ret == -ENOTSUP)
13233                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13234                         res->vlan_id);
13235 #endif
13236 #ifdef RTE_LIBRTE_I40E_PMD
13237         if (ret == -ENOTSUP)
13238                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13239                         res->vlan_id);
13240 #endif
13241 #ifdef RTE_LIBRTE_BNXT_PMD
13242         if (ret == -ENOTSUP)
13243                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13244                         res->vlan_id);
13245 #endif
13246
13247         switch (ret) {
13248         case 0:
13249                 break;
13250         case -EINVAL:
13251                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13252                 break;
13253         case -ENODEV:
13254                 printf("invalid port_id %d\n", res->port_id);
13255                 break;
13256         case -ENOTSUP:
13257                 printf("function not implemented\n");
13258                 break;
13259         default:
13260                 printf("programming error: (%s)\n", strerror(-ret));
13261         }
13262 }
13263
13264 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13265         .f = cmd_set_vf_vlan_insert_parsed,
13266         .data = NULL,
13267         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13268         .tokens = {
13269                 (void *)&cmd_vf_vlan_insert_set,
13270                 (void *)&cmd_vf_vlan_insert_vf,
13271                 (void *)&cmd_vf_vlan_insert_vlan,
13272                 (void *)&cmd_vf_vlan_insert_insert,
13273                 (void *)&cmd_vf_vlan_insert_port_id,
13274                 (void *)&cmd_vf_vlan_insert_vf_id,
13275                 (void *)&cmd_vf_vlan_insert_vlan_id,
13276                 NULL,
13277         },
13278 };
13279
13280 /* tx loopback configuration */
13281
13282 /* Common result structure for tx loopback */
13283 struct cmd_tx_loopback_result {
13284         cmdline_fixed_string_t set;
13285         cmdline_fixed_string_t tx;
13286         cmdline_fixed_string_t loopback;
13287         portid_t port_id;
13288         cmdline_fixed_string_t on_off;
13289 };
13290
13291 /* Common CLI fields for tx loopback enable disable */
13292 cmdline_parse_token_string_t cmd_tx_loopback_set =
13293         TOKEN_STRING_INITIALIZER
13294                 (struct cmd_tx_loopback_result,
13295                  set, "set");
13296 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13297         TOKEN_STRING_INITIALIZER
13298                 (struct cmd_tx_loopback_result,
13299                  tx, "tx");
13300 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13301         TOKEN_STRING_INITIALIZER
13302                 (struct cmd_tx_loopback_result,
13303                  loopback, "loopback");
13304 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13305         TOKEN_NUM_INITIALIZER
13306                 (struct cmd_tx_loopback_result,
13307                  port_id, UINT16);
13308 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13309         TOKEN_STRING_INITIALIZER
13310                 (struct cmd_tx_loopback_result,
13311                  on_off, "on#off");
13312
13313 static void
13314 cmd_set_tx_loopback_parsed(
13315         void *parsed_result,
13316         __attribute__((unused)) struct cmdline *cl,
13317         __attribute__((unused)) void *data)
13318 {
13319         struct cmd_tx_loopback_result *res = parsed_result;
13320         int ret = -ENOTSUP;
13321
13322         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13323
13324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13325                 return;
13326
13327 #ifdef RTE_LIBRTE_IXGBE_PMD
13328         if (ret == -ENOTSUP)
13329                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13330 #endif
13331 #ifdef RTE_LIBRTE_I40E_PMD
13332         if (ret == -ENOTSUP)
13333                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13334 #endif
13335 #ifdef RTE_LIBRTE_BNXT_PMD
13336         if (ret == -ENOTSUP)
13337                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13338 #endif
13339 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13340         if (ret == -ENOTSUP)
13341                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13342 #endif
13343
13344         switch (ret) {
13345         case 0:
13346                 break;
13347         case -EINVAL:
13348                 printf("invalid is_on %d\n", is_on);
13349                 break;
13350         case -ENODEV:
13351                 printf("invalid port_id %d\n", res->port_id);
13352                 break;
13353         case -ENOTSUP:
13354                 printf("function not implemented\n");
13355                 break;
13356         default:
13357                 printf("programming error: (%s)\n", strerror(-ret));
13358         }
13359 }
13360
13361 cmdline_parse_inst_t cmd_set_tx_loopback = {
13362         .f = cmd_set_tx_loopback_parsed,
13363         .data = NULL,
13364         .help_str = "set tx loopback <port_id> on|off",
13365         .tokens = {
13366                 (void *)&cmd_tx_loopback_set,
13367                 (void *)&cmd_tx_loopback_tx,
13368                 (void *)&cmd_tx_loopback_loopback,
13369                 (void *)&cmd_tx_loopback_port_id,
13370                 (void *)&cmd_tx_loopback_on_off,
13371                 NULL,
13372         },
13373 };
13374
13375 /* all queues drop enable configuration */
13376
13377 /* Common result structure for all queues drop enable */
13378 struct cmd_all_queues_drop_en_result {
13379         cmdline_fixed_string_t set;
13380         cmdline_fixed_string_t all;
13381         cmdline_fixed_string_t queues;
13382         cmdline_fixed_string_t drop;
13383         portid_t port_id;
13384         cmdline_fixed_string_t on_off;
13385 };
13386
13387 /* Common CLI fields for tx loopback enable disable */
13388 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13389         TOKEN_STRING_INITIALIZER
13390                 (struct cmd_all_queues_drop_en_result,
13391                  set, "set");
13392 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13393         TOKEN_STRING_INITIALIZER
13394                 (struct cmd_all_queues_drop_en_result,
13395                  all, "all");
13396 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13397         TOKEN_STRING_INITIALIZER
13398                 (struct cmd_all_queues_drop_en_result,
13399                  queues, "queues");
13400 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13401         TOKEN_STRING_INITIALIZER
13402                 (struct cmd_all_queues_drop_en_result,
13403                  drop, "drop");
13404 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13405         TOKEN_NUM_INITIALIZER
13406                 (struct cmd_all_queues_drop_en_result,
13407                  port_id, UINT16);
13408 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13409         TOKEN_STRING_INITIALIZER
13410                 (struct cmd_all_queues_drop_en_result,
13411                  on_off, "on#off");
13412
13413 static void
13414 cmd_set_all_queues_drop_en_parsed(
13415         void *parsed_result,
13416         __attribute__((unused)) struct cmdline *cl,
13417         __attribute__((unused)) void *data)
13418 {
13419         struct cmd_all_queues_drop_en_result *res = parsed_result;
13420         int ret = -ENOTSUP;
13421         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13422
13423         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13424                 return;
13425
13426 #ifdef RTE_LIBRTE_IXGBE_PMD
13427         if (ret == -ENOTSUP)
13428                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13429 #endif
13430 #ifdef RTE_LIBRTE_BNXT_PMD
13431         if (ret == -ENOTSUP)
13432                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13433 #endif
13434         switch (ret) {
13435         case 0:
13436                 break;
13437         case -EINVAL:
13438                 printf("invalid is_on %d\n", is_on);
13439                 break;
13440         case -ENODEV:
13441                 printf("invalid port_id %d\n", res->port_id);
13442                 break;
13443         case -ENOTSUP:
13444                 printf("function not implemented\n");
13445                 break;
13446         default:
13447                 printf("programming error: (%s)\n", strerror(-ret));
13448         }
13449 }
13450
13451 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13452         .f = cmd_set_all_queues_drop_en_parsed,
13453         .data = NULL,
13454         .help_str = "set all queues drop <port_id> on|off",
13455         .tokens = {
13456                 (void *)&cmd_all_queues_drop_en_set,
13457                 (void *)&cmd_all_queues_drop_en_all,
13458                 (void *)&cmd_all_queues_drop_en_queues,
13459                 (void *)&cmd_all_queues_drop_en_drop,
13460                 (void *)&cmd_all_queues_drop_en_port_id,
13461                 (void *)&cmd_all_queues_drop_en_on_off,
13462                 NULL,
13463         },
13464 };
13465
13466 /* vf split drop enable configuration */
13467
13468 /* Common result structure for vf split drop enable */
13469 struct cmd_vf_split_drop_en_result {
13470         cmdline_fixed_string_t set;
13471         cmdline_fixed_string_t vf;
13472         cmdline_fixed_string_t split;
13473         cmdline_fixed_string_t drop;
13474         portid_t port_id;
13475         uint16_t vf_id;
13476         cmdline_fixed_string_t on_off;
13477 };
13478
13479 /* Common CLI fields for vf split drop enable disable */
13480 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13481         TOKEN_STRING_INITIALIZER
13482                 (struct cmd_vf_split_drop_en_result,
13483                  set, "set");
13484 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13485         TOKEN_STRING_INITIALIZER
13486                 (struct cmd_vf_split_drop_en_result,
13487                  vf, "vf");
13488 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13489         TOKEN_STRING_INITIALIZER
13490                 (struct cmd_vf_split_drop_en_result,
13491                  split, "split");
13492 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13493         TOKEN_STRING_INITIALIZER
13494                 (struct cmd_vf_split_drop_en_result,
13495                  drop, "drop");
13496 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13497         TOKEN_NUM_INITIALIZER
13498                 (struct cmd_vf_split_drop_en_result,
13499                  port_id, UINT16);
13500 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13501         TOKEN_NUM_INITIALIZER
13502                 (struct cmd_vf_split_drop_en_result,
13503                  vf_id, UINT16);
13504 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13505         TOKEN_STRING_INITIALIZER
13506                 (struct cmd_vf_split_drop_en_result,
13507                  on_off, "on#off");
13508
13509 static void
13510 cmd_set_vf_split_drop_en_parsed(
13511         void *parsed_result,
13512         __attribute__((unused)) struct cmdline *cl,
13513         __attribute__((unused)) void *data)
13514 {
13515         struct cmd_vf_split_drop_en_result *res = parsed_result;
13516         int ret = -ENOTSUP;
13517         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13518
13519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13520                 return;
13521
13522 #ifdef RTE_LIBRTE_IXGBE_PMD
13523         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13524                         is_on);
13525 #endif
13526         switch (ret) {
13527         case 0:
13528                 break;
13529         case -EINVAL:
13530                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13531                 break;
13532         case -ENODEV:
13533                 printf("invalid port_id %d\n", res->port_id);
13534                 break;
13535         case -ENOTSUP:
13536                 printf("not supported on port %d\n", res->port_id);
13537                 break;
13538         default:
13539                 printf("programming error: (%s)\n", strerror(-ret));
13540         }
13541 }
13542
13543 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13544         .f = cmd_set_vf_split_drop_en_parsed,
13545         .data = NULL,
13546         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13547         .tokens = {
13548                 (void *)&cmd_vf_split_drop_en_set,
13549                 (void *)&cmd_vf_split_drop_en_vf,
13550                 (void *)&cmd_vf_split_drop_en_split,
13551                 (void *)&cmd_vf_split_drop_en_drop,
13552                 (void *)&cmd_vf_split_drop_en_port_id,
13553                 (void *)&cmd_vf_split_drop_en_vf_id,
13554                 (void *)&cmd_vf_split_drop_en_on_off,
13555                 NULL,
13556         },
13557 };
13558
13559 /* vf mac address configuration */
13560
13561 /* Common result structure for vf mac address */
13562 struct cmd_set_vf_mac_addr_result {
13563         cmdline_fixed_string_t set;
13564         cmdline_fixed_string_t vf;
13565         cmdline_fixed_string_t mac;
13566         cmdline_fixed_string_t addr;
13567         portid_t port_id;
13568         uint16_t vf_id;
13569         struct ether_addr mac_addr;
13570
13571 };
13572
13573 /* Common CLI fields for vf split drop enable disable */
13574 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13575         TOKEN_STRING_INITIALIZER
13576                 (struct cmd_set_vf_mac_addr_result,
13577                  set, "set");
13578 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_set_vf_mac_addr_result,
13581                  vf, "vf");
13582 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_set_vf_mac_addr_result,
13585                  mac, "mac");
13586 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13587         TOKEN_STRING_INITIALIZER
13588                 (struct cmd_set_vf_mac_addr_result,
13589                  addr, "addr");
13590 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13591         TOKEN_NUM_INITIALIZER
13592                 (struct cmd_set_vf_mac_addr_result,
13593                  port_id, UINT16);
13594 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13595         TOKEN_NUM_INITIALIZER
13596                 (struct cmd_set_vf_mac_addr_result,
13597                  vf_id, UINT16);
13598 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13599         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13600                  mac_addr);
13601
13602 static void
13603 cmd_set_vf_mac_addr_parsed(
13604         void *parsed_result,
13605         __attribute__((unused)) struct cmdline *cl,
13606         __attribute__((unused)) void *data)
13607 {
13608         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13609         int ret = -ENOTSUP;
13610
13611         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13612                 return;
13613
13614 #ifdef RTE_LIBRTE_IXGBE_PMD
13615         if (ret == -ENOTSUP)
13616                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13617                                 &res->mac_addr);
13618 #endif
13619 #ifdef RTE_LIBRTE_I40E_PMD
13620         if (ret == -ENOTSUP)
13621                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13622                                 &res->mac_addr);
13623 #endif
13624 #ifdef RTE_LIBRTE_BNXT_PMD
13625         if (ret == -ENOTSUP)
13626                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13627                                 &res->mac_addr);
13628 #endif
13629
13630         switch (ret) {
13631         case 0:
13632                 break;
13633         case -EINVAL:
13634                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13635                 break;
13636         case -ENODEV:
13637                 printf("invalid port_id %d\n", res->port_id);
13638                 break;
13639         case -ENOTSUP:
13640                 printf("function not implemented\n");
13641                 break;
13642         default:
13643                 printf("programming error: (%s)\n", strerror(-ret));
13644         }
13645 }
13646
13647 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13648         .f = cmd_set_vf_mac_addr_parsed,
13649         .data = NULL,
13650         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13651         .tokens = {
13652                 (void *)&cmd_set_vf_mac_addr_set,
13653                 (void *)&cmd_set_vf_mac_addr_vf,
13654                 (void *)&cmd_set_vf_mac_addr_mac,
13655                 (void *)&cmd_set_vf_mac_addr_addr,
13656                 (void *)&cmd_set_vf_mac_addr_port_id,
13657                 (void *)&cmd_set_vf_mac_addr_vf_id,
13658                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13659                 NULL,
13660         },
13661 };
13662
13663 /* MACsec configuration */
13664
13665 /* Common result structure for MACsec offload enable */
13666 struct cmd_macsec_offload_on_result {
13667         cmdline_fixed_string_t set;
13668         cmdline_fixed_string_t macsec;
13669         cmdline_fixed_string_t offload;
13670         portid_t port_id;
13671         cmdline_fixed_string_t on;
13672         cmdline_fixed_string_t encrypt;
13673         cmdline_fixed_string_t en_on_off;
13674         cmdline_fixed_string_t replay_protect;
13675         cmdline_fixed_string_t rp_on_off;
13676 };
13677
13678 /* Common CLI fields for MACsec offload disable */
13679 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13680         TOKEN_STRING_INITIALIZER
13681                 (struct cmd_macsec_offload_on_result,
13682                  set, "set");
13683 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13684         TOKEN_STRING_INITIALIZER
13685                 (struct cmd_macsec_offload_on_result,
13686                  macsec, "macsec");
13687 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13688         TOKEN_STRING_INITIALIZER
13689                 (struct cmd_macsec_offload_on_result,
13690                  offload, "offload");
13691 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13692         TOKEN_NUM_INITIALIZER
13693                 (struct cmd_macsec_offload_on_result,
13694                  port_id, UINT16);
13695 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13696         TOKEN_STRING_INITIALIZER
13697                 (struct cmd_macsec_offload_on_result,
13698                  on, "on");
13699 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13700         TOKEN_STRING_INITIALIZER
13701                 (struct cmd_macsec_offload_on_result,
13702                  encrypt, "encrypt");
13703 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_macsec_offload_on_result,
13706                  en_on_off, "on#off");
13707 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_macsec_offload_on_result,
13710                  replay_protect, "replay-protect");
13711 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13712         TOKEN_STRING_INITIALIZER
13713                 (struct cmd_macsec_offload_on_result,
13714                  rp_on_off, "on#off");
13715
13716 static void
13717 cmd_set_macsec_offload_on_parsed(
13718         void *parsed_result,
13719         __attribute__((unused)) struct cmdline *cl,
13720         __attribute__((unused)) void *data)
13721 {
13722         struct cmd_macsec_offload_on_result *res = parsed_result;
13723         int ret = -ENOTSUP;
13724         portid_t port_id = res->port_id;
13725         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13726         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13727         struct rte_eth_dev_info dev_info;
13728
13729         if (port_id_is_invalid(port_id, ENABLED_WARN))
13730                 return;
13731         if (!port_is_stopped(port_id)) {
13732                 printf("Please stop port %d first\n", port_id);
13733                 return;
13734         }
13735
13736         rte_eth_dev_info_get(port_id, &dev_info);
13737         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13738 #ifdef RTE_LIBRTE_IXGBE_PMD
13739                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13740 #endif
13741         }
13742         RTE_SET_USED(en);
13743         RTE_SET_USED(rp);
13744
13745         switch (ret) {
13746         case 0:
13747                 ports[port_id].dev_conf.txmode.offloads |=
13748                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13749                 cmd_reconfig_device_queue(port_id, 1, 1);
13750                 break;
13751         case -ENODEV:
13752                 printf("invalid port_id %d\n", port_id);
13753                 break;
13754         case -ENOTSUP:
13755                 printf("not supported on port %d\n", port_id);
13756                 break;
13757         default:
13758                 printf("programming error: (%s)\n", strerror(-ret));
13759         }
13760 }
13761
13762 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13763         .f = cmd_set_macsec_offload_on_parsed,
13764         .data = NULL,
13765         .help_str = "set macsec offload <port_id> on "
13766                 "encrypt on|off replay-protect on|off",
13767         .tokens = {
13768                 (void *)&cmd_macsec_offload_on_set,
13769                 (void *)&cmd_macsec_offload_on_macsec,
13770                 (void *)&cmd_macsec_offload_on_offload,
13771                 (void *)&cmd_macsec_offload_on_port_id,
13772                 (void *)&cmd_macsec_offload_on_on,
13773                 (void *)&cmd_macsec_offload_on_encrypt,
13774                 (void *)&cmd_macsec_offload_on_en_on_off,
13775                 (void *)&cmd_macsec_offload_on_replay_protect,
13776                 (void *)&cmd_macsec_offload_on_rp_on_off,
13777                 NULL,
13778         },
13779 };
13780
13781 /* Common result structure for MACsec offload disable */
13782 struct cmd_macsec_offload_off_result {
13783         cmdline_fixed_string_t set;
13784         cmdline_fixed_string_t macsec;
13785         cmdline_fixed_string_t offload;
13786         portid_t port_id;
13787         cmdline_fixed_string_t off;
13788 };
13789
13790 /* Common CLI fields for MACsec offload disable */
13791 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13792         TOKEN_STRING_INITIALIZER
13793                 (struct cmd_macsec_offload_off_result,
13794                  set, "set");
13795 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_macsec_offload_off_result,
13798                  macsec, "macsec");
13799 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13800         TOKEN_STRING_INITIALIZER
13801                 (struct cmd_macsec_offload_off_result,
13802                  offload, "offload");
13803 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13804         TOKEN_NUM_INITIALIZER
13805                 (struct cmd_macsec_offload_off_result,
13806                  port_id, UINT16);
13807 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13808         TOKEN_STRING_INITIALIZER
13809                 (struct cmd_macsec_offload_off_result,
13810                  off, "off");
13811
13812 static void
13813 cmd_set_macsec_offload_off_parsed(
13814         void *parsed_result,
13815         __attribute__((unused)) struct cmdline *cl,
13816         __attribute__((unused)) void *data)
13817 {
13818         struct cmd_macsec_offload_off_result *res = parsed_result;
13819         int ret = -ENOTSUP;
13820         struct rte_eth_dev_info dev_info;
13821         portid_t port_id = res->port_id;
13822
13823         if (port_id_is_invalid(port_id, ENABLED_WARN))
13824                 return;
13825         if (!port_is_stopped(port_id)) {
13826                 printf("Please stop port %d first\n", port_id);
13827                 return;
13828         }
13829
13830         rte_eth_dev_info_get(port_id, &dev_info);
13831         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13832 #ifdef RTE_LIBRTE_IXGBE_PMD
13833                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13834 #endif
13835         }
13836         switch (ret) {
13837         case 0:
13838                 ports[port_id].dev_conf.txmode.offloads &=
13839                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13840                 cmd_reconfig_device_queue(port_id, 1, 1);
13841                 break;
13842         case -ENODEV:
13843                 printf("invalid port_id %d\n", port_id);
13844                 break;
13845         case -ENOTSUP:
13846                 printf("not supported on port %d\n", port_id);
13847                 break;
13848         default:
13849                 printf("programming error: (%s)\n", strerror(-ret));
13850         }
13851 }
13852
13853 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13854         .f = cmd_set_macsec_offload_off_parsed,
13855         .data = NULL,
13856         .help_str = "set macsec offload <port_id> off",
13857         .tokens = {
13858                 (void *)&cmd_macsec_offload_off_set,
13859                 (void *)&cmd_macsec_offload_off_macsec,
13860                 (void *)&cmd_macsec_offload_off_offload,
13861                 (void *)&cmd_macsec_offload_off_port_id,
13862                 (void *)&cmd_macsec_offload_off_off,
13863                 NULL,
13864         },
13865 };
13866
13867 /* Common result structure for MACsec secure connection configure */
13868 struct cmd_macsec_sc_result {
13869         cmdline_fixed_string_t set;
13870         cmdline_fixed_string_t macsec;
13871         cmdline_fixed_string_t sc;
13872         cmdline_fixed_string_t tx_rx;
13873         portid_t port_id;
13874         struct ether_addr mac;
13875         uint16_t pi;
13876 };
13877
13878 /* Common CLI fields for MACsec secure connection configure */
13879 cmdline_parse_token_string_t cmd_macsec_sc_set =
13880         TOKEN_STRING_INITIALIZER
13881                 (struct cmd_macsec_sc_result,
13882                  set, "set");
13883 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13884         TOKEN_STRING_INITIALIZER
13885                 (struct cmd_macsec_sc_result,
13886                  macsec, "macsec");
13887 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13888         TOKEN_STRING_INITIALIZER
13889                 (struct cmd_macsec_sc_result,
13890                  sc, "sc");
13891 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13892         TOKEN_STRING_INITIALIZER
13893                 (struct cmd_macsec_sc_result,
13894                  tx_rx, "tx#rx");
13895 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13896         TOKEN_NUM_INITIALIZER
13897                 (struct cmd_macsec_sc_result,
13898                  port_id, UINT16);
13899 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13900         TOKEN_ETHERADDR_INITIALIZER
13901                 (struct cmd_macsec_sc_result,
13902                  mac);
13903 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13904         TOKEN_NUM_INITIALIZER
13905                 (struct cmd_macsec_sc_result,
13906                  pi, UINT16);
13907
13908 static void
13909 cmd_set_macsec_sc_parsed(
13910         void *parsed_result,
13911         __attribute__((unused)) struct cmdline *cl,
13912         __attribute__((unused)) void *data)
13913 {
13914         struct cmd_macsec_sc_result *res = parsed_result;
13915         int ret = -ENOTSUP;
13916         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13917
13918 #ifdef RTE_LIBRTE_IXGBE_PMD
13919         ret = is_tx ?
13920                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13921                                 res->mac.addr_bytes) :
13922                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13923                                 res->mac.addr_bytes, res->pi);
13924 #endif
13925         RTE_SET_USED(is_tx);
13926
13927         switch (ret) {
13928         case 0:
13929                 break;
13930         case -ENODEV:
13931                 printf("invalid port_id %d\n", res->port_id);
13932                 break;
13933         case -ENOTSUP:
13934                 printf("not supported on port %d\n", res->port_id);
13935                 break;
13936         default:
13937                 printf("programming error: (%s)\n", strerror(-ret));
13938         }
13939 }
13940
13941 cmdline_parse_inst_t cmd_set_macsec_sc = {
13942         .f = cmd_set_macsec_sc_parsed,
13943         .data = NULL,
13944         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13945         .tokens = {
13946                 (void *)&cmd_macsec_sc_set,
13947                 (void *)&cmd_macsec_sc_macsec,
13948                 (void *)&cmd_macsec_sc_sc,
13949                 (void *)&cmd_macsec_sc_tx_rx,
13950                 (void *)&cmd_macsec_sc_port_id,
13951                 (void *)&cmd_macsec_sc_mac,
13952                 (void *)&cmd_macsec_sc_pi,
13953                 NULL,
13954         },
13955 };
13956
13957 /* Common result structure for MACsec secure connection configure */
13958 struct cmd_macsec_sa_result {
13959         cmdline_fixed_string_t set;
13960         cmdline_fixed_string_t macsec;
13961         cmdline_fixed_string_t sa;
13962         cmdline_fixed_string_t tx_rx;
13963         portid_t port_id;
13964         uint8_t idx;
13965         uint8_t an;
13966         uint32_t pn;
13967         cmdline_fixed_string_t key;
13968 };
13969
13970 /* Common CLI fields for MACsec secure connection configure */
13971 cmdline_parse_token_string_t cmd_macsec_sa_set =
13972         TOKEN_STRING_INITIALIZER
13973                 (struct cmd_macsec_sa_result,
13974                  set, "set");
13975 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13976         TOKEN_STRING_INITIALIZER
13977                 (struct cmd_macsec_sa_result,
13978                  macsec, "macsec");
13979 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13980         TOKEN_STRING_INITIALIZER
13981                 (struct cmd_macsec_sa_result,
13982                  sa, "sa");
13983 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13984         TOKEN_STRING_INITIALIZER
13985                 (struct cmd_macsec_sa_result,
13986                  tx_rx, "tx#rx");
13987 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13988         TOKEN_NUM_INITIALIZER
13989                 (struct cmd_macsec_sa_result,
13990                  port_id, UINT16);
13991 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13992         TOKEN_NUM_INITIALIZER
13993                 (struct cmd_macsec_sa_result,
13994                  idx, UINT8);
13995 cmdline_parse_token_num_t cmd_macsec_sa_an =
13996         TOKEN_NUM_INITIALIZER
13997                 (struct cmd_macsec_sa_result,
13998                  an, UINT8);
13999 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14000         TOKEN_NUM_INITIALIZER
14001                 (struct cmd_macsec_sa_result,
14002                  pn, UINT32);
14003 cmdline_parse_token_string_t cmd_macsec_sa_key =
14004         TOKEN_STRING_INITIALIZER
14005                 (struct cmd_macsec_sa_result,
14006                  key, NULL);
14007
14008 static void
14009 cmd_set_macsec_sa_parsed(
14010         void *parsed_result,
14011         __attribute__((unused)) struct cmdline *cl,
14012         __attribute__((unused)) void *data)
14013 {
14014         struct cmd_macsec_sa_result *res = parsed_result;
14015         int ret = -ENOTSUP;
14016         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14017         uint8_t key[16] = { 0 };
14018         uint8_t xdgt0;
14019         uint8_t xdgt1;
14020         int key_len;
14021         int i;
14022
14023         key_len = strlen(res->key) / 2;
14024         if (key_len > 16)
14025                 key_len = 16;
14026
14027         for (i = 0; i < key_len; i++) {
14028                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14029                 if (xdgt0 == 0xFF)
14030                         return;
14031                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14032                 if (xdgt1 == 0xFF)
14033                         return;
14034                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14035         }
14036
14037 #ifdef RTE_LIBRTE_IXGBE_PMD
14038         ret = is_tx ?
14039                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14040                         res->idx, res->an, res->pn, key) :
14041                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14042                         res->idx, res->an, res->pn, key);
14043 #endif
14044         RTE_SET_USED(is_tx);
14045         RTE_SET_USED(key);
14046
14047         switch (ret) {
14048         case 0:
14049                 break;
14050         case -EINVAL:
14051                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14052                 break;
14053         case -ENODEV:
14054                 printf("invalid port_id %d\n", res->port_id);
14055                 break;
14056         case -ENOTSUP:
14057                 printf("not supported on port %d\n", res->port_id);
14058                 break;
14059         default:
14060                 printf("programming error: (%s)\n", strerror(-ret));
14061         }
14062 }
14063
14064 cmdline_parse_inst_t cmd_set_macsec_sa = {
14065         .f = cmd_set_macsec_sa_parsed,
14066         .data = NULL,
14067         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14068         .tokens = {
14069                 (void *)&cmd_macsec_sa_set,
14070                 (void *)&cmd_macsec_sa_macsec,
14071                 (void *)&cmd_macsec_sa_sa,
14072                 (void *)&cmd_macsec_sa_tx_rx,
14073                 (void *)&cmd_macsec_sa_port_id,
14074                 (void *)&cmd_macsec_sa_idx,
14075                 (void *)&cmd_macsec_sa_an,
14076                 (void *)&cmd_macsec_sa_pn,
14077                 (void *)&cmd_macsec_sa_key,
14078                 NULL,
14079         },
14080 };
14081
14082 /* VF unicast promiscuous mode configuration */
14083
14084 /* Common result structure for VF unicast promiscuous mode */
14085 struct cmd_vf_promisc_result {
14086         cmdline_fixed_string_t set;
14087         cmdline_fixed_string_t vf;
14088         cmdline_fixed_string_t promisc;
14089         portid_t port_id;
14090         uint32_t vf_id;
14091         cmdline_fixed_string_t on_off;
14092 };
14093
14094 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14095 cmdline_parse_token_string_t cmd_vf_promisc_set =
14096         TOKEN_STRING_INITIALIZER
14097                 (struct cmd_vf_promisc_result,
14098                  set, "set");
14099 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14100         TOKEN_STRING_INITIALIZER
14101                 (struct cmd_vf_promisc_result,
14102                  vf, "vf");
14103 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14104         TOKEN_STRING_INITIALIZER
14105                 (struct cmd_vf_promisc_result,
14106                  promisc, "promisc");
14107 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14108         TOKEN_NUM_INITIALIZER
14109                 (struct cmd_vf_promisc_result,
14110                  port_id, UINT16);
14111 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14112         TOKEN_NUM_INITIALIZER
14113                 (struct cmd_vf_promisc_result,
14114                  vf_id, UINT32);
14115 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14116         TOKEN_STRING_INITIALIZER
14117                 (struct cmd_vf_promisc_result,
14118                  on_off, "on#off");
14119
14120 static void
14121 cmd_set_vf_promisc_parsed(
14122         void *parsed_result,
14123         __attribute__((unused)) struct cmdline *cl,
14124         __attribute__((unused)) void *data)
14125 {
14126         struct cmd_vf_promisc_result *res = parsed_result;
14127         int ret = -ENOTSUP;
14128
14129         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14130
14131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14132                 return;
14133
14134 #ifdef RTE_LIBRTE_I40E_PMD
14135         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14136                                                   res->vf_id, is_on);
14137 #endif
14138
14139         switch (ret) {
14140         case 0:
14141                 break;
14142         case -EINVAL:
14143                 printf("invalid vf_id %d\n", res->vf_id);
14144                 break;
14145         case -ENODEV:
14146                 printf("invalid port_id %d\n", res->port_id);
14147                 break;
14148         case -ENOTSUP:
14149                 printf("function not implemented\n");
14150                 break;
14151         default:
14152                 printf("programming error: (%s)\n", strerror(-ret));
14153         }
14154 }
14155
14156 cmdline_parse_inst_t cmd_set_vf_promisc = {
14157         .f = cmd_set_vf_promisc_parsed,
14158         .data = NULL,
14159         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14160                 "Set unicast promiscuous mode for a VF from the PF",
14161         .tokens = {
14162                 (void *)&cmd_vf_promisc_set,
14163                 (void *)&cmd_vf_promisc_vf,
14164                 (void *)&cmd_vf_promisc_promisc,
14165                 (void *)&cmd_vf_promisc_port_id,
14166                 (void *)&cmd_vf_promisc_vf_id,
14167                 (void *)&cmd_vf_promisc_on_off,
14168                 NULL,
14169         },
14170 };
14171
14172 /* VF multicast promiscuous mode configuration */
14173
14174 /* Common result structure for VF multicast promiscuous mode */
14175 struct cmd_vf_allmulti_result {
14176         cmdline_fixed_string_t set;
14177         cmdline_fixed_string_t vf;
14178         cmdline_fixed_string_t allmulti;
14179         portid_t port_id;
14180         uint32_t vf_id;
14181         cmdline_fixed_string_t on_off;
14182 };
14183
14184 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14185 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14186         TOKEN_STRING_INITIALIZER
14187                 (struct cmd_vf_allmulti_result,
14188                  set, "set");
14189 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14190         TOKEN_STRING_INITIALIZER
14191                 (struct cmd_vf_allmulti_result,
14192                  vf, "vf");
14193 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14194         TOKEN_STRING_INITIALIZER
14195                 (struct cmd_vf_allmulti_result,
14196                  allmulti, "allmulti");
14197 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14198         TOKEN_NUM_INITIALIZER
14199                 (struct cmd_vf_allmulti_result,
14200                  port_id, UINT16);
14201 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14202         TOKEN_NUM_INITIALIZER
14203                 (struct cmd_vf_allmulti_result,
14204                  vf_id, UINT32);
14205 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14206         TOKEN_STRING_INITIALIZER
14207                 (struct cmd_vf_allmulti_result,
14208                  on_off, "on#off");
14209
14210 static void
14211 cmd_set_vf_allmulti_parsed(
14212         void *parsed_result,
14213         __attribute__((unused)) struct cmdline *cl,
14214         __attribute__((unused)) void *data)
14215 {
14216         struct cmd_vf_allmulti_result *res = parsed_result;
14217         int ret = -ENOTSUP;
14218
14219         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14220
14221         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14222                 return;
14223
14224 #ifdef RTE_LIBRTE_I40E_PMD
14225         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14226                                                     res->vf_id, is_on);
14227 #endif
14228
14229         switch (ret) {
14230         case 0:
14231                 break;
14232         case -EINVAL:
14233                 printf("invalid vf_id %d\n", res->vf_id);
14234                 break;
14235         case -ENODEV:
14236                 printf("invalid port_id %d\n", res->port_id);
14237                 break;
14238         case -ENOTSUP:
14239                 printf("function not implemented\n");
14240                 break;
14241         default:
14242                 printf("programming error: (%s)\n", strerror(-ret));
14243         }
14244 }
14245
14246 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14247         .f = cmd_set_vf_allmulti_parsed,
14248         .data = NULL,
14249         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14250                 "Set multicast promiscuous mode for a VF from the PF",
14251         .tokens = {
14252                 (void *)&cmd_vf_allmulti_set,
14253                 (void *)&cmd_vf_allmulti_vf,
14254                 (void *)&cmd_vf_allmulti_allmulti,
14255                 (void *)&cmd_vf_allmulti_port_id,
14256                 (void *)&cmd_vf_allmulti_vf_id,
14257                 (void *)&cmd_vf_allmulti_on_off,
14258                 NULL,
14259         },
14260 };
14261
14262 /* vf broadcast mode configuration */
14263
14264 /* Common result structure for vf broadcast */
14265 struct cmd_set_vf_broadcast_result {
14266         cmdline_fixed_string_t set;
14267         cmdline_fixed_string_t vf;
14268         cmdline_fixed_string_t broadcast;
14269         portid_t port_id;
14270         uint16_t vf_id;
14271         cmdline_fixed_string_t on_off;
14272 };
14273
14274 /* Common CLI fields for vf broadcast enable disable */
14275 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_set_vf_broadcast_result,
14278                  set, "set");
14279 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_set_vf_broadcast_result,
14282                  vf, "vf");
14283 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14284         TOKEN_STRING_INITIALIZER
14285                 (struct cmd_set_vf_broadcast_result,
14286                  broadcast, "broadcast");
14287 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14288         TOKEN_NUM_INITIALIZER
14289                 (struct cmd_set_vf_broadcast_result,
14290                  port_id, UINT16);
14291 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14292         TOKEN_NUM_INITIALIZER
14293                 (struct cmd_set_vf_broadcast_result,
14294                  vf_id, UINT16);
14295 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_set_vf_broadcast_result,
14298                  on_off, "on#off");
14299
14300 static void
14301 cmd_set_vf_broadcast_parsed(
14302         void *parsed_result,
14303         __attribute__((unused)) struct cmdline *cl,
14304         __attribute__((unused)) void *data)
14305 {
14306         struct cmd_set_vf_broadcast_result *res = parsed_result;
14307         int ret = -ENOTSUP;
14308
14309         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14310
14311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14312                 return;
14313
14314 #ifdef RTE_LIBRTE_I40E_PMD
14315         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14316                                             res->vf_id, is_on);
14317 #endif
14318
14319         switch (ret) {
14320         case 0:
14321                 break;
14322         case -EINVAL:
14323                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14324                 break;
14325         case -ENODEV:
14326                 printf("invalid port_id %d\n", res->port_id);
14327                 break;
14328         case -ENOTSUP:
14329                 printf("function not implemented\n");
14330                 break;
14331         default:
14332                 printf("programming error: (%s)\n", strerror(-ret));
14333         }
14334 }
14335
14336 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14337         .f = cmd_set_vf_broadcast_parsed,
14338         .data = NULL,
14339         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14340         .tokens = {
14341                 (void *)&cmd_set_vf_broadcast_set,
14342                 (void *)&cmd_set_vf_broadcast_vf,
14343                 (void *)&cmd_set_vf_broadcast_broadcast,
14344                 (void *)&cmd_set_vf_broadcast_port_id,
14345                 (void *)&cmd_set_vf_broadcast_vf_id,
14346                 (void *)&cmd_set_vf_broadcast_on_off,
14347                 NULL,
14348         },
14349 };
14350
14351 /* vf vlan tag configuration */
14352
14353 /* Common result structure for vf vlan tag */
14354 struct cmd_set_vf_vlan_tag_result {
14355         cmdline_fixed_string_t set;
14356         cmdline_fixed_string_t vf;
14357         cmdline_fixed_string_t vlan;
14358         cmdline_fixed_string_t tag;
14359         portid_t port_id;
14360         uint16_t vf_id;
14361         cmdline_fixed_string_t on_off;
14362 };
14363
14364 /* Common CLI fields for vf vlan tag enable disable */
14365 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14366         TOKEN_STRING_INITIALIZER
14367                 (struct cmd_set_vf_vlan_tag_result,
14368                  set, "set");
14369 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_set_vf_vlan_tag_result,
14372                  vf, "vf");
14373 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_set_vf_vlan_tag_result,
14376                  vlan, "vlan");
14377 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14378         TOKEN_STRING_INITIALIZER
14379                 (struct cmd_set_vf_vlan_tag_result,
14380                  tag, "tag");
14381 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14382         TOKEN_NUM_INITIALIZER
14383                 (struct cmd_set_vf_vlan_tag_result,
14384                  port_id, UINT16);
14385 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14386         TOKEN_NUM_INITIALIZER
14387                 (struct cmd_set_vf_vlan_tag_result,
14388                  vf_id, UINT16);
14389 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14390         TOKEN_STRING_INITIALIZER
14391                 (struct cmd_set_vf_vlan_tag_result,
14392                  on_off, "on#off");
14393
14394 static void
14395 cmd_set_vf_vlan_tag_parsed(
14396         void *parsed_result,
14397         __attribute__((unused)) struct cmdline *cl,
14398         __attribute__((unused)) void *data)
14399 {
14400         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14401         int ret = -ENOTSUP;
14402
14403         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14404
14405         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14406                 return;
14407
14408 #ifdef RTE_LIBRTE_I40E_PMD
14409         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14410                                            res->vf_id, is_on);
14411 #endif
14412
14413         switch (ret) {
14414         case 0:
14415                 break;
14416         case -EINVAL:
14417                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14418                 break;
14419         case -ENODEV:
14420                 printf("invalid port_id %d\n", res->port_id);
14421                 break;
14422         case -ENOTSUP:
14423                 printf("function not implemented\n");
14424                 break;
14425         default:
14426                 printf("programming error: (%s)\n", strerror(-ret));
14427         }
14428 }
14429
14430 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14431         .f = cmd_set_vf_vlan_tag_parsed,
14432         .data = NULL,
14433         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14434         .tokens = {
14435                 (void *)&cmd_set_vf_vlan_tag_set,
14436                 (void *)&cmd_set_vf_vlan_tag_vf,
14437                 (void *)&cmd_set_vf_vlan_tag_vlan,
14438                 (void *)&cmd_set_vf_vlan_tag_tag,
14439                 (void *)&cmd_set_vf_vlan_tag_port_id,
14440                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14441                 (void *)&cmd_set_vf_vlan_tag_on_off,
14442                 NULL,
14443         },
14444 };
14445
14446 /* Common definition of VF and TC TX bandwidth configuration */
14447 struct cmd_vf_tc_bw_result {
14448         cmdline_fixed_string_t set;
14449         cmdline_fixed_string_t vf;
14450         cmdline_fixed_string_t tc;
14451         cmdline_fixed_string_t tx;
14452         cmdline_fixed_string_t min_bw;
14453         cmdline_fixed_string_t max_bw;
14454         cmdline_fixed_string_t strict_link_prio;
14455         portid_t port_id;
14456         uint16_t vf_id;
14457         uint8_t tc_no;
14458         uint32_t bw;
14459         cmdline_fixed_string_t bw_list;
14460         uint8_t tc_map;
14461 };
14462
14463 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14464         TOKEN_STRING_INITIALIZER
14465                 (struct cmd_vf_tc_bw_result,
14466                  set, "set");
14467 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14468         TOKEN_STRING_INITIALIZER
14469                 (struct cmd_vf_tc_bw_result,
14470                  vf, "vf");
14471 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14472         TOKEN_STRING_INITIALIZER
14473                 (struct cmd_vf_tc_bw_result,
14474                  tc, "tc");
14475 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14476         TOKEN_STRING_INITIALIZER
14477                 (struct cmd_vf_tc_bw_result,
14478                  tx, "tx");
14479 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14480         TOKEN_STRING_INITIALIZER
14481                 (struct cmd_vf_tc_bw_result,
14482                  strict_link_prio, "strict-link-priority");
14483 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14484         TOKEN_STRING_INITIALIZER
14485                 (struct cmd_vf_tc_bw_result,
14486                  min_bw, "min-bandwidth");
14487 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14488         TOKEN_STRING_INITIALIZER
14489                 (struct cmd_vf_tc_bw_result,
14490                  max_bw, "max-bandwidth");
14491 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14492         TOKEN_NUM_INITIALIZER
14493                 (struct cmd_vf_tc_bw_result,
14494                  port_id, UINT16);
14495 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14496         TOKEN_NUM_INITIALIZER
14497                 (struct cmd_vf_tc_bw_result,
14498                  vf_id, UINT16);
14499 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14500         TOKEN_NUM_INITIALIZER
14501                 (struct cmd_vf_tc_bw_result,
14502                  tc_no, UINT8);
14503 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14504         TOKEN_NUM_INITIALIZER
14505                 (struct cmd_vf_tc_bw_result,
14506                  bw, UINT32);
14507 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14508         TOKEN_STRING_INITIALIZER
14509                 (struct cmd_vf_tc_bw_result,
14510                  bw_list, NULL);
14511 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14512         TOKEN_NUM_INITIALIZER
14513                 (struct cmd_vf_tc_bw_result,
14514                  tc_map, UINT8);
14515
14516 /* VF max bandwidth setting */
14517 static void
14518 cmd_vf_max_bw_parsed(
14519         void *parsed_result,
14520         __attribute__((unused)) struct cmdline *cl,
14521         __attribute__((unused)) void *data)
14522 {
14523         struct cmd_vf_tc_bw_result *res = parsed_result;
14524         int ret = -ENOTSUP;
14525
14526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14527                 return;
14528
14529 #ifdef RTE_LIBRTE_I40E_PMD
14530         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14531                                          res->vf_id, res->bw);
14532 #endif
14533
14534         switch (ret) {
14535         case 0:
14536                 break;
14537         case -EINVAL:
14538                 printf("invalid vf_id %d or bandwidth %d\n",
14539                        res->vf_id, res->bw);
14540                 break;
14541         case -ENODEV:
14542                 printf("invalid port_id %d\n", res->port_id);
14543                 break;
14544         case -ENOTSUP:
14545                 printf("function not implemented\n");
14546                 break;
14547         default:
14548                 printf("programming error: (%s)\n", strerror(-ret));
14549         }
14550 }
14551
14552 cmdline_parse_inst_t cmd_vf_max_bw = {
14553         .f = cmd_vf_max_bw_parsed,
14554         .data = NULL,
14555         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14556         .tokens = {
14557                 (void *)&cmd_vf_tc_bw_set,
14558                 (void *)&cmd_vf_tc_bw_vf,
14559                 (void *)&cmd_vf_tc_bw_tx,
14560                 (void *)&cmd_vf_tc_bw_max_bw,
14561                 (void *)&cmd_vf_tc_bw_port_id,
14562                 (void *)&cmd_vf_tc_bw_vf_id,
14563                 (void *)&cmd_vf_tc_bw_bw,
14564                 NULL,
14565         },
14566 };
14567
14568 static int
14569 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14570                            uint8_t *tc_num,
14571                            char *str)
14572 {
14573         uint32_t size;
14574         const char *p, *p0 = str;
14575         char s[256];
14576         char *end;
14577         char *str_fld[16];
14578         uint16_t i;
14579         int ret;
14580
14581         p = strchr(p0, '(');
14582         if (p == NULL) {
14583                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14584                 return -1;
14585         }
14586         p++;
14587         p0 = strchr(p, ')');
14588         if (p0 == NULL) {
14589                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14590                 return -1;
14591         }
14592         size = p0 - p;
14593         if (size >= sizeof(s)) {
14594                 printf("The string size exceeds the internal buffer size\n");
14595                 return -1;
14596         }
14597         snprintf(s, sizeof(s), "%.*s", size, p);
14598         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14599         if (ret <= 0) {
14600                 printf("Failed to get the bandwidth list. ");
14601                 return -1;
14602         }
14603         *tc_num = ret;
14604         for (i = 0; i < ret; i++)
14605                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14606
14607         return 0;
14608 }
14609
14610 /* TC min bandwidth setting */
14611 static void
14612 cmd_vf_tc_min_bw_parsed(
14613         void *parsed_result,
14614         __attribute__((unused)) struct cmdline *cl,
14615         __attribute__((unused)) void *data)
14616 {
14617         struct cmd_vf_tc_bw_result *res = parsed_result;
14618         uint8_t tc_num;
14619         uint8_t bw[16];
14620         int ret = -ENOTSUP;
14621
14622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14623                 return;
14624
14625         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14626         if (ret)
14627                 return;
14628
14629 #ifdef RTE_LIBRTE_I40E_PMD
14630         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14631                                               tc_num, bw);
14632 #endif
14633
14634         switch (ret) {
14635         case 0:
14636                 break;
14637         case -EINVAL:
14638                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14639                 break;
14640         case -ENODEV:
14641                 printf("invalid port_id %d\n", res->port_id);
14642                 break;
14643         case -ENOTSUP:
14644                 printf("function not implemented\n");
14645                 break;
14646         default:
14647                 printf("programming error: (%s)\n", strerror(-ret));
14648         }
14649 }
14650
14651 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14652         .f = cmd_vf_tc_min_bw_parsed,
14653         .data = NULL,
14654         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14655                     " <bw1, bw2, ...>",
14656         .tokens = {
14657                 (void *)&cmd_vf_tc_bw_set,
14658                 (void *)&cmd_vf_tc_bw_vf,
14659                 (void *)&cmd_vf_tc_bw_tc,
14660                 (void *)&cmd_vf_tc_bw_tx,
14661                 (void *)&cmd_vf_tc_bw_min_bw,
14662                 (void *)&cmd_vf_tc_bw_port_id,
14663                 (void *)&cmd_vf_tc_bw_vf_id,
14664                 (void *)&cmd_vf_tc_bw_bw_list,
14665                 NULL,
14666         },
14667 };
14668
14669 static void
14670 cmd_tc_min_bw_parsed(
14671         void *parsed_result,
14672         __attribute__((unused)) struct cmdline *cl,
14673         __attribute__((unused)) void *data)
14674 {
14675         struct cmd_vf_tc_bw_result *res = parsed_result;
14676         struct rte_port *port;
14677         uint8_t tc_num;
14678         uint8_t bw[16];
14679         int ret = -ENOTSUP;
14680
14681         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14682                 return;
14683
14684         port = &ports[res->port_id];
14685         /** Check if the port is not started **/
14686         if (port->port_status != RTE_PORT_STOPPED) {
14687                 printf("Please stop port %d first\n", res->port_id);
14688                 return;
14689         }
14690
14691         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14692         if (ret)
14693                 return;
14694
14695 #ifdef RTE_LIBRTE_IXGBE_PMD
14696         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14697 #endif
14698
14699         switch (ret) {
14700         case 0:
14701                 break;
14702         case -EINVAL:
14703                 printf("invalid bandwidth\n");
14704                 break;
14705         case -ENODEV:
14706                 printf("invalid port_id %d\n", res->port_id);
14707                 break;
14708         case -ENOTSUP:
14709                 printf("function not implemented\n");
14710                 break;
14711         default:
14712                 printf("programming error: (%s)\n", strerror(-ret));
14713         }
14714 }
14715
14716 cmdline_parse_inst_t cmd_tc_min_bw = {
14717         .f = cmd_tc_min_bw_parsed,
14718         .data = NULL,
14719         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14720         .tokens = {
14721                 (void *)&cmd_vf_tc_bw_set,
14722                 (void *)&cmd_vf_tc_bw_tc,
14723                 (void *)&cmd_vf_tc_bw_tx,
14724                 (void *)&cmd_vf_tc_bw_min_bw,
14725                 (void *)&cmd_vf_tc_bw_port_id,
14726                 (void *)&cmd_vf_tc_bw_bw_list,
14727                 NULL,
14728         },
14729 };
14730
14731 /* TC max bandwidth setting */
14732 static void
14733 cmd_vf_tc_max_bw_parsed(
14734         void *parsed_result,
14735         __attribute__((unused)) struct cmdline *cl,
14736         __attribute__((unused)) void *data)
14737 {
14738         struct cmd_vf_tc_bw_result *res = parsed_result;
14739         int ret = -ENOTSUP;
14740
14741         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14742                 return;
14743
14744 #ifdef RTE_LIBRTE_I40E_PMD
14745         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14746                                             res->tc_no, res->bw);
14747 #endif
14748
14749         switch (ret) {
14750         case 0:
14751                 break;
14752         case -EINVAL:
14753                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14754                        res->vf_id, res->tc_no, res->bw);
14755                 break;
14756         case -ENODEV:
14757                 printf("invalid port_id %d\n", res->port_id);
14758                 break;
14759         case -ENOTSUP:
14760                 printf("function not implemented\n");
14761                 break;
14762         default:
14763                 printf("programming error: (%s)\n", strerror(-ret));
14764         }
14765 }
14766
14767 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14768         .f = cmd_vf_tc_max_bw_parsed,
14769         .data = NULL,
14770         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14771                     " <bandwidth>",
14772         .tokens = {
14773                 (void *)&cmd_vf_tc_bw_set,
14774                 (void *)&cmd_vf_tc_bw_vf,
14775                 (void *)&cmd_vf_tc_bw_tc,
14776                 (void *)&cmd_vf_tc_bw_tx,
14777                 (void *)&cmd_vf_tc_bw_max_bw,
14778                 (void *)&cmd_vf_tc_bw_port_id,
14779                 (void *)&cmd_vf_tc_bw_vf_id,
14780                 (void *)&cmd_vf_tc_bw_tc_no,
14781                 (void *)&cmd_vf_tc_bw_bw,
14782                 NULL,
14783         },
14784 };
14785
14786
14787 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14788
14789 /* *** Set Port default Traffic Management Hierarchy *** */
14790 struct cmd_set_port_tm_hierarchy_default_result {
14791         cmdline_fixed_string_t set;
14792         cmdline_fixed_string_t port;
14793         cmdline_fixed_string_t tm;
14794         cmdline_fixed_string_t hierarchy;
14795         cmdline_fixed_string_t def;
14796         portid_t port_id;
14797 };
14798
14799 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14800         TOKEN_STRING_INITIALIZER(
14801                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14802 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14803         TOKEN_STRING_INITIALIZER(
14804                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14805 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14806         TOKEN_STRING_INITIALIZER(
14807                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14808 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14809         TOKEN_STRING_INITIALIZER(
14810                 struct cmd_set_port_tm_hierarchy_default_result,
14811                         hierarchy, "hierarchy");
14812 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14813         TOKEN_STRING_INITIALIZER(
14814                 struct cmd_set_port_tm_hierarchy_default_result,
14815                         def, "default");
14816 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14817         TOKEN_NUM_INITIALIZER(
14818                 struct cmd_set_port_tm_hierarchy_default_result,
14819                         port_id, UINT16);
14820
14821 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14822         __attribute__((unused)) struct cmdline *cl,
14823         __attribute__((unused)) void *data)
14824 {
14825         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14826         struct rte_port *p;
14827         portid_t port_id = res->port_id;
14828
14829         if (port_id_is_invalid(port_id, ENABLED_WARN))
14830                 return;
14831
14832         p = &ports[port_id];
14833
14834         /* Forward mode: tm */
14835         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
14836                 printf("  softnicfwd mode not enabled(error)\n");
14837                 return;
14838         }
14839
14840         /* Set the default tm hierarchy */
14841         p->softport.default_tm_hierarchy_enable = 1;
14842 }
14843
14844 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14845         .f = cmd_set_port_tm_hierarchy_default_parsed,
14846         .data = NULL,
14847         .help_str = "set port tm hierarchy default <port_id>",
14848         .tokens = {
14849                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14850                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14851                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14852                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14853                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14854                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14855                 NULL,
14856         },
14857 };
14858 #endif
14859
14860 /** Set VXLAN encapsulation details */
14861 struct cmd_set_vxlan_result {
14862         cmdline_fixed_string_t set;
14863         cmdline_fixed_string_t vxlan;
14864         cmdline_fixed_string_t pos_token;
14865         cmdline_fixed_string_t ip_version;
14866         uint32_t vlan_present:1;
14867         uint32_t vni;
14868         uint16_t udp_src;
14869         uint16_t udp_dst;
14870         cmdline_ipaddr_t ip_src;
14871         cmdline_ipaddr_t ip_dst;
14872         uint16_t tci;
14873         struct ether_addr eth_src;
14874         struct ether_addr eth_dst;
14875 };
14876
14877 cmdline_parse_token_string_t cmd_set_vxlan_set =
14878         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14879 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14880         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14881 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14882         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14883                                  "vxlan-with-vlan");
14884 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14885         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14886                                  "ip-version");
14887 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14888         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14889                                  "ipv4#ipv6");
14890 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14891         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14892                                  "vni");
14893 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14894         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14895 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14896         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14897                                  "udp-src");
14898 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14899         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14900 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14901         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14902                                  "udp-dst");
14903 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14904         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14905 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14906         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14907                                  "ip-src");
14908 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14909         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14910 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14911         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14912                                  "ip-dst");
14913 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14914         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14915 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14916         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14917                                  "vlan-tci");
14918 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14919         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14920 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14921         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14922                                  "eth-src");
14923 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14924         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14925 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14926         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14927                                  "eth-dst");
14928 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14929         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14930
14931 static void cmd_set_vxlan_parsed(void *parsed_result,
14932         __attribute__((unused)) struct cmdline *cl,
14933         __attribute__((unused)) void *data)
14934 {
14935         struct cmd_set_vxlan_result *res = parsed_result;
14936         union {
14937                 uint32_t vxlan_id;
14938                 uint8_t vni[4];
14939         } id = {
14940                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14941         };
14942
14943         if (strcmp(res->vxlan, "vxlan") == 0)
14944                 vxlan_encap_conf.select_vlan = 0;
14945         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14946                 vxlan_encap_conf.select_vlan = 1;
14947         if (strcmp(res->ip_version, "ipv4") == 0)
14948                 vxlan_encap_conf.select_ipv4 = 1;
14949         else if (strcmp(res->ip_version, "ipv6") == 0)
14950                 vxlan_encap_conf.select_ipv4 = 0;
14951         else
14952                 return;
14953         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14954         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14955         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14956         if (vxlan_encap_conf.select_ipv4) {
14957                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14958                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14959         } else {
14960                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14961                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14962         }
14963         if (vxlan_encap_conf.select_vlan)
14964                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14965         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14966                    ETHER_ADDR_LEN);
14967         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14968                    ETHER_ADDR_LEN);
14969 }
14970
14971 cmdline_parse_inst_t cmd_set_vxlan = {
14972         .f = cmd_set_vxlan_parsed,
14973         .data = NULL,
14974         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14975                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14976                 " eth-src <eth-src> eth-dst <eth-dst>",
14977         .tokens = {
14978                 (void *)&cmd_set_vxlan_set,
14979                 (void *)&cmd_set_vxlan_vxlan,
14980                 (void *)&cmd_set_vxlan_ip_version,
14981                 (void *)&cmd_set_vxlan_ip_version_value,
14982                 (void *)&cmd_set_vxlan_vni,
14983                 (void *)&cmd_set_vxlan_vni_value,
14984                 (void *)&cmd_set_vxlan_udp_src,
14985                 (void *)&cmd_set_vxlan_udp_src_value,
14986                 (void *)&cmd_set_vxlan_udp_dst,
14987                 (void *)&cmd_set_vxlan_udp_dst_value,
14988                 (void *)&cmd_set_vxlan_ip_src,
14989                 (void *)&cmd_set_vxlan_ip_src_value,
14990                 (void *)&cmd_set_vxlan_ip_dst,
14991                 (void *)&cmd_set_vxlan_ip_dst_value,
14992                 (void *)&cmd_set_vxlan_eth_src,
14993                 (void *)&cmd_set_vxlan_eth_src_value,
14994                 (void *)&cmd_set_vxlan_eth_dst,
14995                 (void *)&cmd_set_vxlan_eth_dst_value,
14996                 NULL,
14997         },
14998 };
14999
15000 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15001         .f = cmd_set_vxlan_parsed,
15002         .data = NULL,
15003         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15004                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15005                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15006                 " <eth-dst>",
15007         .tokens = {
15008                 (void *)&cmd_set_vxlan_set,
15009                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15010                 (void *)&cmd_set_vxlan_ip_version,
15011                 (void *)&cmd_set_vxlan_ip_version_value,
15012                 (void *)&cmd_set_vxlan_vni,
15013                 (void *)&cmd_set_vxlan_vni_value,
15014                 (void *)&cmd_set_vxlan_udp_src,
15015                 (void *)&cmd_set_vxlan_udp_src_value,
15016                 (void *)&cmd_set_vxlan_udp_dst,
15017                 (void *)&cmd_set_vxlan_udp_dst_value,
15018                 (void *)&cmd_set_vxlan_ip_src,
15019                 (void *)&cmd_set_vxlan_ip_src_value,
15020                 (void *)&cmd_set_vxlan_ip_dst,
15021                 (void *)&cmd_set_vxlan_ip_dst_value,
15022                 (void *)&cmd_set_vxlan_vlan,
15023                 (void *)&cmd_set_vxlan_vlan_value,
15024                 (void *)&cmd_set_vxlan_eth_src,
15025                 (void *)&cmd_set_vxlan_eth_src_value,
15026                 (void *)&cmd_set_vxlan_eth_dst,
15027                 (void *)&cmd_set_vxlan_eth_dst_value,
15028                 NULL,
15029         },
15030 };
15031
15032 /* Strict link priority scheduling mode setting */
15033 static void
15034 cmd_strict_link_prio_parsed(
15035         void *parsed_result,
15036         __attribute__((unused)) struct cmdline *cl,
15037         __attribute__((unused)) void *data)
15038 {
15039         struct cmd_vf_tc_bw_result *res = parsed_result;
15040         int ret = -ENOTSUP;
15041
15042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15043                 return;
15044
15045 #ifdef RTE_LIBRTE_I40E_PMD
15046         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15047 #endif
15048
15049         switch (ret) {
15050         case 0:
15051                 break;
15052         case -EINVAL:
15053                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15054                 break;
15055         case -ENODEV:
15056                 printf("invalid port_id %d\n", res->port_id);
15057                 break;
15058         case -ENOTSUP:
15059                 printf("function not implemented\n");
15060                 break;
15061         default:
15062                 printf("programming error: (%s)\n", strerror(-ret));
15063         }
15064 }
15065
15066 cmdline_parse_inst_t cmd_strict_link_prio = {
15067         .f = cmd_strict_link_prio_parsed,
15068         .data = NULL,
15069         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15070         .tokens = {
15071                 (void *)&cmd_vf_tc_bw_set,
15072                 (void *)&cmd_vf_tc_bw_tx,
15073                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15074                 (void *)&cmd_vf_tc_bw_port_id,
15075                 (void *)&cmd_vf_tc_bw_tc_map,
15076                 NULL,
15077         },
15078 };
15079
15080 /* Load dynamic device personalization*/
15081 struct cmd_ddp_add_result {
15082         cmdline_fixed_string_t ddp;
15083         cmdline_fixed_string_t add;
15084         portid_t port_id;
15085         char filepath[];
15086 };
15087
15088 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15089         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15090 cmdline_parse_token_string_t cmd_ddp_add_add =
15091         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15092 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15093         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15094 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15095         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15096
15097 static void
15098 cmd_ddp_add_parsed(
15099         void *parsed_result,
15100         __attribute__((unused)) struct cmdline *cl,
15101         __attribute__((unused)) void *data)
15102 {
15103         struct cmd_ddp_add_result *res = parsed_result;
15104         uint8_t *buff;
15105         uint32_t size;
15106         char *filepath;
15107         char *file_fld[2];
15108         int file_num;
15109         int ret = -ENOTSUP;
15110
15111         if (!all_ports_stopped()) {
15112                 printf("Please stop all ports first\n");
15113                 return;
15114         }
15115
15116         filepath = strdup(res->filepath);
15117         if (filepath == NULL) {
15118                 printf("Failed to allocate memory\n");
15119                 return;
15120         }
15121         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15122
15123         buff = open_file(file_fld[0], &size);
15124         if (!buff) {
15125                 free((void *)filepath);
15126                 return;
15127         }
15128
15129 #ifdef RTE_LIBRTE_I40E_PMD
15130         if (ret == -ENOTSUP)
15131                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15132                                                buff, size,
15133                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15134 #endif
15135
15136         if (ret == -EEXIST)
15137                 printf("Profile has already existed.\n");
15138         else if (ret < 0)
15139                 printf("Failed to load profile.\n");
15140         else if (file_num == 2)
15141                 save_file(file_fld[1], buff, size);
15142
15143         close_file(buff);
15144         free((void *)filepath);
15145 }
15146
15147 cmdline_parse_inst_t cmd_ddp_add = {
15148         .f = cmd_ddp_add_parsed,
15149         .data = NULL,
15150         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15151         .tokens = {
15152                 (void *)&cmd_ddp_add_ddp,
15153                 (void *)&cmd_ddp_add_add,
15154                 (void *)&cmd_ddp_add_port_id,
15155                 (void *)&cmd_ddp_add_filepath,
15156                 NULL,
15157         },
15158 };
15159
15160 /* Delete dynamic device personalization*/
15161 struct cmd_ddp_del_result {
15162         cmdline_fixed_string_t ddp;
15163         cmdline_fixed_string_t del;
15164         portid_t port_id;
15165         char filepath[];
15166 };
15167
15168 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15169         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15170 cmdline_parse_token_string_t cmd_ddp_del_del =
15171         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15172 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15173         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15174 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15175         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15176
15177 static void
15178 cmd_ddp_del_parsed(
15179         void *parsed_result,
15180         __attribute__((unused)) struct cmdline *cl,
15181         __attribute__((unused)) void *data)
15182 {
15183         struct cmd_ddp_del_result *res = parsed_result;
15184         uint8_t *buff;
15185         uint32_t size;
15186         int ret = -ENOTSUP;
15187
15188         if (!all_ports_stopped()) {
15189                 printf("Please stop all ports first\n");
15190                 return;
15191         }
15192
15193         buff = open_file(res->filepath, &size);
15194         if (!buff)
15195                 return;
15196
15197 #ifdef RTE_LIBRTE_I40E_PMD
15198         if (ret == -ENOTSUP)
15199                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15200                                                buff, size,
15201                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15202 #endif
15203
15204         if (ret == -EACCES)
15205                 printf("Profile does not exist.\n");
15206         else if (ret < 0)
15207                 printf("Failed to delete profile.\n");
15208
15209         close_file(buff);
15210 }
15211
15212 cmdline_parse_inst_t cmd_ddp_del = {
15213         .f = cmd_ddp_del_parsed,
15214         .data = NULL,
15215         .help_str = "ddp del <port_id> <backup_profile_path>",
15216         .tokens = {
15217                 (void *)&cmd_ddp_del_ddp,
15218                 (void *)&cmd_ddp_del_del,
15219                 (void *)&cmd_ddp_del_port_id,
15220                 (void *)&cmd_ddp_del_filepath,
15221                 NULL,
15222         },
15223 };
15224
15225 /* Get dynamic device personalization profile info */
15226 struct cmd_ddp_info_result {
15227         cmdline_fixed_string_t ddp;
15228         cmdline_fixed_string_t get;
15229         cmdline_fixed_string_t info;
15230         char filepath[];
15231 };
15232
15233 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15234         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15235 cmdline_parse_token_string_t cmd_ddp_info_get =
15236         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15237 cmdline_parse_token_string_t cmd_ddp_info_info =
15238         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15239 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15240         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15241
15242 static void
15243 cmd_ddp_info_parsed(
15244         void *parsed_result,
15245         __attribute__((unused)) struct cmdline *cl,
15246         __attribute__((unused)) void *data)
15247 {
15248         struct cmd_ddp_info_result *res = parsed_result;
15249         uint8_t *pkg;
15250         uint32_t pkg_size;
15251         int ret = -ENOTSUP;
15252 #ifdef RTE_LIBRTE_I40E_PMD
15253         uint32_t i, j, n;
15254         uint8_t *buff;
15255         uint32_t buff_size = 0;
15256         struct rte_pmd_i40e_profile_info info;
15257         uint32_t dev_num = 0;
15258         struct rte_pmd_i40e_ddp_device_id *devs;
15259         uint32_t proto_num = 0;
15260         struct rte_pmd_i40e_proto_info *proto = NULL;
15261         uint32_t pctype_num = 0;
15262         struct rte_pmd_i40e_ptype_info *pctype;
15263         uint32_t ptype_num = 0;
15264         struct rte_pmd_i40e_ptype_info *ptype;
15265         uint8_t proto_id;
15266
15267 #endif
15268
15269         pkg = open_file(res->filepath, &pkg_size);
15270         if (!pkg)
15271                 return;
15272
15273 #ifdef RTE_LIBRTE_I40E_PMD
15274         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15275                                 (uint8_t *)&info, sizeof(info),
15276                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15277         if (!ret) {
15278                 printf("Global Track id:       0x%x\n", info.track_id);
15279                 printf("Global Version:        %d.%d.%d.%d\n",
15280                         info.version.major,
15281                         info.version.minor,
15282                         info.version.update,
15283                         info.version.draft);
15284                 printf("Global Package name:   %s\n\n", info.name);
15285         }
15286
15287         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15288                                 (uint8_t *)&info, sizeof(info),
15289                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15290         if (!ret) {
15291                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15292                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15293                         info.version.major,
15294                         info.version.minor,
15295                         info.version.update,
15296                         info.version.draft);
15297                 printf("i40e Profile name:     %s\n\n", info.name);
15298         }
15299
15300         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15301                                 (uint8_t *)&buff_size, sizeof(buff_size),
15302                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15303         if (!ret && buff_size) {
15304                 buff = (uint8_t *)malloc(buff_size);
15305                 if (buff) {
15306                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15307                                                 buff, buff_size,
15308                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15309                         if (!ret)
15310                                 printf("Package Notes:\n%s\n\n", buff);
15311                         free(buff);
15312                 }
15313         }
15314
15315         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15316                                 (uint8_t *)&dev_num, sizeof(dev_num),
15317                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15318         if (!ret && dev_num) {
15319                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15320                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15321                 if (devs) {
15322                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15323                                                 (uint8_t *)devs, buff_size,
15324                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15325                         if (!ret) {
15326                                 printf("List of supported devices:\n");
15327                                 for (i = 0; i < dev_num; i++) {
15328                                         printf("  %04X:%04X %04X:%04X\n",
15329                                                 devs[i].vendor_dev_id >> 16,
15330                                                 devs[i].vendor_dev_id & 0xFFFF,
15331                                                 devs[i].sub_vendor_dev_id >> 16,
15332                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15333                                 }
15334                                 printf("\n");
15335                         }
15336                         free(devs);
15337                 }
15338         }
15339
15340         /* get information about protocols and packet types */
15341         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15342                 (uint8_t *)&proto_num, sizeof(proto_num),
15343                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15344         if (ret || !proto_num)
15345                 goto no_print_return;
15346
15347         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15348         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15349         if (!proto)
15350                 goto no_print_return;
15351
15352         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15353                                         buff_size,
15354                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15355         if (!ret) {
15356                 printf("List of used protocols:\n");
15357                 for (i = 0; i < proto_num; i++)
15358                         printf("  %2u: %s\n", proto[i].proto_id,
15359                                proto[i].name);
15360                 printf("\n");
15361         }
15362         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15363                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15364                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15365         if (ret || !pctype_num)
15366                 goto no_print_pctypes;
15367
15368         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15369         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15370         if (!pctype)
15371                 goto no_print_pctypes;
15372
15373         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15374                                         buff_size,
15375                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15376         if (ret) {
15377                 free(pctype);
15378                 goto no_print_pctypes;
15379         }
15380
15381         printf("List of defined packet classification types:\n");
15382         for (i = 0; i < pctype_num; i++) {
15383                 printf("  %2u:", pctype[i].ptype_id);
15384                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15385                         proto_id = pctype[i].protocols[j];
15386                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15387                                 for (n = 0; n < proto_num; n++) {
15388                                         if (proto[n].proto_id == proto_id) {
15389                                                 printf(" %s", proto[n].name);
15390                                                 break;
15391                                         }
15392                                 }
15393                         }
15394                 }
15395                 printf("\n");
15396         }
15397         printf("\n");
15398         free(pctype);
15399
15400 no_print_pctypes:
15401
15402         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15403                                         sizeof(ptype_num),
15404                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15405         if (ret || !ptype_num)
15406                 goto no_print_return;
15407
15408         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15409         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15410         if (!ptype)
15411                 goto no_print_return;
15412
15413         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15414                                         buff_size,
15415                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15416         if (ret) {
15417                 free(ptype);
15418                 goto no_print_return;
15419         }
15420         printf("List of defined packet types:\n");
15421         for (i = 0; i < ptype_num; i++) {
15422                 printf("  %2u:", ptype[i].ptype_id);
15423                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15424                         proto_id = ptype[i].protocols[j];
15425                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15426                                 for (n = 0; n < proto_num; n++) {
15427                                         if (proto[n].proto_id == proto_id) {
15428                                                 printf(" %s", proto[n].name);
15429                                                 break;
15430                                         }
15431                                 }
15432                         }
15433                 }
15434                 printf("\n");
15435         }
15436         free(ptype);
15437         printf("\n");
15438
15439         ret = 0;
15440 no_print_return:
15441         if (proto)
15442                 free(proto);
15443 #endif
15444         if (ret == -ENOTSUP)
15445                 printf("Function not supported in PMD driver\n");
15446         close_file(pkg);
15447 }
15448
15449 cmdline_parse_inst_t cmd_ddp_get_info = {
15450         .f = cmd_ddp_info_parsed,
15451         .data = NULL,
15452         .help_str = "ddp get info <profile_path>",
15453         .tokens = {
15454                 (void *)&cmd_ddp_info_ddp,
15455                 (void *)&cmd_ddp_info_get,
15456                 (void *)&cmd_ddp_info_info,
15457                 (void *)&cmd_ddp_info_filepath,
15458                 NULL,
15459         },
15460 };
15461
15462 /* Get dynamic device personalization profile info list*/
15463 #define PROFILE_INFO_SIZE 48
15464 #define MAX_PROFILE_NUM 16
15465
15466 struct cmd_ddp_get_list_result {
15467         cmdline_fixed_string_t ddp;
15468         cmdline_fixed_string_t get;
15469         cmdline_fixed_string_t list;
15470         portid_t port_id;
15471 };
15472
15473 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15474         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15475 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15476         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15477 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15478         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15479 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15480         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15481
15482 static void
15483 cmd_ddp_get_list_parsed(
15484         __attribute__((unused)) void *parsed_result,
15485         __attribute__((unused)) struct cmdline *cl,
15486         __attribute__((unused)) void *data)
15487 {
15488 #ifdef RTE_LIBRTE_I40E_PMD
15489         struct cmd_ddp_get_list_result *res = parsed_result;
15490         struct rte_pmd_i40e_profile_list *p_list;
15491         struct rte_pmd_i40e_profile_info *p_info;
15492         uint32_t p_num;
15493         uint32_t size;
15494         uint32_t i;
15495 #endif
15496         int ret = -ENOTSUP;
15497
15498 #ifdef RTE_LIBRTE_I40E_PMD
15499         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15500         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15501         if (!p_list)
15502                 printf("%s: Failed to malloc buffer\n", __func__);
15503
15504         if (ret == -ENOTSUP)
15505                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15506                                                 (uint8_t *)p_list, size);
15507
15508         if (!ret) {
15509                 p_num = p_list->p_count;
15510                 printf("Profile number is: %d\n\n", p_num);
15511
15512                 for (i = 0; i < p_num; i++) {
15513                         p_info = &p_list->p_info[i];
15514                         printf("Profile %d:\n", i);
15515                         printf("Track id:     0x%x\n", p_info->track_id);
15516                         printf("Version:      %d.%d.%d.%d\n",
15517                                p_info->version.major,
15518                                p_info->version.minor,
15519                                p_info->version.update,
15520                                p_info->version.draft);
15521                         printf("Profile name: %s\n\n", p_info->name);
15522                 }
15523         }
15524
15525         free(p_list);
15526 #endif
15527
15528         if (ret < 0)
15529                 printf("Failed to get ddp list\n");
15530 }
15531
15532 cmdline_parse_inst_t cmd_ddp_get_list = {
15533         .f = cmd_ddp_get_list_parsed,
15534         .data = NULL,
15535         .help_str = "ddp get list <port_id>",
15536         .tokens = {
15537                 (void *)&cmd_ddp_get_list_ddp,
15538                 (void *)&cmd_ddp_get_list_get,
15539                 (void *)&cmd_ddp_get_list_list,
15540                 (void *)&cmd_ddp_get_list_port_id,
15541                 NULL,
15542         },
15543 };
15544
15545 /* Configure input set */
15546 struct cmd_cfg_input_set_result {
15547         cmdline_fixed_string_t port;
15548         cmdline_fixed_string_t cfg;
15549         portid_t port_id;
15550         cmdline_fixed_string_t pctype;
15551         uint8_t pctype_id;
15552         cmdline_fixed_string_t inset_type;
15553         cmdline_fixed_string_t opt;
15554         cmdline_fixed_string_t field;
15555         uint8_t field_idx;
15556 };
15557
15558 static void
15559 cmd_cfg_input_set_parsed(
15560         __attribute__((unused)) void *parsed_result,
15561         __attribute__((unused)) struct cmdline *cl,
15562         __attribute__((unused)) void *data)
15563 {
15564 #ifdef RTE_LIBRTE_I40E_PMD
15565         struct cmd_cfg_input_set_result *res = parsed_result;
15566         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15567         struct rte_pmd_i40e_inset inset;
15568 #endif
15569         int ret = -ENOTSUP;
15570
15571         if (!all_ports_stopped()) {
15572                 printf("Please stop all ports first\n");
15573                 return;
15574         }
15575
15576 #ifdef RTE_LIBRTE_I40E_PMD
15577         if (!strcmp(res->inset_type, "hash_inset"))
15578                 inset_type = INSET_HASH;
15579         else if (!strcmp(res->inset_type, "fdir_inset"))
15580                 inset_type = INSET_FDIR;
15581         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15582                 inset_type = INSET_FDIR_FLX;
15583         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15584                                      &inset, inset_type);
15585         if (ret) {
15586                 printf("Failed to get input set.\n");
15587                 return;
15588         }
15589
15590         if (!strcmp(res->opt, "get")) {
15591                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15592                                                    res->field_idx);
15593                 if (ret)
15594                         printf("Field index %d is enabled.\n", res->field_idx);
15595                 else
15596                         printf("Field index %d is disabled.\n", res->field_idx);
15597                 return;
15598         } else if (!strcmp(res->opt, "set"))
15599                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15600                                                    res->field_idx);
15601         else if (!strcmp(res->opt, "clear"))
15602                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15603                                                      res->field_idx);
15604         if (ret) {
15605                 printf("Failed to configure input set field.\n");
15606                 return;
15607         }
15608
15609         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15610                                      &inset, inset_type);
15611         if (ret) {
15612                 printf("Failed to set input set.\n");
15613                 return;
15614         }
15615 #endif
15616
15617         if (ret == -ENOTSUP)
15618                 printf("Function not supported\n");
15619 }
15620
15621 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15622         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15623                                  port, "port");
15624 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15625         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15626                                  cfg, "config");
15627 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15628         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15629                               port_id, UINT16);
15630 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15631         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15632                                  pctype, "pctype");
15633 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15634         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15635                               pctype_id, UINT8);
15636 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15637         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15638                                  inset_type,
15639                                  "hash_inset#fdir_inset#fdir_flx_inset");
15640 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15641         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15642                                  opt, "get#set#clear");
15643 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15644         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15645                                  field, "field");
15646 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15647         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15648                               field_idx, UINT8);
15649
15650 cmdline_parse_inst_t cmd_cfg_input_set = {
15651         .f = cmd_cfg_input_set_parsed,
15652         .data = NULL,
15653         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15654                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15655         .tokens = {
15656                 (void *)&cmd_cfg_input_set_port,
15657                 (void *)&cmd_cfg_input_set_cfg,
15658                 (void *)&cmd_cfg_input_set_port_id,
15659                 (void *)&cmd_cfg_input_set_pctype,
15660                 (void *)&cmd_cfg_input_set_pctype_id,
15661                 (void *)&cmd_cfg_input_set_inset_type,
15662                 (void *)&cmd_cfg_input_set_opt,
15663                 (void *)&cmd_cfg_input_set_field,
15664                 (void *)&cmd_cfg_input_set_field_idx,
15665                 NULL,
15666         },
15667 };
15668
15669 /* Clear input set */
15670 struct cmd_clear_input_set_result {
15671         cmdline_fixed_string_t port;
15672         cmdline_fixed_string_t cfg;
15673         portid_t port_id;
15674         cmdline_fixed_string_t pctype;
15675         uint8_t pctype_id;
15676         cmdline_fixed_string_t inset_type;
15677         cmdline_fixed_string_t clear;
15678         cmdline_fixed_string_t all;
15679 };
15680
15681 static void
15682 cmd_clear_input_set_parsed(
15683         __attribute__((unused)) void *parsed_result,
15684         __attribute__((unused)) struct cmdline *cl,
15685         __attribute__((unused)) void *data)
15686 {
15687 #ifdef RTE_LIBRTE_I40E_PMD
15688         struct cmd_clear_input_set_result *res = parsed_result;
15689         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15690         struct rte_pmd_i40e_inset inset;
15691 #endif
15692         int ret = -ENOTSUP;
15693
15694         if (!all_ports_stopped()) {
15695                 printf("Please stop all ports first\n");
15696                 return;
15697         }
15698
15699 #ifdef RTE_LIBRTE_I40E_PMD
15700         if (!strcmp(res->inset_type, "hash_inset"))
15701                 inset_type = INSET_HASH;
15702         else if (!strcmp(res->inset_type, "fdir_inset"))
15703                 inset_type = INSET_FDIR;
15704         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15705                 inset_type = INSET_FDIR_FLX;
15706
15707         memset(&inset, 0, sizeof(inset));
15708
15709         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15710                                      &inset, inset_type);
15711         if (ret) {
15712                 printf("Failed to clear input set.\n");
15713                 return;
15714         }
15715
15716 #endif
15717
15718         if (ret == -ENOTSUP)
15719                 printf("Function not supported\n");
15720 }
15721
15722 cmdline_parse_token_string_t cmd_clear_input_set_port =
15723         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15724                                  port, "port");
15725 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15726         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15727                                  cfg, "config");
15728 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15729         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15730                               port_id, UINT16);
15731 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15732         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15733                                  pctype, "pctype");
15734 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15735         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15736                               pctype_id, UINT8);
15737 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15738         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15739                                  inset_type,
15740                                  "hash_inset#fdir_inset#fdir_flx_inset");
15741 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15742         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15743                                  clear, "clear");
15744 cmdline_parse_token_string_t cmd_clear_input_set_all =
15745         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15746                                  all, "all");
15747
15748 cmdline_parse_inst_t cmd_clear_input_set = {
15749         .f = cmd_clear_input_set_parsed,
15750         .data = NULL,
15751         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15752                     "fdir_inset|fdir_flx_inset clear all",
15753         .tokens = {
15754                 (void *)&cmd_clear_input_set_port,
15755                 (void *)&cmd_clear_input_set_cfg,
15756                 (void *)&cmd_clear_input_set_port_id,
15757                 (void *)&cmd_clear_input_set_pctype,
15758                 (void *)&cmd_clear_input_set_pctype_id,
15759                 (void *)&cmd_clear_input_set_inset_type,
15760                 (void *)&cmd_clear_input_set_clear,
15761                 (void *)&cmd_clear_input_set_all,
15762                 NULL,
15763         },
15764 };
15765
15766 /* show vf stats */
15767
15768 /* Common result structure for show vf stats */
15769 struct cmd_show_vf_stats_result {
15770         cmdline_fixed_string_t show;
15771         cmdline_fixed_string_t vf;
15772         cmdline_fixed_string_t stats;
15773         portid_t port_id;
15774         uint16_t vf_id;
15775 };
15776
15777 /* Common CLI fields show vf stats*/
15778 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15779         TOKEN_STRING_INITIALIZER
15780                 (struct cmd_show_vf_stats_result,
15781                  show, "show");
15782 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15783         TOKEN_STRING_INITIALIZER
15784                 (struct cmd_show_vf_stats_result,
15785                  vf, "vf");
15786 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15787         TOKEN_STRING_INITIALIZER
15788                 (struct cmd_show_vf_stats_result,
15789                  stats, "stats");
15790 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15791         TOKEN_NUM_INITIALIZER
15792                 (struct cmd_show_vf_stats_result,
15793                  port_id, UINT16);
15794 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15795         TOKEN_NUM_INITIALIZER
15796                 (struct cmd_show_vf_stats_result,
15797                  vf_id, UINT16);
15798
15799 static void
15800 cmd_show_vf_stats_parsed(
15801         void *parsed_result,
15802         __attribute__((unused)) struct cmdline *cl,
15803         __attribute__((unused)) void *data)
15804 {
15805         struct cmd_show_vf_stats_result *res = parsed_result;
15806         struct rte_eth_stats stats;
15807         int ret = -ENOTSUP;
15808         static const char *nic_stats_border = "########################";
15809
15810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15811                 return;
15812
15813         memset(&stats, 0, sizeof(stats));
15814
15815 #ifdef RTE_LIBRTE_I40E_PMD
15816         if (ret == -ENOTSUP)
15817                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15818                                                 res->vf_id,
15819                                                 &stats);
15820 #endif
15821 #ifdef RTE_LIBRTE_BNXT_PMD
15822         if (ret == -ENOTSUP)
15823                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15824                                                 res->vf_id,
15825                                                 &stats);
15826 #endif
15827
15828         switch (ret) {
15829         case 0:
15830                 break;
15831         case -EINVAL:
15832                 printf("invalid vf_id %d\n", res->vf_id);
15833                 break;
15834         case -ENODEV:
15835                 printf("invalid port_id %d\n", res->port_id);
15836                 break;
15837         case -ENOTSUP:
15838                 printf("function not implemented\n");
15839                 break;
15840         default:
15841                 printf("programming error: (%s)\n", strerror(-ret));
15842         }
15843
15844         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15845                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15846
15847         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15848                "%-"PRIu64"\n",
15849                stats.ipackets, stats.imissed, stats.ibytes);
15850         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15851         printf("  RX-nombuf:  %-10"PRIu64"\n",
15852                stats.rx_nombuf);
15853         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15854                "%-"PRIu64"\n",
15855                stats.opackets, stats.oerrors, stats.obytes);
15856
15857         printf("  %s############################%s\n",
15858                                nic_stats_border, nic_stats_border);
15859 }
15860
15861 cmdline_parse_inst_t cmd_show_vf_stats = {
15862         .f = cmd_show_vf_stats_parsed,
15863         .data = NULL,
15864         .help_str = "show vf stats <port_id> <vf_id>",
15865         .tokens = {
15866                 (void *)&cmd_show_vf_stats_show,
15867                 (void *)&cmd_show_vf_stats_vf,
15868                 (void *)&cmd_show_vf_stats_stats,
15869                 (void *)&cmd_show_vf_stats_port_id,
15870                 (void *)&cmd_show_vf_stats_vf_id,
15871                 NULL,
15872         },
15873 };
15874
15875 /* clear vf stats */
15876
15877 /* Common result structure for clear vf stats */
15878 struct cmd_clear_vf_stats_result {
15879         cmdline_fixed_string_t clear;
15880         cmdline_fixed_string_t vf;
15881         cmdline_fixed_string_t stats;
15882         portid_t port_id;
15883         uint16_t vf_id;
15884 };
15885
15886 /* Common CLI fields clear vf stats*/
15887 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15888         TOKEN_STRING_INITIALIZER
15889                 (struct cmd_clear_vf_stats_result,
15890                  clear, "clear");
15891 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15892         TOKEN_STRING_INITIALIZER
15893                 (struct cmd_clear_vf_stats_result,
15894                  vf, "vf");
15895 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15896         TOKEN_STRING_INITIALIZER
15897                 (struct cmd_clear_vf_stats_result,
15898                  stats, "stats");
15899 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15900         TOKEN_NUM_INITIALIZER
15901                 (struct cmd_clear_vf_stats_result,
15902                  port_id, UINT16);
15903 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15904         TOKEN_NUM_INITIALIZER
15905                 (struct cmd_clear_vf_stats_result,
15906                  vf_id, UINT16);
15907
15908 static void
15909 cmd_clear_vf_stats_parsed(
15910         void *parsed_result,
15911         __attribute__((unused)) struct cmdline *cl,
15912         __attribute__((unused)) void *data)
15913 {
15914         struct cmd_clear_vf_stats_result *res = parsed_result;
15915         int ret = -ENOTSUP;
15916
15917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15918                 return;
15919
15920 #ifdef RTE_LIBRTE_I40E_PMD
15921         if (ret == -ENOTSUP)
15922                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15923                                                   res->vf_id);
15924 #endif
15925 #ifdef RTE_LIBRTE_BNXT_PMD
15926         if (ret == -ENOTSUP)
15927                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15928                                                   res->vf_id);
15929 #endif
15930
15931         switch (ret) {
15932         case 0:
15933                 break;
15934         case -EINVAL:
15935                 printf("invalid vf_id %d\n", res->vf_id);
15936                 break;
15937         case -ENODEV:
15938                 printf("invalid port_id %d\n", res->port_id);
15939                 break;
15940         case -ENOTSUP:
15941                 printf("function not implemented\n");
15942                 break;
15943         default:
15944                 printf("programming error: (%s)\n", strerror(-ret));
15945         }
15946 }
15947
15948 cmdline_parse_inst_t cmd_clear_vf_stats = {
15949         .f = cmd_clear_vf_stats_parsed,
15950         .data = NULL,
15951         .help_str = "clear vf stats <port_id> <vf_id>",
15952         .tokens = {
15953                 (void *)&cmd_clear_vf_stats_clear,
15954                 (void *)&cmd_clear_vf_stats_vf,
15955                 (void *)&cmd_clear_vf_stats_stats,
15956                 (void *)&cmd_clear_vf_stats_port_id,
15957                 (void *)&cmd_clear_vf_stats_vf_id,
15958                 NULL,
15959         },
15960 };
15961
15962 /* port config pctype mapping reset */
15963
15964 /* Common result structure for port config pctype mapping reset */
15965 struct cmd_pctype_mapping_reset_result {
15966         cmdline_fixed_string_t port;
15967         cmdline_fixed_string_t config;
15968         portid_t port_id;
15969         cmdline_fixed_string_t pctype;
15970         cmdline_fixed_string_t mapping;
15971         cmdline_fixed_string_t reset;
15972 };
15973
15974 /* Common CLI fields for port config pctype mapping reset*/
15975 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15976         TOKEN_STRING_INITIALIZER
15977                 (struct cmd_pctype_mapping_reset_result,
15978                  port, "port");
15979 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15980         TOKEN_STRING_INITIALIZER
15981                 (struct cmd_pctype_mapping_reset_result,
15982                  config, "config");
15983 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15984         TOKEN_NUM_INITIALIZER
15985                 (struct cmd_pctype_mapping_reset_result,
15986                  port_id, UINT16);
15987 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15988         TOKEN_STRING_INITIALIZER
15989                 (struct cmd_pctype_mapping_reset_result,
15990                  pctype, "pctype");
15991 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15992         TOKEN_STRING_INITIALIZER
15993                 (struct cmd_pctype_mapping_reset_result,
15994                  mapping, "mapping");
15995 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15996         TOKEN_STRING_INITIALIZER
15997                 (struct cmd_pctype_mapping_reset_result,
15998                  reset, "reset");
15999
16000 static void
16001 cmd_pctype_mapping_reset_parsed(
16002         void *parsed_result,
16003         __attribute__((unused)) struct cmdline *cl,
16004         __attribute__((unused)) void *data)
16005 {
16006         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16007         int ret = -ENOTSUP;
16008
16009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16010                 return;
16011
16012 #ifdef RTE_LIBRTE_I40E_PMD
16013         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16014 #endif
16015
16016         switch (ret) {
16017         case 0:
16018                 break;
16019         case -ENODEV:
16020                 printf("invalid port_id %d\n", res->port_id);
16021                 break;
16022         case -ENOTSUP:
16023                 printf("function not implemented\n");
16024                 break;
16025         default:
16026                 printf("programming error: (%s)\n", strerror(-ret));
16027         }
16028 }
16029
16030 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16031         .f = cmd_pctype_mapping_reset_parsed,
16032         .data = NULL,
16033         .help_str = "port config <port_id> pctype mapping reset",
16034         .tokens = {
16035                 (void *)&cmd_pctype_mapping_reset_port,
16036                 (void *)&cmd_pctype_mapping_reset_config,
16037                 (void *)&cmd_pctype_mapping_reset_port_id,
16038                 (void *)&cmd_pctype_mapping_reset_pctype,
16039                 (void *)&cmd_pctype_mapping_reset_mapping,
16040                 (void *)&cmd_pctype_mapping_reset_reset,
16041                 NULL,
16042         },
16043 };
16044
16045 /* show port pctype mapping */
16046
16047 /* Common result structure for show port pctype mapping */
16048 struct cmd_pctype_mapping_get_result {
16049         cmdline_fixed_string_t show;
16050         cmdline_fixed_string_t port;
16051         portid_t port_id;
16052         cmdline_fixed_string_t pctype;
16053         cmdline_fixed_string_t mapping;
16054 };
16055
16056 /* Common CLI fields for pctype mapping get */
16057 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16058         TOKEN_STRING_INITIALIZER
16059                 (struct cmd_pctype_mapping_get_result,
16060                  show, "show");
16061 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16062         TOKEN_STRING_INITIALIZER
16063                 (struct cmd_pctype_mapping_get_result,
16064                  port, "port");
16065 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16066         TOKEN_NUM_INITIALIZER
16067                 (struct cmd_pctype_mapping_get_result,
16068                  port_id, UINT16);
16069 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16070         TOKEN_STRING_INITIALIZER
16071                 (struct cmd_pctype_mapping_get_result,
16072                  pctype, "pctype");
16073 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16074         TOKEN_STRING_INITIALIZER
16075                 (struct cmd_pctype_mapping_get_result,
16076                  mapping, "mapping");
16077
16078 static void
16079 cmd_pctype_mapping_get_parsed(
16080         void *parsed_result,
16081         __attribute__((unused)) struct cmdline *cl,
16082         __attribute__((unused)) void *data)
16083 {
16084         struct cmd_pctype_mapping_get_result *res = parsed_result;
16085         int ret = -ENOTSUP;
16086 #ifdef RTE_LIBRTE_I40E_PMD
16087         struct rte_pmd_i40e_flow_type_mapping
16088                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16089         int i, j, first_pctype;
16090 #endif
16091
16092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16093                 return;
16094
16095 #ifdef RTE_LIBRTE_I40E_PMD
16096         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16097 #endif
16098
16099         switch (ret) {
16100         case 0:
16101                 break;
16102         case -ENODEV:
16103                 printf("invalid port_id %d\n", res->port_id);
16104                 return;
16105         case -ENOTSUP:
16106                 printf("function not implemented\n");
16107                 return;
16108         default:
16109                 printf("programming error: (%s)\n", strerror(-ret));
16110                 return;
16111         }
16112
16113 #ifdef RTE_LIBRTE_I40E_PMD
16114         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16115                 if (mapping[i].pctype != 0ULL) {
16116                         first_pctype = 1;
16117
16118                         printf("pctype: ");
16119                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16120                                 if (mapping[i].pctype & (1ULL << j)) {
16121                                         printf(first_pctype ?
16122                                                "%02d" : ",%02d", j);
16123                                         first_pctype = 0;
16124                                 }
16125                         }
16126                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16127                 }
16128         }
16129 #endif
16130 }
16131
16132 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16133         .f = cmd_pctype_mapping_get_parsed,
16134         .data = NULL,
16135         .help_str = "show port <port_id> pctype mapping",
16136         .tokens = {
16137                 (void *)&cmd_pctype_mapping_get_show,
16138                 (void *)&cmd_pctype_mapping_get_port,
16139                 (void *)&cmd_pctype_mapping_get_port_id,
16140                 (void *)&cmd_pctype_mapping_get_pctype,
16141                 (void *)&cmd_pctype_mapping_get_mapping,
16142                 NULL,
16143         },
16144 };
16145
16146 /* port config pctype mapping update */
16147
16148 /* Common result structure for port config pctype mapping update */
16149 struct cmd_pctype_mapping_update_result {
16150         cmdline_fixed_string_t port;
16151         cmdline_fixed_string_t config;
16152         portid_t port_id;
16153         cmdline_fixed_string_t pctype;
16154         cmdline_fixed_string_t mapping;
16155         cmdline_fixed_string_t update;
16156         cmdline_fixed_string_t pctype_list;
16157         uint16_t flow_type;
16158 };
16159
16160 /* Common CLI fields for pctype mapping update*/
16161 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16162         TOKEN_STRING_INITIALIZER
16163                 (struct cmd_pctype_mapping_update_result,
16164                  port, "port");
16165 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16166         TOKEN_STRING_INITIALIZER
16167                 (struct cmd_pctype_mapping_update_result,
16168                  config, "config");
16169 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16170         TOKEN_NUM_INITIALIZER
16171                 (struct cmd_pctype_mapping_update_result,
16172                  port_id, UINT16);
16173 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16174         TOKEN_STRING_INITIALIZER
16175                 (struct cmd_pctype_mapping_update_result,
16176                  pctype, "pctype");
16177 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16178         TOKEN_STRING_INITIALIZER
16179                 (struct cmd_pctype_mapping_update_result,
16180                  mapping, "mapping");
16181 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16182         TOKEN_STRING_INITIALIZER
16183                 (struct cmd_pctype_mapping_update_result,
16184                  update, "update");
16185 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16186         TOKEN_STRING_INITIALIZER
16187                 (struct cmd_pctype_mapping_update_result,
16188                  pctype_list, NULL);
16189 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16190         TOKEN_NUM_INITIALIZER
16191                 (struct cmd_pctype_mapping_update_result,
16192                  flow_type, UINT16);
16193
16194 static void
16195 cmd_pctype_mapping_update_parsed(
16196         void *parsed_result,
16197         __attribute__((unused)) struct cmdline *cl,
16198         __attribute__((unused)) void *data)
16199 {
16200         struct cmd_pctype_mapping_update_result *res = parsed_result;
16201         int ret = -ENOTSUP;
16202 #ifdef RTE_LIBRTE_I40E_PMD
16203         struct rte_pmd_i40e_flow_type_mapping mapping;
16204         unsigned int i;
16205         unsigned int nb_item;
16206         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16207 #endif
16208
16209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16210                 return;
16211
16212 #ifdef RTE_LIBRTE_I40E_PMD
16213         nb_item = parse_item_list(res->pctype_list, "pctypes",
16214                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16215         mapping.flow_type = res->flow_type;
16216         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16217                 mapping.pctype |= (1ULL << pctype_list[i]);
16218         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16219                                                 &mapping,
16220                                                 1,
16221                                                 0);
16222 #endif
16223
16224         switch (ret) {
16225         case 0:
16226                 break;
16227         case -EINVAL:
16228                 printf("invalid pctype or flow type\n");
16229                 break;
16230         case -ENODEV:
16231                 printf("invalid port_id %d\n", res->port_id);
16232                 break;
16233         case -ENOTSUP:
16234                 printf("function not implemented\n");
16235                 break;
16236         default:
16237                 printf("programming error: (%s)\n", strerror(-ret));
16238         }
16239 }
16240
16241 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16242         .f = cmd_pctype_mapping_update_parsed,
16243         .data = NULL,
16244         .help_str = "port config <port_id> pctype mapping update"
16245         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16246         .tokens = {
16247                 (void *)&cmd_pctype_mapping_update_port,
16248                 (void *)&cmd_pctype_mapping_update_config,
16249                 (void *)&cmd_pctype_mapping_update_port_id,
16250                 (void *)&cmd_pctype_mapping_update_pctype,
16251                 (void *)&cmd_pctype_mapping_update_mapping,
16252                 (void *)&cmd_pctype_mapping_update_update,
16253                 (void *)&cmd_pctype_mapping_update_pc_type,
16254                 (void *)&cmd_pctype_mapping_update_flow_type,
16255                 NULL,
16256         },
16257 };
16258
16259 /* ptype mapping get */
16260
16261 /* Common result structure for ptype mapping get */
16262 struct cmd_ptype_mapping_get_result {
16263         cmdline_fixed_string_t ptype;
16264         cmdline_fixed_string_t mapping;
16265         cmdline_fixed_string_t get;
16266         portid_t port_id;
16267         uint8_t valid_only;
16268 };
16269
16270 /* Common CLI fields for ptype mapping get */
16271 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16272         TOKEN_STRING_INITIALIZER
16273                 (struct cmd_ptype_mapping_get_result,
16274                  ptype, "ptype");
16275 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16276         TOKEN_STRING_INITIALIZER
16277                 (struct cmd_ptype_mapping_get_result,
16278                  mapping, "mapping");
16279 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16280         TOKEN_STRING_INITIALIZER
16281                 (struct cmd_ptype_mapping_get_result,
16282                  get, "get");
16283 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16284         TOKEN_NUM_INITIALIZER
16285                 (struct cmd_ptype_mapping_get_result,
16286                  port_id, UINT16);
16287 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16288         TOKEN_NUM_INITIALIZER
16289                 (struct cmd_ptype_mapping_get_result,
16290                  valid_only, UINT8);
16291
16292 static void
16293 cmd_ptype_mapping_get_parsed(
16294         void *parsed_result,
16295         __attribute__((unused)) struct cmdline *cl,
16296         __attribute__((unused)) void *data)
16297 {
16298         struct cmd_ptype_mapping_get_result *res = parsed_result;
16299         int ret = -ENOTSUP;
16300 #ifdef RTE_LIBRTE_I40E_PMD
16301         int max_ptype_num = 256;
16302         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16303         uint16_t count;
16304         int i;
16305 #endif
16306
16307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16308                 return;
16309
16310 #ifdef RTE_LIBRTE_I40E_PMD
16311         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16312                                         mapping,
16313                                         max_ptype_num,
16314                                         &count,
16315                                         res->valid_only);
16316 #endif
16317
16318         switch (ret) {
16319         case 0:
16320                 break;
16321         case -ENODEV:
16322                 printf("invalid port_id %d\n", res->port_id);
16323                 break;
16324         case -ENOTSUP:
16325                 printf("function not implemented\n");
16326                 break;
16327         default:
16328                 printf("programming error: (%s)\n", strerror(-ret));
16329         }
16330
16331 #ifdef RTE_LIBRTE_I40E_PMD
16332         if (!ret) {
16333                 for (i = 0; i < count; i++)
16334                         printf("%3d\t0x%08x\n",
16335                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16336         }
16337 #endif
16338 }
16339
16340 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16341         .f = cmd_ptype_mapping_get_parsed,
16342         .data = NULL,
16343         .help_str = "ptype mapping get <port_id> <valid_only>",
16344         .tokens = {
16345                 (void *)&cmd_ptype_mapping_get_ptype,
16346                 (void *)&cmd_ptype_mapping_get_mapping,
16347                 (void *)&cmd_ptype_mapping_get_get,
16348                 (void *)&cmd_ptype_mapping_get_port_id,
16349                 (void *)&cmd_ptype_mapping_get_valid_only,
16350                 NULL,
16351         },
16352 };
16353
16354 /* ptype mapping replace */
16355
16356 /* Common result structure for ptype mapping replace */
16357 struct cmd_ptype_mapping_replace_result {
16358         cmdline_fixed_string_t ptype;
16359         cmdline_fixed_string_t mapping;
16360         cmdline_fixed_string_t replace;
16361         portid_t port_id;
16362         uint32_t target;
16363         uint8_t mask;
16364         uint32_t pkt_type;
16365 };
16366
16367 /* Common CLI fields for ptype mapping replace */
16368 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16369         TOKEN_STRING_INITIALIZER
16370                 (struct cmd_ptype_mapping_replace_result,
16371                  ptype, "ptype");
16372 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16373         TOKEN_STRING_INITIALIZER
16374                 (struct cmd_ptype_mapping_replace_result,
16375                  mapping, "mapping");
16376 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16377         TOKEN_STRING_INITIALIZER
16378                 (struct cmd_ptype_mapping_replace_result,
16379                  replace, "replace");
16380 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16381         TOKEN_NUM_INITIALIZER
16382                 (struct cmd_ptype_mapping_replace_result,
16383                  port_id, UINT16);
16384 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16385         TOKEN_NUM_INITIALIZER
16386                 (struct cmd_ptype_mapping_replace_result,
16387                  target, UINT32);
16388 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16389         TOKEN_NUM_INITIALIZER
16390                 (struct cmd_ptype_mapping_replace_result,
16391                  mask, UINT8);
16392 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16393         TOKEN_NUM_INITIALIZER
16394                 (struct cmd_ptype_mapping_replace_result,
16395                  pkt_type, UINT32);
16396
16397 static void
16398 cmd_ptype_mapping_replace_parsed(
16399         void *parsed_result,
16400         __attribute__((unused)) struct cmdline *cl,
16401         __attribute__((unused)) void *data)
16402 {
16403         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16404         int ret = -ENOTSUP;
16405
16406         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16407                 return;
16408
16409 #ifdef RTE_LIBRTE_I40E_PMD
16410         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16411                                         res->target,
16412                                         res->mask,
16413                                         res->pkt_type);
16414 #endif
16415
16416         switch (ret) {
16417         case 0:
16418                 break;
16419         case -EINVAL:
16420                 printf("invalid ptype 0x%8x or 0x%8x\n",
16421                                 res->target, res->pkt_type);
16422                 break;
16423         case -ENODEV:
16424                 printf("invalid port_id %d\n", res->port_id);
16425                 break;
16426         case -ENOTSUP:
16427                 printf("function not implemented\n");
16428                 break;
16429         default:
16430                 printf("programming error: (%s)\n", strerror(-ret));
16431         }
16432 }
16433
16434 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16435         .f = cmd_ptype_mapping_replace_parsed,
16436         .data = NULL,
16437         .help_str =
16438                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16439         .tokens = {
16440                 (void *)&cmd_ptype_mapping_replace_ptype,
16441                 (void *)&cmd_ptype_mapping_replace_mapping,
16442                 (void *)&cmd_ptype_mapping_replace_replace,
16443                 (void *)&cmd_ptype_mapping_replace_port_id,
16444                 (void *)&cmd_ptype_mapping_replace_target,
16445                 (void *)&cmd_ptype_mapping_replace_mask,
16446                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16447                 NULL,
16448         },
16449 };
16450
16451 /* ptype mapping reset */
16452
16453 /* Common result structure for ptype mapping reset */
16454 struct cmd_ptype_mapping_reset_result {
16455         cmdline_fixed_string_t ptype;
16456         cmdline_fixed_string_t mapping;
16457         cmdline_fixed_string_t reset;
16458         portid_t port_id;
16459 };
16460
16461 /* Common CLI fields for ptype mapping reset*/
16462 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16463         TOKEN_STRING_INITIALIZER
16464                 (struct cmd_ptype_mapping_reset_result,
16465                  ptype, "ptype");
16466 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16467         TOKEN_STRING_INITIALIZER
16468                 (struct cmd_ptype_mapping_reset_result,
16469                  mapping, "mapping");
16470 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16471         TOKEN_STRING_INITIALIZER
16472                 (struct cmd_ptype_mapping_reset_result,
16473                  reset, "reset");
16474 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16475         TOKEN_NUM_INITIALIZER
16476                 (struct cmd_ptype_mapping_reset_result,
16477                  port_id, UINT16);
16478
16479 static void
16480 cmd_ptype_mapping_reset_parsed(
16481         void *parsed_result,
16482         __attribute__((unused)) struct cmdline *cl,
16483         __attribute__((unused)) void *data)
16484 {
16485         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16486         int ret = -ENOTSUP;
16487
16488         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16489                 return;
16490
16491 #ifdef RTE_LIBRTE_I40E_PMD
16492         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16493 #endif
16494
16495         switch (ret) {
16496         case 0:
16497                 break;
16498         case -ENODEV:
16499                 printf("invalid port_id %d\n", res->port_id);
16500                 break;
16501         case -ENOTSUP:
16502                 printf("function not implemented\n");
16503                 break;
16504         default:
16505                 printf("programming error: (%s)\n", strerror(-ret));
16506         }
16507 }
16508
16509 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16510         .f = cmd_ptype_mapping_reset_parsed,
16511         .data = NULL,
16512         .help_str = "ptype mapping reset <port_id>",
16513         .tokens = {
16514                 (void *)&cmd_ptype_mapping_reset_ptype,
16515                 (void *)&cmd_ptype_mapping_reset_mapping,
16516                 (void *)&cmd_ptype_mapping_reset_reset,
16517                 (void *)&cmd_ptype_mapping_reset_port_id,
16518                 NULL,
16519         },
16520 };
16521
16522 /* ptype mapping update */
16523
16524 /* Common result structure for ptype mapping update */
16525 struct cmd_ptype_mapping_update_result {
16526         cmdline_fixed_string_t ptype;
16527         cmdline_fixed_string_t mapping;
16528         cmdline_fixed_string_t reset;
16529         portid_t port_id;
16530         uint8_t hw_ptype;
16531         uint32_t sw_ptype;
16532 };
16533
16534 /* Common CLI fields for ptype mapping update*/
16535 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16536         TOKEN_STRING_INITIALIZER
16537                 (struct cmd_ptype_mapping_update_result,
16538                  ptype, "ptype");
16539 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16540         TOKEN_STRING_INITIALIZER
16541                 (struct cmd_ptype_mapping_update_result,
16542                  mapping, "mapping");
16543 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16544         TOKEN_STRING_INITIALIZER
16545                 (struct cmd_ptype_mapping_update_result,
16546                  reset, "update");
16547 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16548         TOKEN_NUM_INITIALIZER
16549                 (struct cmd_ptype_mapping_update_result,
16550                  port_id, UINT16);
16551 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16552         TOKEN_NUM_INITIALIZER
16553                 (struct cmd_ptype_mapping_update_result,
16554                  hw_ptype, UINT8);
16555 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16556         TOKEN_NUM_INITIALIZER
16557                 (struct cmd_ptype_mapping_update_result,
16558                  sw_ptype, UINT32);
16559
16560 static void
16561 cmd_ptype_mapping_update_parsed(
16562         void *parsed_result,
16563         __attribute__((unused)) struct cmdline *cl,
16564         __attribute__((unused)) void *data)
16565 {
16566         struct cmd_ptype_mapping_update_result *res = parsed_result;
16567         int ret = -ENOTSUP;
16568 #ifdef RTE_LIBRTE_I40E_PMD
16569         struct rte_pmd_i40e_ptype_mapping mapping;
16570 #endif
16571         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16572                 return;
16573
16574 #ifdef RTE_LIBRTE_I40E_PMD
16575         mapping.hw_ptype = res->hw_ptype;
16576         mapping.sw_ptype = res->sw_ptype;
16577         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16578                                                 &mapping,
16579                                                 1,
16580                                                 0);
16581 #endif
16582
16583         switch (ret) {
16584         case 0:
16585                 break;
16586         case -EINVAL:
16587                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16588                 break;
16589         case -ENODEV:
16590                 printf("invalid port_id %d\n", res->port_id);
16591                 break;
16592         case -ENOTSUP:
16593                 printf("function not implemented\n");
16594                 break;
16595         default:
16596                 printf("programming error: (%s)\n", strerror(-ret));
16597         }
16598 }
16599
16600 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16601         .f = cmd_ptype_mapping_update_parsed,
16602         .data = NULL,
16603         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16604         .tokens = {
16605                 (void *)&cmd_ptype_mapping_update_ptype,
16606                 (void *)&cmd_ptype_mapping_update_mapping,
16607                 (void *)&cmd_ptype_mapping_update_update,
16608                 (void *)&cmd_ptype_mapping_update_port_id,
16609                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16610                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16611                 NULL,
16612         },
16613 };
16614
16615 /* Common result structure for file commands */
16616 struct cmd_cmdfile_result {
16617         cmdline_fixed_string_t load;
16618         cmdline_fixed_string_t filename;
16619 };
16620
16621 /* Common CLI fields for file commands */
16622 cmdline_parse_token_string_t cmd_load_cmdfile =
16623         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16624 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16625         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16626
16627 static void
16628 cmd_load_from_file_parsed(
16629         void *parsed_result,
16630         __attribute__((unused)) struct cmdline *cl,
16631         __attribute__((unused)) void *data)
16632 {
16633         struct cmd_cmdfile_result *res = parsed_result;
16634
16635         cmdline_read_from_file(res->filename);
16636 }
16637
16638 cmdline_parse_inst_t cmd_load_from_file = {
16639         .f = cmd_load_from_file_parsed,
16640         .data = NULL,
16641         .help_str = "load <filename>",
16642         .tokens = {
16643                 (void *)&cmd_load_cmdfile,
16644                 (void *)&cmd_load_cmdfile_filename,
16645                 NULL,
16646         },
16647 };
16648
16649 /* Get Rx offloads capabilities */
16650 struct cmd_rx_offload_get_capa_result {
16651         cmdline_fixed_string_t show;
16652         cmdline_fixed_string_t port;
16653         portid_t port_id;
16654         cmdline_fixed_string_t rx_offload;
16655         cmdline_fixed_string_t capabilities;
16656 };
16657
16658 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16659         TOKEN_STRING_INITIALIZER
16660                 (struct cmd_rx_offload_get_capa_result,
16661                  show, "show");
16662 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16663         TOKEN_STRING_INITIALIZER
16664                 (struct cmd_rx_offload_get_capa_result,
16665                  port, "port");
16666 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16667         TOKEN_NUM_INITIALIZER
16668                 (struct cmd_rx_offload_get_capa_result,
16669                  port_id, UINT16);
16670 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16671         TOKEN_STRING_INITIALIZER
16672                 (struct cmd_rx_offload_get_capa_result,
16673                  rx_offload, "rx_offload");
16674 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16675         TOKEN_STRING_INITIALIZER
16676                 (struct cmd_rx_offload_get_capa_result,
16677                  capabilities, "capabilities");
16678
16679 static void
16680 print_rx_offloads(uint64_t offloads)
16681 {
16682         uint64_t single_offload;
16683         int begin;
16684         int end;
16685         int bit;
16686
16687         if (offloads == 0)
16688                 return;
16689
16690         begin = __builtin_ctzll(offloads);
16691         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16692
16693         single_offload = 1 << begin;
16694         for (bit = begin; bit < end; bit++) {
16695                 if (offloads & single_offload)
16696                         printf(" %s",
16697                                rte_eth_dev_rx_offload_name(single_offload));
16698                 single_offload <<= 1;
16699         }
16700 }
16701
16702 static void
16703 cmd_rx_offload_get_capa_parsed(
16704         void *parsed_result,
16705         __attribute__((unused)) struct cmdline *cl,
16706         __attribute__((unused)) void *data)
16707 {
16708         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16709         struct rte_eth_dev_info dev_info;
16710         portid_t port_id = res->port_id;
16711         uint64_t queue_offloads;
16712         uint64_t port_offloads;
16713
16714         rte_eth_dev_info_get(port_id, &dev_info);
16715         queue_offloads = dev_info.rx_queue_offload_capa;
16716         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16717
16718         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16719         printf("  Per Queue :");
16720         print_rx_offloads(queue_offloads);
16721
16722         printf("\n");
16723         printf("  Per Port  :");
16724         print_rx_offloads(port_offloads);
16725         printf("\n\n");
16726 }
16727
16728 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16729         .f = cmd_rx_offload_get_capa_parsed,
16730         .data = NULL,
16731         .help_str = "show port <port_id> rx_offload capabilities",
16732         .tokens = {
16733                 (void *)&cmd_rx_offload_get_capa_show,
16734                 (void *)&cmd_rx_offload_get_capa_port,
16735                 (void *)&cmd_rx_offload_get_capa_port_id,
16736                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16737                 (void *)&cmd_rx_offload_get_capa_capabilities,
16738                 NULL,
16739         }
16740 };
16741
16742 /* Get Rx offloads configuration */
16743 struct cmd_rx_offload_get_configuration_result {
16744         cmdline_fixed_string_t show;
16745         cmdline_fixed_string_t port;
16746         portid_t port_id;
16747         cmdline_fixed_string_t rx_offload;
16748         cmdline_fixed_string_t configuration;
16749 };
16750
16751 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16752         TOKEN_STRING_INITIALIZER
16753                 (struct cmd_rx_offload_get_configuration_result,
16754                  show, "show");
16755 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16756         TOKEN_STRING_INITIALIZER
16757                 (struct cmd_rx_offload_get_configuration_result,
16758                  port, "port");
16759 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16760         TOKEN_NUM_INITIALIZER
16761                 (struct cmd_rx_offload_get_configuration_result,
16762                  port_id, UINT16);
16763 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16764         TOKEN_STRING_INITIALIZER
16765                 (struct cmd_rx_offload_get_configuration_result,
16766                  rx_offload, "rx_offload");
16767 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16768         TOKEN_STRING_INITIALIZER
16769                 (struct cmd_rx_offload_get_configuration_result,
16770                  configuration, "configuration");
16771
16772 static void
16773 cmd_rx_offload_get_configuration_parsed(
16774         void *parsed_result,
16775         __attribute__((unused)) struct cmdline *cl,
16776         __attribute__((unused)) void *data)
16777 {
16778         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16779         struct rte_eth_dev_info dev_info;
16780         portid_t port_id = res->port_id;
16781         struct rte_port *port = &ports[port_id];
16782         uint64_t port_offloads;
16783         uint64_t queue_offloads;
16784         uint16_t nb_rx_queues;
16785         int q;
16786
16787         printf("Rx Offloading Configuration of port %d :\n", port_id);
16788
16789         port_offloads = port->dev_conf.rxmode.offloads;
16790         printf("  Port :");
16791         print_rx_offloads(port_offloads);
16792         printf("\n");
16793
16794         rte_eth_dev_info_get(port_id, &dev_info);
16795         nb_rx_queues = dev_info.nb_rx_queues;
16796         for (q = 0; q < nb_rx_queues; q++) {
16797                 queue_offloads = port->rx_conf[q].offloads;
16798                 printf("  Queue[%2d] :", q);
16799                 print_rx_offloads(queue_offloads);
16800                 printf("\n");
16801         }
16802         printf("\n");
16803 }
16804
16805 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16806         .f = cmd_rx_offload_get_configuration_parsed,
16807         .data = NULL,
16808         .help_str = "show port <port_id> rx_offload configuration",
16809         .tokens = {
16810                 (void *)&cmd_rx_offload_get_configuration_show,
16811                 (void *)&cmd_rx_offload_get_configuration_port,
16812                 (void *)&cmd_rx_offload_get_configuration_port_id,
16813                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16814                 (void *)&cmd_rx_offload_get_configuration_configuration,
16815                 NULL,
16816         }
16817 };
16818
16819 /* Enable/Disable a per port offloading */
16820 struct cmd_config_per_port_rx_offload_result {
16821         cmdline_fixed_string_t port;
16822         cmdline_fixed_string_t config;
16823         portid_t port_id;
16824         cmdline_fixed_string_t rx_offload;
16825         cmdline_fixed_string_t offload;
16826         cmdline_fixed_string_t on_off;
16827 };
16828
16829 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16830         TOKEN_STRING_INITIALIZER
16831                 (struct cmd_config_per_port_rx_offload_result,
16832                  port, "port");
16833 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16834         TOKEN_STRING_INITIALIZER
16835                 (struct cmd_config_per_port_rx_offload_result,
16836                  config, "config");
16837 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16838         TOKEN_NUM_INITIALIZER
16839                 (struct cmd_config_per_port_rx_offload_result,
16840                  port_id, UINT16);
16841 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16842         TOKEN_STRING_INITIALIZER
16843                 (struct cmd_config_per_port_rx_offload_result,
16844                  rx_offload, "rx_offload");
16845 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16846         TOKEN_STRING_INITIALIZER
16847                 (struct cmd_config_per_port_rx_offload_result,
16848                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16849                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16850                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16851                            "crc_strip#scatter#timestamp#security");
16852 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16853         TOKEN_STRING_INITIALIZER
16854                 (struct cmd_config_per_port_rx_offload_result,
16855                  on_off, "on#off");
16856
16857 static uint64_t
16858 search_rx_offload(const char *name)
16859 {
16860         uint64_t single_offload;
16861         const char *single_name;
16862         int found = 0;
16863         unsigned int bit;
16864
16865         single_offload = 1;
16866         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16867                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16868                 if (!strcasecmp(single_name, name)) {
16869                         found = 1;
16870                         break;
16871                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16872                         break;
16873                 else if (single_name == NULL)
16874                         break;
16875                 single_offload <<= 1;
16876         }
16877
16878         if (found)
16879                 return single_offload;
16880
16881         return 0;
16882 }
16883
16884 static void
16885 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16886                                 __attribute__((unused)) struct cmdline *cl,
16887                                 __attribute__((unused)) void *data)
16888 {
16889         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16890         portid_t port_id = res->port_id;
16891         struct rte_eth_dev_info dev_info;
16892         struct rte_port *port = &ports[port_id];
16893         uint64_t single_offload;
16894         uint16_t nb_rx_queues;
16895         int q;
16896
16897         if (port->port_status != RTE_PORT_STOPPED) {
16898                 printf("Error: Can't config offload when Port %d "
16899                        "is not stopped\n", port_id);
16900                 return;
16901         }
16902
16903         single_offload = search_rx_offload(res->offload);
16904         if (single_offload == 0) {
16905                 printf("Unknown offload name: %s\n", res->offload);
16906                 return;
16907         }
16908
16909         rte_eth_dev_info_get(port_id, &dev_info);
16910         nb_rx_queues = dev_info.nb_rx_queues;
16911         if (!strcmp(res->on_off, "on")) {
16912                 port->dev_conf.rxmode.offloads |= single_offload;
16913                 for (q = 0; q < nb_rx_queues; q++)
16914                         port->rx_conf[q].offloads |= single_offload;
16915         } else {
16916                 port->dev_conf.rxmode.offloads &= ~single_offload;
16917                 for (q = 0; q < nb_rx_queues; q++)
16918                         port->rx_conf[q].offloads &= ~single_offload;
16919         }
16920
16921         cmd_reconfig_device_queue(port_id, 1, 1);
16922 }
16923
16924 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16925         .f = cmd_config_per_port_rx_offload_parsed,
16926         .data = NULL,
16927         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16928                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16929                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16930                     "jumbo_frame|crc_strip|scatter|timestamp|security "
16931                     "on|off",
16932         .tokens = {
16933                 (void *)&cmd_config_per_port_rx_offload_result_port,
16934                 (void *)&cmd_config_per_port_rx_offload_result_config,
16935                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16936                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16937                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16938                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16939                 NULL,
16940         }
16941 };
16942
16943 /* Enable/Disable a per queue offloading */
16944 struct cmd_config_per_queue_rx_offload_result {
16945         cmdline_fixed_string_t port;
16946         portid_t port_id;
16947         cmdline_fixed_string_t rxq;
16948         uint16_t queue_id;
16949         cmdline_fixed_string_t rx_offload;
16950         cmdline_fixed_string_t offload;
16951         cmdline_fixed_string_t on_off;
16952 };
16953
16954 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16955         TOKEN_STRING_INITIALIZER
16956                 (struct cmd_config_per_queue_rx_offload_result,
16957                  port, "port");
16958 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16959         TOKEN_NUM_INITIALIZER
16960                 (struct cmd_config_per_queue_rx_offload_result,
16961                  port_id, UINT16);
16962 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16963         TOKEN_STRING_INITIALIZER
16964                 (struct cmd_config_per_queue_rx_offload_result,
16965                  rxq, "rxq");
16966 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16967         TOKEN_NUM_INITIALIZER
16968                 (struct cmd_config_per_queue_rx_offload_result,
16969                  queue_id, UINT16);
16970 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16971         TOKEN_STRING_INITIALIZER
16972                 (struct cmd_config_per_queue_rx_offload_result,
16973                  rx_offload, "rx_offload");
16974 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16975         TOKEN_STRING_INITIALIZER
16976                 (struct cmd_config_per_queue_rx_offload_result,
16977                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16978                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16979                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16980                            "crc_strip#scatter#timestamp#security");
16981 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16982         TOKEN_STRING_INITIALIZER
16983                 (struct cmd_config_per_queue_rx_offload_result,
16984                  on_off, "on#off");
16985
16986 static void
16987 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16988                                 __attribute__((unused)) struct cmdline *cl,
16989                                 __attribute__((unused)) void *data)
16990 {
16991         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16992         struct rte_eth_dev_info dev_info;
16993         portid_t port_id = res->port_id;
16994         uint16_t queue_id = res->queue_id;
16995         struct rte_port *port = &ports[port_id];
16996         uint64_t single_offload;
16997
16998         if (port->port_status != RTE_PORT_STOPPED) {
16999                 printf("Error: Can't config offload when Port %d "
17000                        "is not stopped\n", port_id);
17001                 return;
17002         }
17003
17004         rte_eth_dev_info_get(port_id, &dev_info);
17005         if (queue_id >= dev_info.nb_rx_queues) {
17006                 printf("Error: input queue_id should be 0 ... "
17007                        "%d\n", dev_info.nb_rx_queues - 1);
17008                 return;
17009         }
17010
17011         single_offload = search_rx_offload(res->offload);
17012         if (single_offload == 0) {
17013                 printf("Unknown offload name: %s\n", res->offload);
17014                 return;
17015         }
17016
17017         if (!strcmp(res->on_off, "on"))
17018                 port->rx_conf[queue_id].offloads |= single_offload;
17019         else
17020                 port->rx_conf[queue_id].offloads &= ~single_offload;
17021
17022         cmd_reconfig_device_queue(port_id, 1, 1);
17023 }
17024
17025 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17026         .f = cmd_config_per_queue_rx_offload_parsed,
17027         .data = NULL,
17028         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17029                     "vlan_strip|ipv4_cksum|"
17030                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17031                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17032                     "jumbo_frame|crc_strip|scatter|timestamp|security "
17033                     "on|off",
17034         .tokens = {
17035                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17036                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17037                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17038                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17039                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17040                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17041                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17042                 NULL,
17043         }
17044 };
17045
17046 /* Get Tx offloads capabilities */
17047 struct cmd_tx_offload_get_capa_result {
17048         cmdline_fixed_string_t show;
17049         cmdline_fixed_string_t port;
17050         portid_t port_id;
17051         cmdline_fixed_string_t tx_offload;
17052         cmdline_fixed_string_t capabilities;
17053 };
17054
17055 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17056         TOKEN_STRING_INITIALIZER
17057                 (struct cmd_tx_offload_get_capa_result,
17058                  show, "show");
17059 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17060         TOKEN_STRING_INITIALIZER
17061                 (struct cmd_tx_offload_get_capa_result,
17062                  port, "port");
17063 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17064         TOKEN_NUM_INITIALIZER
17065                 (struct cmd_tx_offload_get_capa_result,
17066                  port_id, UINT16);
17067 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17068         TOKEN_STRING_INITIALIZER
17069                 (struct cmd_tx_offload_get_capa_result,
17070                  tx_offload, "tx_offload");
17071 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17072         TOKEN_STRING_INITIALIZER
17073                 (struct cmd_tx_offload_get_capa_result,
17074                  capabilities, "capabilities");
17075
17076 static void
17077 print_tx_offloads(uint64_t offloads)
17078 {
17079         uint64_t single_offload;
17080         int begin;
17081         int end;
17082         int bit;
17083
17084         if (offloads == 0)
17085                 return;
17086
17087         begin = __builtin_ctzll(offloads);
17088         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17089
17090         single_offload = 1 << begin;
17091         for (bit = begin; bit < end; bit++) {
17092                 if (offloads & single_offload)
17093                         printf(" %s",
17094                                rte_eth_dev_tx_offload_name(single_offload));
17095                 single_offload <<= 1;
17096         }
17097 }
17098
17099 static void
17100 cmd_tx_offload_get_capa_parsed(
17101         void *parsed_result,
17102         __attribute__((unused)) struct cmdline *cl,
17103         __attribute__((unused)) void *data)
17104 {
17105         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17106         struct rte_eth_dev_info dev_info;
17107         portid_t port_id = res->port_id;
17108         uint64_t queue_offloads;
17109         uint64_t port_offloads;
17110
17111         rte_eth_dev_info_get(port_id, &dev_info);
17112         queue_offloads = dev_info.tx_queue_offload_capa;
17113         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17114
17115         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17116         printf("  Per Queue :");
17117         print_tx_offloads(queue_offloads);
17118
17119         printf("\n");
17120         printf("  Per Port  :");
17121         print_tx_offloads(port_offloads);
17122         printf("\n\n");
17123 }
17124
17125 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17126         .f = cmd_tx_offload_get_capa_parsed,
17127         .data = NULL,
17128         .help_str = "show port <port_id> tx_offload capabilities",
17129         .tokens = {
17130                 (void *)&cmd_tx_offload_get_capa_show,
17131                 (void *)&cmd_tx_offload_get_capa_port,
17132                 (void *)&cmd_tx_offload_get_capa_port_id,
17133                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17134                 (void *)&cmd_tx_offload_get_capa_capabilities,
17135                 NULL,
17136         }
17137 };
17138
17139 /* Get Tx offloads configuration */
17140 struct cmd_tx_offload_get_configuration_result {
17141         cmdline_fixed_string_t show;
17142         cmdline_fixed_string_t port;
17143         portid_t port_id;
17144         cmdline_fixed_string_t tx_offload;
17145         cmdline_fixed_string_t configuration;
17146 };
17147
17148 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17149         TOKEN_STRING_INITIALIZER
17150                 (struct cmd_tx_offload_get_configuration_result,
17151                  show, "show");
17152 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17153         TOKEN_STRING_INITIALIZER
17154                 (struct cmd_tx_offload_get_configuration_result,
17155                  port, "port");
17156 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17157         TOKEN_NUM_INITIALIZER
17158                 (struct cmd_tx_offload_get_configuration_result,
17159                  port_id, UINT16);
17160 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17161         TOKEN_STRING_INITIALIZER
17162                 (struct cmd_tx_offload_get_configuration_result,
17163                  tx_offload, "tx_offload");
17164 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17165         TOKEN_STRING_INITIALIZER
17166                 (struct cmd_tx_offload_get_configuration_result,
17167                  configuration, "configuration");
17168
17169 static void
17170 cmd_tx_offload_get_configuration_parsed(
17171         void *parsed_result,
17172         __attribute__((unused)) struct cmdline *cl,
17173         __attribute__((unused)) void *data)
17174 {
17175         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17176         struct rte_eth_dev_info dev_info;
17177         portid_t port_id = res->port_id;
17178         struct rte_port *port = &ports[port_id];
17179         uint64_t port_offloads;
17180         uint64_t queue_offloads;
17181         uint16_t nb_tx_queues;
17182         int q;
17183
17184         printf("Tx Offloading Configuration of port %d :\n", port_id);
17185
17186         port_offloads = port->dev_conf.txmode.offloads;
17187         printf("  Port :");
17188         print_tx_offloads(port_offloads);
17189         printf("\n");
17190
17191         rte_eth_dev_info_get(port_id, &dev_info);
17192         nb_tx_queues = dev_info.nb_tx_queues;
17193         for (q = 0; q < nb_tx_queues; q++) {
17194                 queue_offloads = port->tx_conf[q].offloads;
17195                 printf("  Queue[%2d] :", q);
17196                 print_tx_offloads(queue_offloads);
17197                 printf("\n");
17198         }
17199         printf("\n");
17200 }
17201
17202 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17203         .f = cmd_tx_offload_get_configuration_parsed,
17204         .data = NULL,
17205         .help_str = "show port <port_id> tx_offload configuration",
17206         .tokens = {
17207                 (void *)&cmd_tx_offload_get_configuration_show,
17208                 (void *)&cmd_tx_offload_get_configuration_port,
17209                 (void *)&cmd_tx_offload_get_configuration_port_id,
17210                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17211                 (void *)&cmd_tx_offload_get_configuration_configuration,
17212                 NULL,
17213         }
17214 };
17215
17216 /* Enable/Disable a per port offloading */
17217 struct cmd_config_per_port_tx_offload_result {
17218         cmdline_fixed_string_t port;
17219         cmdline_fixed_string_t config;
17220         portid_t port_id;
17221         cmdline_fixed_string_t tx_offload;
17222         cmdline_fixed_string_t offload;
17223         cmdline_fixed_string_t on_off;
17224 };
17225
17226 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17227         TOKEN_STRING_INITIALIZER
17228                 (struct cmd_config_per_port_tx_offload_result,
17229                  port, "port");
17230 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17231         TOKEN_STRING_INITIALIZER
17232                 (struct cmd_config_per_port_tx_offload_result,
17233                  config, "config");
17234 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17235         TOKEN_NUM_INITIALIZER
17236                 (struct cmd_config_per_port_tx_offload_result,
17237                  port_id, UINT16);
17238 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17239         TOKEN_STRING_INITIALIZER
17240                 (struct cmd_config_per_port_tx_offload_result,
17241                  tx_offload, "tx_offload");
17242 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17243         TOKEN_STRING_INITIALIZER
17244                 (struct cmd_config_per_port_tx_offload_result,
17245                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17246                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17247                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17248                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17249                           "mt_lockfree#multi_segs#fast_free#security");
17250 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17251         TOKEN_STRING_INITIALIZER
17252                 (struct cmd_config_per_port_tx_offload_result,
17253                  on_off, "on#off");
17254
17255 static uint64_t
17256 search_tx_offload(const char *name)
17257 {
17258         uint64_t single_offload;
17259         const char *single_name;
17260         int found = 0;
17261         unsigned int bit;
17262
17263         single_offload = 1;
17264         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17265                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17266                 if (!strcasecmp(single_name, name)) {
17267                         found = 1;
17268                         break;
17269                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17270                         break;
17271                 else if (single_name == NULL)
17272                         break;
17273                 single_offload <<= 1;
17274         }
17275
17276         if (found)
17277                 return single_offload;
17278
17279         return 0;
17280 }
17281
17282 static void
17283 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17284                                 __attribute__((unused)) struct cmdline *cl,
17285                                 __attribute__((unused)) void *data)
17286 {
17287         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17288         portid_t port_id = res->port_id;
17289         struct rte_eth_dev_info dev_info;
17290         struct rte_port *port = &ports[port_id];
17291         uint64_t single_offload;
17292         uint16_t nb_tx_queues;
17293         int q;
17294
17295         if (port->port_status != RTE_PORT_STOPPED) {
17296                 printf("Error: Can't config offload when Port %d "
17297                        "is not stopped\n", port_id);
17298                 return;
17299         }
17300
17301         single_offload = search_tx_offload(res->offload);
17302         if (single_offload == 0) {
17303                 printf("Unknown offload name: %s\n", res->offload);
17304                 return;
17305         }
17306
17307         rte_eth_dev_info_get(port_id, &dev_info);
17308         nb_tx_queues = dev_info.nb_tx_queues;
17309         if (!strcmp(res->on_off, "on")) {
17310                 port->dev_conf.txmode.offloads |= single_offload;
17311                 for (q = 0; q < nb_tx_queues; q++)
17312                         port->tx_conf[q].offloads |= single_offload;
17313         } else {
17314                 port->dev_conf.txmode.offloads &= ~single_offload;
17315                 for (q = 0; q < nb_tx_queues; q++)
17316                         port->tx_conf[q].offloads &= ~single_offload;
17317         }
17318
17319         cmd_reconfig_device_queue(port_id, 1, 1);
17320 }
17321
17322 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17323         .f = cmd_config_per_port_tx_offload_parsed,
17324         .data = NULL,
17325         .help_str = "port config <port_id> tx_offload "
17326                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17327                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17328                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17329                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17330                     "mt_lockfree|multi_segs|fast_free|security "
17331                     "on|off",
17332         .tokens = {
17333                 (void *)&cmd_config_per_port_tx_offload_result_port,
17334                 (void *)&cmd_config_per_port_tx_offload_result_config,
17335                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17336                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17337                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17338                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17339                 NULL,
17340         }
17341 };
17342
17343 /* Enable/Disable a per queue offloading */
17344 struct cmd_config_per_queue_tx_offload_result {
17345         cmdline_fixed_string_t port;
17346         portid_t port_id;
17347         cmdline_fixed_string_t txq;
17348         uint16_t queue_id;
17349         cmdline_fixed_string_t tx_offload;
17350         cmdline_fixed_string_t offload;
17351         cmdline_fixed_string_t on_off;
17352 };
17353
17354 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17355         TOKEN_STRING_INITIALIZER
17356                 (struct cmd_config_per_queue_tx_offload_result,
17357                  port, "port");
17358 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17359         TOKEN_NUM_INITIALIZER
17360                 (struct cmd_config_per_queue_tx_offload_result,
17361                  port_id, UINT16);
17362 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17363         TOKEN_STRING_INITIALIZER
17364                 (struct cmd_config_per_queue_tx_offload_result,
17365                  txq, "txq");
17366 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17367         TOKEN_NUM_INITIALIZER
17368                 (struct cmd_config_per_queue_tx_offload_result,
17369                  queue_id, UINT16);
17370 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17371         TOKEN_STRING_INITIALIZER
17372                 (struct cmd_config_per_queue_tx_offload_result,
17373                  tx_offload, "tx_offload");
17374 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17375         TOKEN_STRING_INITIALIZER
17376                 (struct cmd_config_per_queue_tx_offload_result,
17377                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17378                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17379                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17380                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17381                           "mt_lockfree#multi_segs#fast_free#security");
17382 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17383         TOKEN_STRING_INITIALIZER
17384                 (struct cmd_config_per_queue_tx_offload_result,
17385                  on_off, "on#off");
17386
17387 static void
17388 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17389                                 __attribute__((unused)) struct cmdline *cl,
17390                                 __attribute__((unused)) void *data)
17391 {
17392         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17393         struct rte_eth_dev_info dev_info;
17394         portid_t port_id = res->port_id;
17395         uint16_t queue_id = res->queue_id;
17396         struct rte_port *port = &ports[port_id];
17397         uint64_t single_offload;
17398
17399         if (port->port_status != RTE_PORT_STOPPED) {
17400                 printf("Error: Can't config offload when Port %d "
17401                        "is not stopped\n", port_id);
17402                 return;
17403         }
17404
17405         rte_eth_dev_info_get(port_id, &dev_info);
17406         if (queue_id >= dev_info.nb_tx_queues) {
17407                 printf("Error: input queue_id should be 0 ... "
17408                        "%d\n", dev_info.nb_tx_queues - 1);
17409                 return;
17410         }
17411
17412         single_offload = search_tx_offload(res->offload);
17413         if (single_offload == 0) {
17414                 printf("Unknown offload name: %s\n", res->offload);
17415                 return;
17416         }
17417
17418         if (!strcmp(res->on_off, "on"))
17419                 port->tx_conf[queue_id].offloads |= single_offload;
17420         else
17421                 port->tx_conf[queue_id].offloads &= ~single_offload;
17422
17423         cmd_reconfig_device_queue(port_id, 1, 1);
17424 }
17425
17426 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17427         .f = cmd_config_per_queue_tx_offload_parsed,
17428         .data = NULL,
17429         .help_str = "port <port_id> txq <queue_id> tx_offload "
17430                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17431                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17432                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17433                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17434                     "mt_lockfree|multi_segs|fast_free|security "
17435                     "on|off",
17436         .tokens = {
17437                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17438                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17439                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17440                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17441                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17442                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17443                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17444                 NULL,
17445         }
17446 };
17447
17448 /* ******************************************************************************** */
17449
17450 /* list of instructions */
17451 cmdline_parse_ctx_t main_ctx[] = {
17452         (cmdline_parse_inst_t *)&cmd_help_brief,
17453         (cmdline_parse_inst_t *)&cmd_help_long,
17454         (cmdline_parse_inst_t *)&cmd_quit,
17455         (cmdline_parse_inst_t *)&cmd_load_from_file,
17456         (cmdline_parse_inst_t *)&cmd_showport,
17457         (cmdline_parse_inst_t *)&cmd_showqueue,
17458         (cmdline_parse_inst_t *)&cmd_showportall,
17459         (cmdline_parse_inst_t *)&cmd_showcfg,
17460         (cmdline_parse_inst_t *)&cmd_start,
17461         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17462         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17463         (cmdline_parse_inst_t *)&cmd_set_link_up,
17464         (cmdline_parse_inst_t *)&cmd_set_link_down,
17465         (cmdline_parse_inst_t *)&cmd_reset,
17466         (cmdline_parse_inst_t *)&cmd_set_numbers,
17467         (cmdline_parse_inst_t *)&cmd_set_log,
17468         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17469         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17470         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17471         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17472         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17473         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17474         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17475         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17476         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17477         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17478         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17479         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17480         (cmdline_parse_inst_t *)&cmd_set_link_check,
17481         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17482         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17483         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17484         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17485 #ifdef RTE_LIBRTE_PMD_BOND
17486         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17487         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17488         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17489         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17490         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17491         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17492         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17493         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17494         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17495         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17496         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17497 #endif
17498         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17499         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17500         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17501         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17502         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17503         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17504         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17505         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17506         (cmdline_parse_inst_t *)&cmd_csum_set,
17507         (cmdline_parse_inst_t *)&cmd_csum_show,
17508         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17509         (cmdline_parse_inst_t *)&cmd_tso_set,
17510         (cmdline_parse_inst_t *)&cmd_tso_show,
17511         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17512         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17513         (cmdline_parse_inst_t *)&cmd_gro_enable,
17514         (cmdline_parse_inst_t *)&cmd_gro_flush,
17515         (cmdline_parse_inst_t *)&cmd_gro_show,
17516         (cmdline_parse_inst_t *)&cmd_gso_enable,
17517         (cmdline_parse_inst_t *)&cmd_gso_size,
17518         (cmdline_parse_inst_t *)&cmd_gso_show,
17519         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17520         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17521         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17522         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17523         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17524         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17525         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17526         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17527         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17528         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17529         (cmdline_parse_inst_t *)&cmd_config_dcb,
17530         (cmdline_parse_inst_t *)&cmd_read_reg,
17531         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17532         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17533         (cmdline_parse_inst_t *)&cmd_write_reg,
17534         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17535         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17536         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17537         (cmdline_parse_inst_t *)&cmd_stop,
17538         (cmdline_parse_inst_t *)&cmd_mac_addr,
17539         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17540         (cmdline_parse_inst_t *)&cmd_set_qmap,
17541         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17542         (cmdline_parse_inst_t *)&cmd_operate_port,
17543         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17544         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17545         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17546         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17547         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17548         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17549         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17550         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17551         (cmdline_parse_inst_t *)&cmd_config_mtu,
17552         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17553         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17554         (cmdline_parse_inst_t *)&cmd_config_rss,
17555         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17556         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17557         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17558         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17559         (cmdline_parse_inst_t *)&cmd_showport_reta,
17560         (cmdline_parse_inst_t *)&cmd_config_burst,
17561         (cmdline_parse_inst_t *)&cmd_config_thresh,
17562         (cmdline_parse_inst_t *)&cmd_config_threshold,
17563         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17564         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17565         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17566         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
17567         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17568         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
17569         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17570         (cmdline_parse_inst_t *)&cmd_global_config,
17571         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17572         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17573         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17574         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17575         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17576         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17577         (cmdline_parse_inst_t *)&cmd_dump,
17578         (cmdline_parse_inst_t *)&cmd_dump_one,
17579         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
17580         (cmdline_parse_inst_t *)&cmd_syn_filter,
17581         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
17582         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
17583         (cmdline_parse_inst_t *)&cmd_flex_filter,
17584         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
17585         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
17586         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
17587         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
17588         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
17589         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
17590         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17591         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
17592         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17593         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17594         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17595         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
17596         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17597         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
17598         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
17599         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
17600         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
17601         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
17602         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
17603         (cmdline_parse_inst_t *)&cmd_flow,
17604         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17605         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17606         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17607         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17608         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17609         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17610         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17611         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17612         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17613         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17614         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
17615         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17616         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17617         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17618         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
17619         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
17620         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
17621         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
17622         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
17623         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
17624         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
17625         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
17626         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
17627         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
17628         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17629         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17630         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17631         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17632         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17633         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17634         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17635         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17636         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17637         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17638         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17639         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17640         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17641         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17642         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17643         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17644         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17645         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17646         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17647         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17648         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17649         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17650         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17651         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17652         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17653 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
17654         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
17655 #endif
17656         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17657         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17658         (cmdline_parse_inst_t *)&cmd_ddp_add,
17659         (cmdline_parse_inst_t *)&cmd_ddp_del,
17660         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17661         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17662         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17663         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17664         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17665         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17666         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17667         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17668         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17669         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17670
17671         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17672         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17673         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17674         (cmdline_parse_inst_t *)&cmd_queue_region,
17675         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17676         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17677         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17678         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17679         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17680         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17681         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17682         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17683         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17684         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17685         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17686         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17687         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17688         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17689         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17690         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17691         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17692         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17693         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17694         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17695         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17696         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17697         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17698         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17699         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17700         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17701         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17702         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17703         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17704         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17705         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17706         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17707 #ifdef RTE_LIBRTE_BPF
17708         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17709         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17710 #endif
17711         NULL,
17712 };
17713
17714 /* read cmdline commands from file */
17715 void
17716 cmdline_read_from_file(const char *filename)
17717 {
17718         struct cmdline *cl;
17719
17720         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17721         if (cl == NULL) {
17722                 printf("Failed to create file based cmdline context: %s\n",
17723                        filename);
17724                 return;
17725         }
17726
17727         cmdline_interact(cl);
17728         cmdline_quit(cl);
17729
17730         cmdline_free(cl);
17731
17732         printf("Read CLI commands from %s\n", filename);
17733 }
17734
17735 /* prompt function, called from main on MASTER lcore */
17736 void
17737 prompt(void)
17738 {
17739         int status;
17740
17741         /* initialize non-constant commands */
17742         cmd_set_fwd_mode_init();
17743         cmd_set_fwd_retry_mode_init();
17744
17745 #if defined RTE_LIBRTE_PMD_SOFTNIC
17746         portid_t softnic_portid, pid;
17747         uint8_t softnic_enable = 0;
17748
17749         if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
17750                 RTE_ETH_FOREACH_DEV(pid) {
17751                         struct rte_port *port = &ports[pid];
17752                         const char *driver = port->dev_info.driver_name;
17753
17754                         if (strcmp(driver, "net_softnic") == 0) {
17755                                 softnic_portid = pid;
17756                                 softnic_enable = 1;
17757                                 break;
17758                         }
17759                 }
17760         }
17761 #endif
17762
17763         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17764         if (testpmd_cl == NULL)
17765                 return;
17766
17767         for (;;) {
17768                 status = cmdline_poll(testpmd_cl);
17769                 if (status < 0)
17770                         rte_panic("CLI poll error (%" PRId32 ")\n", status);
17771                 else if (status == RDLINE_EXITED) {
17772                         cmdline_stdin_exit(testpmd_cl);
17773                         rte_exit(0, "\n");
17774                 }
17775
17776 #if defined RTE_LIBRTE_PMD_SOFTNIC
17777
17778         if ((softnic_enable == 1) &&
17779                 (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0))
17780                 rte_pmd_softnic_manage(softnic_portid);
17781 #endif
17782         }
17783 }
17784
17785 void
17786 prompt_exit(void)
17787 {
17788         if (testpmd_cl != NULL)
17789                 cmdline_quit(testpmd_cl);
17790 }
17791
17792 static void
17793 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17794 {
17795         if (id == (portid_t)RTE_PORT_ALL) {
17796                 portid_t pid;
17797
17798                 RTE_ETH_FOREACH_DEV(pid) {
17799                         /* check if need_reconfig has been set to 1 */
17800                         if (ports[pid].need_reconfig == 0)
17801                                 ports[pid].need_reconfig = dev;
17802                         /* check if need_reconfig_queues has been set to 1 */
17803                         if (ports[pid].need_reconfig_queues == 0)
17804                                 ports[pid].need_reconfig_queues = queue;
17805                 }
17806         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17807                 /* check if need_reconfig has been set to 1 */
17808                 if (ports[id].need_reconfig == 0)
17809                         ports[id].need_reconfig = dev;
17810                 /* check if need_reconfig_queues has been set to 1 */
17811                 if (ports[id].need_reconfig_queues == 0)
17812                         ports[id].need_reconfig_queues = queue;
17813         }
17814 }