app/testpmd: move VXLAN/NVGRE help in filters section
[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_flow.h>
48 #include <rte_gro.h>
49
50 #include <cmdline_rdline.h>
51 #include <cmdline_parse.h>
52 #include <cmdline_parse_num.h>
53 #include <cmdline_parse_string.h>
54 #include <cmdline_parse_ipaddr.h>
55 #include <cmdline_parse_etheraddr.h>
56 #include <cmdline_socket.h>
57 #include <cmdline.h>
58 #ifdef RTE_LIBRTE_PMD_BOND
59 #include <rte_eth_bond.h>
60 #include <rte_eth_bond_8023ad.h>
61 #endif
62 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
63 #include <rte_pmd_dpaa.h>
64 #endif
65 #ifdef RTE_LIBRTE_IXGBE_PMD
66 #include <rte_pmd_ixgbe.h>
67 #endif
68 #ifdef RTE_LIBRTE_I40E_PMD
69 #include <rte_pmd_i40e.h>
70 #endif
71 #ifdef RTE_LIBRTE_BNXT_PMD
72 #include <rte_pmd_bnxt.h>
73 #endif
74 #include "testpmd.h"
75 #include "cmdline_mtr.h"
76 #include "cmdline_tm.h"
77 #include "bpf_cmd.h"
78
79 static struct cmdline *testpmd_cl;
80
81 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
82
83 /* *** Help command with introduction. *** */
84 struct cmd_help_brief_result {
85         cmdline_fixed_string_t help;
86 };
87
88 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
89                                   struct cmdline *cl,
90                                   __attribute__((unused)) void *data)
91 {
92         cmdline_printf(
93                 cl,
94                 "\n"
95                 "Help is available for the following sections:\n\n"
96                 "    help control                    : Start and stop forwarding.\n"
97                 "    help display                    : Displaying port, stats and config "
98                 "information.\n"
99                 "    help config                     : Configuration information.\n"
100                 "    help ports                      : Configuring ports.\n"
101                 "    help registers                  : Reading and setting port registers.\n"
102                 "    help filters                    : Filters configuration help.\n"
103                 "    help traffic_management         : Traffic Management commmands.\n"
104                 "    help all                        : All of the above sections.\n\n"
105         );
106
107 }
108
109 cmdline_parse_token_string_t cmd_help_brief_help =
110         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
111
112 cmdline_parse_inst_t cmd_help_brief = {
113         .f = cmd_help_brief_parsed,
114         .data = NULL,
115         .help_str = "help: Show help",
116         .tokens = {
117                 (void *)&cmd_help_brief_help,
118                 NULL,
119         },
120 };
121
122 /* *** Help command with help sections. *** */
123 struct cmd_help_long_result {
124         cmdline_fixed_string_t help;
125         cmdline_fixed_string_t section;
126 };
127
128 static void cmd_help_long_parsed(void *parsed_result,
129                                  struct cmdline *cl,
130                                  __attribute__((unused)) void *data)
131 {
132         int show_all = 0;
133         struct cmd_help_long_result *res = parsed_result;
134
135         if (!strcmp(res->section, "all"))
136                 show_all = 1;
137
138         if (show_all || !strcmp(res->section, "control")) {
139
140                 cmdline_printf(
141                         cl,
142                         "\n"
143                         "Control forwarding:\n"
144                         "-------------------\n\n"
145
146                         "start\n"
147                         "    Start packet forwarding with current configuration.\n\n"
148
149                         "start tx_first\n"
150                         "    Start packet forwarding with current config"
151                         " after sending one burst of packets.\n\n"
152
153                         "stop\n"
154                         "    Stop packet forwarding, and display accumulated"
155                         " statistics.\n\n"
156
157                         "quit\n"
158                         "    Quit to prompt.\n\n"
159                 );
160         }
161
162         if (show_all || !strcmp(res->section, "display")) {
163
164                 cmdline_printf(
165                         cl,
166                         "\n"
167                         "Display:\n"
168                         "--------\n\n"
169
170                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
171                         "    Display information for port_id, or all.\n\n"
172
173                         "show port X rss reta (size) (mask0,mask1,...)\n"
174                         "    Display the rss redirection table entry indicated"
175                         " by masks on port X. size is used to indicate the"
176                         " hardware supported reta size\n\n"
177
178                         "show port (port_id) rss-hash [key]\n"
179                         "    Display the RSS hash functions and RSS hash key of port\n\n"
180
181                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
182                         "    Clear information for port_id, or all.\n\n"
183
184                         "show (rxq|txq) info (port_id) (queue_id)\n"
185                         "    Display information for configured RX/TX queue.\n\n"
186
187                         "show config (rxtx|cores|fwd|txpkts)\n"
188                         "    Display the given configuration.\n\n"
189
190                         "read rxd (port_id) (queue_id) (rxd_id)\n"
191                         "    Display an RX descriptor of a port RX queue.\n\n"
192
193                         "read txd (port_id) (queue_id) (txd_id)\n"
194                         "    Display a TX descriptor of a port TX queue.\n\n"
195
196                         "ddp get list (port_id)\n"
197                         "    Get ddp profile info list\n\n"
198
199                         "ddp get info (profile_path)\n"
200                         "    Get ddp profile information.\n\n"
201
202                         "show vf stats (port_id) (vf_id)\n"
203                         "    Display a VF's statistics.\n\n"
204
205                         "clear vf stats (port_id) (vf_id)\n"
206                         "    Reset a VF's statistics.\n\n"
207
208                         "show port (port_id) pctype mapping\n"
209                         "    Get flow ptype to pctype mapping on a port\n\n"
210
211                         "show port meter stats (port_id) (meter_id) (clear)\n"
212                         "    Get meter stats on a port\n\n"
213
214                         "show fwd stats all\n"
215                         "    Display statistics for all fwd engines.\n\n"
216
217                         "clear fwd stats all\n"
218                         "    Clear statistics for all fwd engines.\n\n"
219
220                         "show port (port_id) rx_offload capabilities\n"
221                         "    List all per queue and per port Rx offloading"
222                         " capabilities of a port\n\n"
223
224                         "show port (port_id) rx_offload configuration\n"
225                         "    List port level and all queue level"
226                         " Rx offloading configuration\n\n"
227
228                         "show port (port_id) tx_offload capabilities\n"
229                         "    List all per queue and per port"
230                         " Tx offloading capabilities of a port\n\n"
231
232                         "show port (port_id) tx_offload configuration\n"
233                         "    List port level and all queue level"
234                         " Tx offloading configuration\n\n"
235
236                         "show port (port_id) tx_metadata\n"
237                         "    Show Tx metadata value set"
238                         " for a specific port\n\n"
239                 );
240         }
241
242         if (show_all || !strcmp(res->section, "config")) {
243                 cmdline_printf(
244                         cl,
245                         "\n"
246                         "Configuration:\n"
247                         "--------------\n"
248                         "Configuration changes only become active when"
249                         " forwarding is started/restarted.\n\n"
250
251                         "set default\n"
252                         "    Reset forwarding to the default configuration.\n\n"
253
254                         "set verbose (level)\n"
255                         "    Set the debug verbosity level X.\n\n"
256
257                         "set log global|(type) (level)\n"
258                         "    Set the log level.\n\n"
259
260                         "set nbport (num)\n"
261                         "    Set number of ports.\n\n"
262
263                         "set nbcore (num)\n"
264                         "    Set number of cores.\n\n"
265
266                         "set coremask (mask)\n"
267                         "    Set the forwarding cores hexadecimal mask.\n\n"
268
269                         "set portmask (mask)\n"
270                         "    Set the forwarding ports hexadecimal mask.\n\n"
271
272                         "set burst (num)\n"
273                         "    Set number of packets per burst.\n\n"
274
275                         "set burst tx delay (microseconds) retry (num)\n"
276                         "    Set the transmit delay time and number of retries,"
277                         " effective when retry is enabled.\n\n"
278
279                         "set txpkts (x[,y]*)\n"
280                         "    Set the length of each segment of TXONLY"
281                         " and optionally CSUM packets.\n\n"
282
283                         "set txsplit (off|on|rand)\n"
284                         "    Set the split policy for the TX packets."
285                         " Right now only applicable for CSUM and TXONLY"
286                         " modes\n\n"
287
288                         "set corelist (x[,y]*)\n"
289                         "    Set the list of forwarding cores.\n\n"
290
291                         "set portlist (x[,y]*)\n"
292                         "    Set the list of forwarding ports.\n\n"
293
294                         "set port setup on (iterator|event)\n"
295                         "    Select how attached port is retrieved for setup.\n\n"
296
297                         "set tx loopback (port_id) (on|off)\n"
298                         "    Enable or disable tx loopback.\n\n"
299
300                         "set all queues drop (port_id) (on|off)\n"
301                         "    Set drop enable bit for all queues.\n\n"
302
303                         "set vf split drop (port_id) (vf_id) (on|off)\n"
304                         "    Set split drop enable bit for a VF from the PF.\n\n"
305
306                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
307                         "    Set MAC antispoof for a VF from the PF.\n\n"
308
309                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
310                         "    Enable MACsec offload.\n\n"
311
312                         "set macsec offload (port_id) off\n"
313                         "    Disable MACsec offload.\n\n"
314
315                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
316                         "    Configure MACsec secure connection (SC).\n\n"
317
318                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
319                         "    Configure MACsec secure association (SA).\n\n"
320
321                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
322                         "    Set VF broadcast for a VF from the PF.\n\n"
323
324                         "vlan set strip (on|off) (port_id)\n"
325                         "    Set the VLAN strip on a port.\n\n"
326
327                         "vlan set stripq (on|off) (port_id,queue_id)\n"
328                         "    Set the VLAN strip for a queue on a port.\n\n"
329
330                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
331                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
332
333                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
334                         "    Set VLAN insert for a VF from the PF.\n\n"
335
336                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
337                         "    Set VLAN antispoof for a VF from the PF.\n\n"
338
339                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
340                         "    Set VLAN tag for a VF from the PF.\n\n"
341
342                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
343                         "    Set a VF's max bandwidth(Mbps).\n\n"
344
345                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
346                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
347
348                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
349                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
350
351                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
352                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
353
354                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
355                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
356
357                         "vlan set filter (on|off) (port_id)\n"
358                         "    Set the VLAN filter on a port.\n\n"
359
360                         "vlan set qinq (on|off) (port_id)\n"
361                         "    Set the VLAN QinQ (extended queue in queue)"
362                         " on a port.\n\n"
363
364                         "vlan set (inner|outer) tpid (value) (port_id)\n"
365                         "    Set the VLAN TPID for Packet Filtering on"
366                         " a port\n\n"
367
368                         "rx_vlan add (vlan_id|all) (port_id)\n"
369                         "    Add a vlan_id, or all identifiers, to the set"
370                         " of VLAN identifiers filtered by port_id.\n\n"
371
372                         "rx_vlan rm (vlan_id|all) (port_id)\n"
373                         "    Remove a vlan_id, or all identifiers, from the set"
374                         " of VLAN identifiers filtered by port_id.\n\n"
375
376                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
377                         "    Add a vlan_id, to the set of VLAN identifiers"
378                         "filtered for VF(s) from port_id.\n\n"
379
380                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
381                         "    Remove a vlan_id, to the set of VLAN identifiers"
382                         "filtered for VF(s) from port_id.\n\n"
383
384                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
385                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
386                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
387                         "   add a tunnel filter of a port.\n\n"
388
389                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
390                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
391                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
392                         "   remove a tunnel filter of a port.\n\n"
393
394                         "rx_vxlan_port add (udp_port) (port_id)\n"
395                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
396
397                         "rx_vxlan_port rm (udp_port) (port_id)\n"
398                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
399
400                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
401                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
402                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
403
404                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
405                         "    Set port based TX VLAN insertion.\n\n"
406
407                         "tx_vlan reset (port_id)\n"
408                         "    Disable hardware insertion of a VLAN header in"
409                         " packets sent on a port.\n\n"
410
411                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
412                         "    Select hardware or software calculation of the"
413                         " checksum when transmitting a packet using the"
414                         " csum forward engine.\n"
415                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
416                         "    outer-ip concerns the outer IP layer in"
417                         "    outer-udp concerns the outer UDP layer in"
418                         " case the packet is recognized as a tunnel packet by"
419                         " the forward engine (vxlan, gre and ipip are supported)\n"
420                         "    Please check the NIC datasheet for HW limits.\n\n"
421
422                         "csum parse-tunnel (on|off) (tx_port_id)\n"
423                         "    If disabled, treat tunnel packets as non-tunneled"
424                         " packets (treat inner headers as payload). The port\n"
425                         "    argument is the port used for TX in csum forward"
426                         " engine.\n\n"
427
428                         "csum show (port_id)\n"
429                         "    Display tx checksum offload configuration\n\n"
430
431                         "tso set (segsize) (portid)\n"
432                         "    Enable TCP Segmentation Offload in csum forward"
433                         " engine.\n"
434                         "    Please check the NIC datasheet for HW limits.\n\n"
435
436                         "tso show (portid)"
437                         "    Display the status of TCP Segmentation Offload.\n\n"
438
439                         "set port (port_id) gro on|off\n"
440                         "    Enable or disable Generic Receive Offload in"
441                         " csum forwarding engine.\n\n"
442
443                         "show port (port_id) gro\n"
444                         "    Display GRO configuration.\n\n"
445
446                         "set gro flush (cycles)\n"
447                         "    Set the cycle to flush GROed packets from"
448                         " reassembly tables.\n\n"
449
450                         "set port (port_id) gso (on|off)"
451                         "    Enable or disable Generic Segmentation Offload in"
452                         " csum forwarding engine.\n\n"
453
454                         "set gso segsz (length)\n"
455                         "    Set max packet length for output GSO segments,"
456                         " including packet header and payload.\n\n"
457
458                         "show port (port_id) gso\n"
459                         "    Show GSO configuration.\n\n"
460
461                         "set fwd (%s)\n"
462                         "    Set packet forwarding mode.\n\n"
463
464                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
465                         "    Add a MAC address on port_id.\n\n"
466
467                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
468                         "    Remove a MAC address from port_id.\n\n"
469
470                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Set the default MAC address for port_id.\n\n"
472
473                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
474                         "    Add a MAC address for a VF on the port.\n\n"
475
476                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Set the MAC address for a VF from the PF.\n\n"
478
479                         "set eth-peer (port_id) (peer_addr)\n"
480                         "    set the peer address for certain port.\n\n"
481
482                         "set port (port_id) uta (mac_address|all) (on|off)\n"
483                         "    Add/Remove a or all unicast hash filter(s)"
484                         "from port X.\n\n"
485
486                         "set promisc (port_id|all) (on|off)\n"
487                         "    Set the promiscuous mode on port_id, or all.\n\n"
488
489                         "set allmulti (port_id|all) (on|off)\n"
490                         "    Set the allmulti mode on port_id, or all.\n\n"
491
492                         "set vf promisc (port_id) (vf_id) (on|off)\n"
493                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
494
495                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
496                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
497
498                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
499                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
500                         " (on|off) autoneg (on|off) (port_id)\n"
501                         "set flow_ctrl rx (on|off) (portid)\n"
502                         "set flow_ctrl tx (on|off) (portid)\n"
503                         "set flow_ctrl high_water (high_water) (portid)\n"
504                         "set flow_ctrl low_water (low_water) (portid)\n"
505                         "set flow_ctrl pause_time (pause_time) (portid)\n"
506                         "set flow_ctrl send_xon (send_xon) (portid)\n"
507                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
508                         "set flow_ctrl autoneg (on|off) (port_id)\n"
509                         "    Set the link flow control parameter on a port.\n\n"
510
511                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
512                         " (low_water) (pause_time) (priority) (port_id)\n"
513                         "    Set the priority flow control parameter on a"
514                         " port.\n\n"
515
516                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
517                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
518                         " queue on port.\n"
519                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
520                         " on port 0 to mapping 5.\n\n"
521
522                         "set xstats-hide-zero on|off\n"
523                         "    Set the option to hide the zero values"
524                         " for xstats display.\n"
525
526                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
527                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
528
529                         "set port (port_id) vf (vf_id) (mac_addr)"
530                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
531                         "   Add/Remove unicast or multicast MAC addr filter"
532                         " for a VF.\n\n"
533
534                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
535                         "|MPE) (on|off)\n"
536                         "    AUPE:accepts untagged VLAN;"
537                         "ROPE:accept unicast hash\n\n"
538                         "    BAM:accepts broadcast packets;"
539                         "MPE:accepts all multicast packets\n\n"
540                         "    Enable/Disable a VF receive mode of a port\n\n"
541
542                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
543                         "    Set rate limit for a queue of a port\n\n"
544
545                         "set port (port_id) vf (vf_id) rate (rate_num) "
546                         "queue_mask (queue_mask_value)\n"
547                         "    Set rate limit for queues in VF of a port\n\n"
548
549                         "set port (port_id) mirror-rule (rule_id)"
550                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
551                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
552                         "   Set pool or vlan type mirror rule on a port.\n"
553                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
554                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
555                         " to pool 0.\n\n"
556
557                         "set port (port_id) mirror-rule (rule_id)"
558                         " (uplink-mirror|downlink-mirror) dst-pool"
559                         " (pool_id) (on|off)\n"
560                         "   Set uplink or downlink type mirror rule on a port.\n"
561                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
562                         " 0 on' enable mirror income traffic to pool 0.\n\n"
563
564                         "reset port (port_id) mirror-rule (rule_id)\n"
565                         "   Reset a mirror rule.\n\n"
566
567                         "set flush_rx (on|off)\n"
568                         "   Flush (default) or don't flush RX streams before"
569                         " forwarding. Mainly used with PCAP drivers.\n\n"
570
571                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
572                         "   Set the bypass mode for the lowest port on bypass enabled"
573                         " NIC.\n\n"
574
575                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
576                         "mode (normal|bypass|isolate) (port_id)\n"
577                         "   Set the event required to initiate specified bypass mode for"
578                         " the lowest port on a bypass enabled NIC where:\n"
579                         "       timeout   = enable bypass after watchdog timeout.\n"
580                         "       os_on     = enable bypass when OS/board is powered on.\n"
581                         "       os_off    = enable bypass when OS/board is powered off.\n"
582                         "       power_on  = enable bypass when power supply is turned on.\n"
583                         "       power_off = enable bypass when power supply is turned off."
584                         "\n\n"
585
586                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
587                         "   Set the bypass watchdog timeout to 'n' seconds"
588                         " where 0 = instant.\n\n"
589
590                         "show bypass config (port_id)\n"
591                         "   Show the bypass configuration for a bypass enabled NIC"
592                         " using the lowest port on the NIC.\n\n"
593
594 #ifdef RTE_LIBRTE_PMD_BOND
595                         "create bonded device (mode) (socket)\n"
596                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
597
598                         "add bonding slave (slave_id) (port_id)\n"
599                         "       Add a slave device to a bonded device.\n\n"
600
601                         "remove bonding slave (slave_id) (port_id)\n"
602                         "       Remove a slave device from a bonded device.\n\n"
603
604                         "set bonding mode (value) (port_id)\n"
605                         "       Set the bonding mode on a bonded device.\n\n"
606
607                         "set bonding primary (slave_id) (port_id)\n"
608                         "       Set the primary slave for a bonded device.\n\n"
609
610                         "show bonding config (port_id)\n"
611                         "       Show the bonding config for port_id.\n\n"
612
613                         "set bonding mac_addr (port_id) (address)\n"
614                         "       Set the MAC address of a bonded device.\n\n"
615
616                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
617                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
618
619                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
620                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
621
622                         "set bonding mon_period (port_id) (value)\n"
623                         "       Set the bonding link status monitoring polling period in ms.\n\n"
624
625                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
626                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
627
628 #endif
629                         "set link-up port (port_id)\n"
630                         "       Set link up for a port.\n\n"
631
632                         "set link-down port (port_id)\n"
633                         "       Set link down for a port.\n\n"
634
635                         "E-tag set insertion on port-tag-id (value)"
636                         " port (port_id) vf (vf_id)\n"
637                         "    Enable E-tag insertion for a VF on a port\n\n"
638
639                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
640                         "    Disable E-tag insertion for a VF on a port\n\n"
641
642                         "E-tag set stripping (on|off) port (port_id)\n"
643                         "    Enable/disable E-tag stripping on a port\n\n"
644
645                         "E-tag set forwarding (on|off) port (port_id)\n"
646                         "    Enable/disable E-tag based forwarding"
647                         " on a port\n\n"
648
649                         "E-tag set filter add e-tag-id (value) dst-pool"
650                         " (pool_id) port (port_id)\n"
651                         "    Add an E-tag forwarding filter on a port\n\n"
652
653                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
654                         "    Delete an E-tag forwarding filter on a port\n\n"
655
656                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
657                         "    Load a profile package on a port\n\n"
658
659                         "ddp del (port_id) (backup_profile_path)\n"
660                         "    Delete a profile package from a port\n\n"
661
662                         "ptype mapping get (port_id) (valid_only)\n"
663                         "    Get ptype mapping on a port\n\n"
664
665                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
666                         "    Replace target with the pkt_type in ptype mapping\n\n"
667
668                         "ptype mapping reset (port_id)\n"
669                         "    Reset ptype mapping on a port\n\n"
670
671                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
672                         "    Update a ptype mapping item on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "queue_start_index (value) queue_num (value)\n"
676                         "    Set a queue region on a port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "flowtype (value)\n"
680                         "    Set a flowtype region index on a port\n\n"
681
682                         "set port (port_id) queue-region UP (value) region_id (value)\n"
683                         "    Set the mapping of User Priority to "
684                         "queue region on a port\n\n"
685
686                         "set port (port_id) queue-region flush (on|off)\n"
687                         "    flush all queue region related configuration\n\n"
688
689                         "show port meter cap (port_id)\n"
690                         "    Show port meter capability information\n\n"
691
692                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
693                         "    meter profile add - srtcm rfc 2697\n\n"
694
695                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
696                         "    meter profile add - trtcm rfc 2698\n\n"
697
698                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
699                         "    meter profile add - trtcm rfc 4115\n\n"
700
701                         "del port meter profile (port_id) (profile_id)\n"
702                         "    meter profile delete\n\n"
703
704                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
705                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
706                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
707                         "(dscp_tbl_entry63)]\n"
708                         "    meter create\n\n"
709
710                         "enable port meter (port_id) (mtr_id)\n"
711                         "    meter enable\n\n"
712
713                         "disable port meter (port_id) (mtr_id)\n"
714                         "    meter disable\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
723                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
724                         "    update meter dscp table entries\n\n"
725
726                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
727                         "(action0) [(action1) (action2)]\n"
728                         "    meter update policer action\n\n"
729
730                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
731                         "    meter update stats\n\n"
732
733                         "show port (port_id) queue-region\n"
734                         "    show all queue region related configuration info\n\n"
735
736                         , list_pkt_forwarding_modes()
737                 );
738         }
739
740         if (show_all || !strcmp(res->section, "ports")) {
741
742                 cmdline_printf(
743                         cl,
744                         "\n"
745                         "Port Operations:\n"
746                         "----------------\n\n"
747
748                         "port start (port_id|all)\n"
749                         "    Start all ports or port_id.\n\n"
750
751                         "port stop (port_id|all)\n"
752                         "    Stop all ports or port_id.\n\n"
753
754                         "port close (port_id|all)\n"
755                         "    Close all ports or port_id.\n\n"
756
757                         "port attach (ident)\n"
758                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
759
760                         "port detach (port_id)\n"
761                         "    Detach physical or virtual dev by port_id\n\n"
762
763                         "port config (port_id|all)"
764                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
765                         " duplex (half|full|auto)\n"
766                         "    Set speed and duplex for all ports or port_id\n\n"
767
768                         "port config (port_id|all) loopback (mode)\n"
769                         "    Set loopback mode for all ports or port_id\n\n"
770
771                         "port config all (rxq|txq|rxd|txd) (value)\n"
772                         "    Set number for rxq/txq/rxd/txd.\n\n"
773
774                         "port config all max-pkt-len (value)\n"
775                         "    Set the max packet length.\n\n"
776
777                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
778                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
779                         " (on|off)\n"
780                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
781                         " for ports.\n\n"
782
783                         "port config all rss (all|default|ip|tcp|udp|sctp|"
784                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
785                         "    Set the RSS mode.\n\n"
786
787                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
788                         "    Set the RSS redirection table.\n\n"
789
790                         "port config (port_id) dcb vt (on|off) (traffic_class)"
791                         " pfc (on|off)\n"
792                         "    Set the DCB mode.\n\n"
793
794                         "port config all burst (value)\n"
795                         "    Set the number of packets per burst.\n\n"
796
797                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
798                         " (value)\n"
799                         "    Set the ring prefetch/host/writeback threshold"
800                         " for tx/rx queue.\n\n"
801
802                         "port config all (txfreet|txrst|rxfreet) (value)\n"
803                         "    Set free threshold for rx/tx, or set"
804                         " tx rs bit threshold.\n\n"
805                         "port config mtu X value\n"
806                         "    Set the MTU of port X to a given value\n\n"
807
808                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
809                         "    Set a rx/tx queue's ring size configuration, the new"
810                         " value will take effect after command that (re-)start the port"
811                         " or command that setup the specific queue\n\n"
812
813                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
814                         "    Start/stop a rx/tx queue of port X. Only take effect"
815                         " when port X is started\n\n"
816
817                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
818                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
819                         " take effect when port X is stopped.\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) setup\n"
822                         "    Setup a rx/tx queue of port X.\n\n"
823
824                         "port config (port_id|all) l2-tunnel E-tag ether-type"
825                         " (value)\n"
826                         "    Set the value of E-tag ether-type.\n\n"
827
828                         "port config (port_id|all) l2-tunnel E-tag"
829                         " (enable|disable)\n"
830                         "    Enable/disable the E-tag support.\n\n"
831
832                         "port config (port_id) pctype mapping reset\n"
833                         "    Reset flow type to pctype mapping on a port\n\n"
834
835                         "port config (port_id) pctype mapping update"
836                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
837                         "    Update a flow type to pctype mapping item on a port\n\n"
838
839                         "port config (port_id) pctype (pctype_id) hash_inset|"
840                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
841                         " (field_idx)\n"
842                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
843
844                         "port config (port_id) pctype (pctype_id) hash_inset|"
845                         "fdir_inset|fdir_flx_inset clear all"
846                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
847
848                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
849                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
850
851                         "port config <port_id> rx_offload vlan_strip|"
852                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
853                         "outer_ipv4_cksum|macsec_strip|header_split|"
854                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
855                         "scatter|timestamp|security|keep_crc on|off\n"
856                         "     Enable or disable a per port Rx offloading"
857                         " on all Rx queues of a port\n\n"
858
859                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
860                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
861                         "outer_ipv4_cksum|macsec_strip|header_split|"
862                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
863                         "scatter|timestamp|security|keep_crc on|off\n"
864                         "    Enable or disable a per queue Rx offloading"
865                         " only on a specific Rx queue\n\n"
866
867                         "port config (port_id) tx_offload vlan_insert|"
868                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
869                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
870                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
871                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
872                         "security|match_metadata on|off\n"
873                         "    Enable or disable a per port Tx offloading"
874                         " on all Tx queues of a port\n\n"
875
876                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
880                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
881                         " on|off\n"
882                         "    Enable or disable a per queue Tx offloading"
883                         " only on a specific Tx queue\n\n"
884
885                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
886                         "    Load an eBPF program as a callback"
887                         " for particular RX/TX queue\n\n"
888
889                         "bpf-unload rx|tx (port) (queue)\n"
890                         "    Unload previously loaded eBPF program"
891                         " for particular RX/TX queue\n\n"
892
893                         "port config (port_id) tx_metadata (value)\n"
894                         "    Set Tx metadata value per port. Testpmd will add this value"
895                         " to any Tx packet sent from this port\n\n"
896                 );
897         }
898
899         if (show_all || !strcmp(res->section, "registers")) {
900
901                 cmdline_printf(
902                         cl,
903                         "\n"
904                         "Registers:\n"
905                         "----------\n\n"
906
907                         "read reg (port_id) (address)\n"
908                         "    Display value of a port register.\n\n"
909
910                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
911                         "    Display a port register bit field.\n\n"
912
913                         "read regbit (port_id) (address) (bit_x)\n"
914                         "    Display a single port register bit.\n\n"
915
916                         "write reg (port_id) (address) (value)\n"
917                         "    Set value of a port register.\n\n"
918
919                         "write regfield (port_id) (address) (bit_x) (bit_y)"
920                         " (value)\n"
921                         "    Set bit field of a port register.\n\n"
922
923                         "write regbit (port_id) (address) (bit_x) (value)\n"
924                         "    Set single bit value of a port register.\n\n"
925                 );
926         }
927         if (show_all || !strcmp(res->section, "filters")) {
928
929                 cmdline_printf(
930                         cl,
931                         "\n"
932                         "filters:\n"
933                         "--------\n\n"
934
935                         "ethertype_filter (port_id) (add|del)"
936                         " (mac_addr|mac_ignr) (mac_address) ethertype"
937                         " (ether_type) (drop|fwd) queue (queue_id)\n"
938                         "    Add/Del an ethertype filter.\n\n"
939
940                         "2tuple_filter (port_id) (add|del)"
941                         " dst_port (dst_port_value) protocol (protocol_value)"
942                         " mask (mask_value) tcp_flags (tcp_flags_value)"
943                         " priority (prio_value) queue (queue_id)\n"
944                         "    Add/Del a 2tuple filter.\n\n"
945
946                         "5tuple_filter (port_id) (add|del)"
947                         " dst_ip (dst_address) src_ip (src_address)"
948                         " dst_port (dst_port_value) src_port (src_port_value)"
949                         " protocol (protocol_value)"
950                         " mask (mask_value) tcp_flags (tcp_flags_value)"
951                         " priority (prio_value) queue (queue_id)\n"
952                         "    Add/Del a 5tuple filter.\n\n"
953
954                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
955                         "    Add/Del syn filter.\n\n"
956
957                         "flex_filter (port_id) (add|del) len (len_value)"
958                         " bytes (bytes_value) mask (mask_value)"
959                         " priority (prio_value) queue (queue_id)\n"
960                         "    Add/Del a flex filter.\n\n"
961
962                         "flow_director_filter (port_id) mode IP (add|del|update)"
963                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
964                         " src (src_ip_address) dst (dst_ip_address)"
965                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
966                         " vlan (vlan_value) flexbytes (flexbytes_value)"
967                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
968                         " fd_id (fd_id_value)\n"
969                         "    Add/Del an IP type flow director filter.\n\n"
970
971                         "flow_director_filter (port_id) mode IP (add|del|update)"
972                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
973                         " src (src_ip_address) (src_port)"
974                         " dst (dst_ip_address) (dst_port)"
975                         " tos (tos_value) ttl (ttl_value)"
976                         " vlan (vlan_value) flexbytes (flexbytes_value)"
977                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
978                         " fd_id (fd_id_value)\n"
979                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
980
981                         "flow_director_filter (port_id) mode IP (add|del|update)"
982                         " flow (ipv4-sctp|ipv6-sctp)"
983                         " src (src_ip_address) (src_port)"
984                         " dst (dst_ip_address) (dst_port)"
985                         " tag (verification_tag) "
986                         " tos (tos_value) ttl (ttl_value)"
987                         " vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a SCTP type flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode IP (add|del|update)"
993                         " flow l2_payload ether (ethertype)"
994                         " flexbytes (flexbytes_value) (drop|fwd)"
995                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
996                         "    Add/Del a l2 payload type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
999                         " mac (mac_address) vlan (vlan_value)"
1000                         " flexbytes (flexbytes_value) (drop|fwd)"
1001                         " queue (queue_id) fd_id (fd_id_value)\n"
1002                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1003
1004                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1005                         " mac (mac_address) vlan (vlan_value)"
1006                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1007                         " flexbytes (flexbytes_value) (drop|fwd)"
1008                         " queue (queue_id) fd_id (fd_id_value)\n"
1009                         "    Add/Del a Tunnel flow director filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode raw (add|del|update)"
1012                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1013                         " fd_id (fd_id_value) packet (packet file name)\n"
1014                         "    Add/Del a raw type flow director filter.\n\n"
1015
1016                         "flush_flow_director (port_id)\n"
1017                         "    Flush all flow director entries of a device.\n\n"
1018
1019                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1020                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1021                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1022                         "    Set flow director IP mask.\n\n"
1023
1024                         "flow_director_mask (port_id) mode MAC-VLAN"
1025                         " vlan (vlan_value)\n"
1026                         "    Set flow director MAC-VLAN mask.\n\n"
1027
1028                         "flow_director_mask (port_id) mode Tunnel"
1029                         " vlan (vlan_value) mac (mac_value)"
1030                         " tunnel-type (tunnel_type_value)"
1031                         " tunnel-id (tunnel_id_value)\n"
1032                         "    Set flow director Tunnel mask.\n\n"
1033
1034                         "flow_director_flex_mask (port_id)"
1035                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1036                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1037                         " (mask)\n"
1038                         "    Configure mask of flex payload.\n\n"
1039
1040                         "flow_director_flex_payload (port_id)"
1041                         " (raw|l2|l3|l4) (config)\n"
1042                         "    Configure flex payload selection.\n\n"
1043
1044                         "get_sym_hash_ena_per_port (port_id)\n"
1045                         "    get symmetric hash enable configuration per port.\n\n"
1046
1047                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1048                         "    set symmetric hash enable configuration per port"
1049                         " to enable or disable.\n\n"
1050
1051                         "get_hash_global_config (port_id)\n"
1052                         "    Get the global configurations of hash filters.\n\n"
1053
1054                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1055                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1056                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1057                         " (enable|disable)\n"
1058                         "    Set the global configurations of hash filters.\n\n"
1059
1060                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1061                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1062                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1063                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1064                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1065                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1066                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1067                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1068                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1069                         "fld-8th|none) (select|add)\n"
1070                         "    Set the input set for hash.\n\n"
1071
1072                         "set_fdir_input_set (port_id) "
1073                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1074                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1075                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1076                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1077                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1078                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1079                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1080                         " (select|add)\n"
1081                         "    Set the input set for FDir.\n\n"
1082
1083                         "flow validate {port_id}"
1084                         " [group {group_id}] [priority {level}]"
1085                         " [ingress] [egress]"
1086                         " pattern {item} [/ {item} [...]] / end"
1087                         " actions {action} [/ {action} [...]] / end\n"
1088                         "    Check whether a flow rule can be created.\n\n"
1089
1090                         "flow create {port_id}"
1091                         " [group {group_id}] [priority {level}]"
1092                         " [ingress] [egress]"
1093                         " pattern {item} [/ {item} [...]] / end"
1094                         " actions {action} [/ {action} [...]] / end\n"
1095                         "    Create a flow rule.\n\n"
1096
1097                         "flow destroy {port_id} rule {rule_id} [...]\n"
1098                         "    Destroy specific flow rules.\n\n"
1099
1100                         "flow flush {port_id}\n"
1101                         "    Destroy all flow rules.\n\n"
1102
1103                         "flow query {port_id} {rule_id} {action}\n"
1104                         "    Query an existing flow rule.\n\n"
1105
1106                         "flow list {port_id} [group {group_id}] [...]\n"
1107                         "    List existing flow rules sorted by priority,"
1108                         " filtered by group identifiers.\n\n"
1109
1110                         "flow isolate {port_id} {boolean}\n"
1111                         "    Restrict ingress traffic to the defined"
1112                         " flow rules\n\n"
1113
1114                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1115                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1116                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1117                         "       Configure the VXLAN encapsulation for flows.\n\n"
1118
1119                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1120                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1121                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1122                         " eth-dst (eth-dst)\n"
1123                         "       Configure the VXLAN encapsulation for flows.\n\n"
1124
1125                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1126                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1127                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1128                         " eth-dst (eth-dst)\n"
1129                         "       Configure the VXLAN encapsulation for flows.\n\n"
1130
1131                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1132                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1133                         " (eth-dst)\n"
1134                         "       Configure the NVGRE encapsulation for flows.\n\n"
1135
1136                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1137                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1138                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1139                         "       Configure the NVGRE encapsulation for flows.\n\n"
1140
1141                 );
1142         }
1143
1144         if (show_all || !strcmp(res->section, "traffic_management")) {
1145                 cmdline_printf(
1146                         cl,
1147                         "\n"
1148                         "Traffic Management:\n"
1149                         "--------------\n"
1150                         "show port tm cap (port_id)\n"
1151                         "       Display the port TM capability.\n\n"
1152
1153                         "show port tm level cap (port_id) (level_id)\n"
1154                         "       Display the port TM hierarchical level capability.\n\n"
1155
1156                         "show port tm node cap (port_id) (node_id)\n"
1157                         "       Display the port TM node capability.\n\n"
1158
1159                         "show port tm node type (port_id) (node_id)\n"
1160                         "       Display the port TM node type.\n\n"
1161
1162                         "show port tm node stats (port_id) (node_id) (clear)\n"
1163                         "       Display the port TM node stats.\n\n"
1164
1165 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1166                         "set port tm hierarchy default (port_id)\n"
1167                         "       Set default traffic Management hierarchy on a port\n\n"
1168 #endif
1169
1170                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1171                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1172                         " (packet_length_adjust)\n"
1173                         "       Add port tm node private shaper profile.\n\n"
1174
1175                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1176                         "       Delete port tm node private shaper profile.\n\n"
1177
1178                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1179                         " (shaper_profile_id)\n"
1180                         "       Add/update port tm node shared shaper.\n\n"
1181
1182                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1183                         "       Delete port tm node shared shaper.\n\n"
1184
1185                         "set port tm node shaper profile (port_id) (node_id)"
1186                         " (shaper_profile_id)\n"
1187                         "       Set port tm node shaper profile.\n\n"
1188
1189                         "add port tm node wred profile (port_id) (wred_profile_id)"
1190                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1191                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1192                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1193                         "       Add port tm node wred profile.\n\n"
1194
1195                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1196                         "       Delete port tm node wred profile.\n\n"
1197
1198                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1199                         " (priority) (weight) (level_id) (shaper_profile_id)"
1200                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1201                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1202                         "       Add port tm nonleaf node.\n\n"
1203
1204                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1205                         " (priority) (weight) (level_id) (shaper_profile_id)"
1206                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1207                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1208                         "       Add port tm leaf node.\n\n"
1209
1210                         "del port tm node (port_id) (node_id)\n"
1211                         "       Delete port tm node.\n\n"
1212
1213                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1214                         " (priority) (weight)\n"
1215                         "       Set port tm node parent.\n\n"
1216
1217                         "suspend port tm node (port_id) (node_id)"
1218                         "       Suspend tm node.\n\n"
1219
1220                         "resume port tm node (port_id) (node_id)"
1221                         "       Resume tm node.\n\n"
1222
1223                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1224                         "       Commit tm hierarchy.\n\n"
1225
1226                         "set port tm mark ip_ecn (port) (green) (yellow)"
1227                         " (red)\n"
1228                         "    Enables/Disables the traffic management marking"
1229                         " for IP ECN (Explicit Congestion Notification)"
1230                         " packets on a given port\n\n"
1231
1232                         "set port tm mark ip_dscp (port) (green) (yellow)"
1233                         " (red)\n"
1234                         "    Enables/Disables the traffic management marking"
1235                         " on the port for IP dscp packets\n\n"
1236
1237                         "set port tm mark vlan_dei (port) (green) (yellow)"
1238                         " (red)\n"
1239                         "    Enables/Disables the traffic management marking"
1240                         " on the port for VLAN packets with DEI enabled\n\n"
1241                 );
1242         }
1243
1244 }
1245
1246 cmdline_parse_token_string_t cmd_help_long_help =
1247         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1248
1249 cmdline_parse_token_string_t cmd_help_long_section =
1250         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1251                         "all#control#display#config#"
1252                         "ports#registers#filters#traffic_management");
1253
1254 cmdline_parse_inst_t cmd_help_long = {
1255         .f = cmd_help_long_parsed,
1256         .data = NULL,
1257         .help_str = "help all|control|display|config|ports|register|"
1258                 "filters|traffic_management: "
1259                 "Show help",
1260         .tokens = {
1261                 (void *)&cmd_help_long_help,
1262                 (void *)&cmd_help_long_section,
1263                 NULL,
1264         },
1265 };
1266
1267
1268 /* *** start/stop/close all ports *** */
1269 struct cmd_operate_port_result {
1270         cmdline_fixed_string_t keyword;
1271         cmdline_fixed_string_t name;
1272         cmdline_fixed_string_t value;
1273 };
1274
1275 static void cmd_operate_port_parsed(void *parsed_result,
1276                                 __attribute__((unused)) struct cmdline *cl,
1277                                 __attribute__((unused)) void *data)
1278 {
1279         struct cmd_operate_port_result *res = parsed_result;
1280
1281         if (!strcmp(res->name, "start"))
1282                 start_port(RTE_PORT_ALL);
1283         else if (!strcmp(res->name, "stop"))
1284                 stop_port(RTE_PORT_ALL);
1285         else if (!strcmp(res->name, "close"))
1286                 close_port(RTE_PORT_ALL);
1287         else if (!strcmp(res->name, "reset"))
1288                 reset_port(RTE_PORT_ALL);
1289         else
1290                 printf("Unknown parameter\n");
1291 }
1292
1293 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1294         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1295                                                                 "port");
1296 cmdline_parse_token_string_t cmd_operate_port_all_port =
1297         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1298                                                 "start#stop#close#reset");
1299 cmdline_parse_token_string_t cmd_operate_port_all_all =
1300         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1301
1302 cmdline_parse_inst_t cmd_operate_port = {
1303         .f = cmd_operate_port_parsed,
1304         .data = NULL,
1305         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1306         .tokens = {
1307                 (void *)&cmd_operate_port_all_cmd,
1308                 (void *)&cmd_operate_port_all_port,
1309                 (void *)&cmd_operate_port_all_all,
1310                 NULL,
1311         },
1312 };
1313
1314 /* *** start/stop/close specific port *** */
1315 struct cmd_operate_specific_port_result {
1316         cmdline_fixed_string_t keyword;
1317         cmdline_fixed_string_t name;
1318         uint8_t value;
1319 };
1320
1321 static void cmd_operate_specific_port_parsed(void *parsed_result,
1322                         __attribute__((unused)) struct cmdline *cl,
1323                                 __attribute__((unused)) void *data)
1324 {
1325         struct cmd_operate_specific_port_result *res = parsed_result;
1326
1327         if (!strcmp(res->name, "start"))
1328                 start_port(res->value);
1329         else if (!strcmp(res->name, "stop"))
1330                 stop_port(res->value);
1331         else if (!strcmp(res->name, "close"))
1332                 close_port(res->value);
1333         else if (!strcmp(res->name, "reset"))
1334                 reset_port(res->value);
1335         else
1336                 printf("Unknown parameter\n");
1337 }
1338
1339 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1340         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1341                                                         keyword, "port");
1342 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1343         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1344                                                 name, "start#stop#close#reset");
1345 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1346         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1347                                                         value, UINT8);
1348
1349 cmdline_parse_inst_t cmd_operate_specific_port = {
1350         .f = cmd_operate_specific_port_parsed,
1351         .data = NULL,
1352         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1353         .tokens = {
1354                 (void *)&cmd_operate_specific_port_cmd,
1355                 (void *)&cmd_operate_specific_port_port,
1356                 (void *)&cmd_operate_specific_port_id,
1357                 NULL,
1358         },
1359 };
1360
1361 /* *** enable port setup (after attach) via iterator or event *** */
1362 struct cmd_set_port_setup_on_result {
1363         cmdline_fixed_string_t set;
1364         cmdline_fixed_string_t port;
1365         cmdline_fixed_string_t setup;
1366         cmdline_fixed_string_t on;
1367         cmdline_fixed_string_t mode;
1368 };
1369
1370 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1371                                 __attribute__((unused)) struct cmdline *cl,
1372                                 __attribute__((unused)) void *data)
1373 {
1374         struct cmd_set_port_setup_on_result *res = parsed_result;
1375
1376         if (strcmp(res->mode, "event") == 0)
1377                 setup_on_probe_event = true;
1378         else if (strcmp(res->mode, "iterator") == 0)
1379                 setup_on_probe_event = false;
1380         else
1381                 printf("Unknown mode\n");
1382 }
1383
1384 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1385         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1386                         set, "set");
1387 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1388         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1389                         port, "port");
1390 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1391         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1392                         setup, "setup");
1393 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1394         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1395                         on, "on");
1396 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1397         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1398                         mode, "iterator#event");
1399
1400 cmdline_parse_inst_t cmd_set_port_setup_on = {
1401         .f = cmd_set_port_setup_on_parsed,
1402         .data = NULL,
1403         .help_str = "set port setup on iterator|event",
1404         .tokens = {
1405                 (void *)&cmd_set_port_setup_on_set,
1406                 (void *)&cmd_set_port_setup_on_port,
1407                 (void *)&cmd_set_port_setup_on_setup,
1408                 (void *)&cmd_set_port_setup_on_on,
1409                 (void *)&cmd_set_port_setup_on_mode,
1410                 NULL,
1411         },
1412 };
1413
1414 /* *** attach a specified port *** */
1415 struct cmd_operate_attach_port_result {
1416         cmdline_fixed_string_t port;
1417         cmdline_fixed_string_t keyword;
1418         cmdline_fixed_string_t identifier;
1419 };
1420
1421 static void cmd_operate_attach_port_parsed(void *parsed_result,
1422                                 __attribute__((unused)) struct cmdline *cl,
1423                                 __attribute__((unused)) void *data)
1424 {
1425         struct cmd_operate_attach_port_result *res = parsed_result;
1426
1427         if (!strcmp(res->keyword, "attach"))
1428                 attach_port(res->identifier);
1429         else
1430                 printf("Unknown parameter\n");
1431 }
1432
1433 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1434         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1435                         port, "port");
1436 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1437         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1438                         keyword, "attach");
1439 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1440         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1441                         identifier, NULL);
1442
1443 cmdline_parse_inst_t cmd_operate_attach_port = {
1444         .f = cmd_operate_attach_port_parsed,
1445         .data = NULL,
1446         .help_str = "port attach <identifier>: "
1447                 "(identifier: pci address or virtual dev name)",
1448         .tokens = {
1449                 (void *)&cmd_operate_attach_port_port,
1450                 (void *)&cmd_operate_attach_port_keyword,
1451                 (void *)&cmd_operate_attach_port_identifier,
1452                 NULL,
1453         },
1454 };
1455
1456 /* *** detach a specified port *** */
1457 struct cmd_operate_detach_port_result {
1458         cmdline_fixed_string_t port;
1459         cmdline_fixed_string_t keyword;
1460         portid_t port_id;
1461 };
1462
1463 static void cmd_operate_detach_port_parsed(void *parsed_result,
1464                                 __attribute__((unused)) struct cmdline *cl,
1465                                 __attribute__((unused)) void *data)
1466 {
1467         struct cmd_operate_detach_port_result *res = parsed_result;
1468
1469         if (!strcmp(res->keyword, "detach"))
1470                 detach_port_device(res->port_id);
1471         else
1472                 printf("Unknown parameter\n");
1473 }
1474
1475 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1476         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1477                         port, "port");
1478 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1479         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1480                         keyword, "detach");
1481 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1482         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1483                         port_id, UINT16);
1484
1485 cmdline_parse_inst_t cmd_operate_detach_port = {
1486         .f = cmd_operate_detach_port_parsed,
1487         .data = NULL,
1488         .help_str = "port detach <port_id>",
1489         .tokens = {
1490                 (void *)&cmd_operate_detach_port_port,
1491                 (void *)&cmd_operate_detach_port_keyword,
1492                 (void *)&cmd_operate_detach_port_port_id,
1493                 NULL,
1494         },
1495 };
1496
1497 /* *** configure speed for all ports *** */
1498 struct cmd_config_speed_all {
1499         cmdline_fixed_string_t port;
1500         cmdline_fixed_string_t keyword;
1501         cmdline_fixed_string_t all;
1502         cmdline_fixed_string_t item1;
1503         cmdline_fixed_string_t item2;
1504         cmdline_fixed_string_t value1;
1505         cmdline_fixed_string_t value2;
1506 };
1507
1508 static int
1509 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1510 {
1511
1512         int duplex;
1513
1514         if (!strcmp(duplexstr, "half")) {
1515                 duplex = ETH_LINK_HALF_DUPLEX;
1516         } else if (!strcmp(duplexstr, "full")) {
1517                 duplex = ETH_LINK_FULL_DUPLEX;
1518         } else if (!strcmp(duplexstr, "auto")) {
1519                 duplex = ETH_LINK_FULL_DUPLEX;
1520         } else {
1521                 printf("Unknown duplex parameter\n");
1522                 return -1;
1523         }
1524
1525         if (!strcmp(speedstr, "10")) {
1526                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1527                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1528         } else if (!strcmp(speedstr, "100")) {
1529                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1530                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1531         } else {
1532                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1533                         printf("Invalid speed/duplex parameters\n");
1534                         return -1;
1535                 }
1536                 if (!strcmp(speedstr, "1000")) {
1537                         *speed = ETH_LINK_SPEED_1G;
1538                 } else if (!strcmp(speedstr, "10000")) {
1539                         *speed = ETH_LINK_SPEED_10G;
1540                 } else if (!strcmp(speedstr, "25000")) {
1541                         *speed = ETH_LINK_SPEED_25G;
1542                 } else if (!strcmp(speedstr, "40000")) {
1543                         *speed = ETH_LINK_SPEED_40G;
1544                 } else if (!strcmp(speedstr, "50000")) {
1545                         *speed = ETH_LINK_SPEED_50G;
1546                 } else if (!strcmp(speedstr, "100000")) {
1547                         *speed = ETH_LINK_SPEED_100G;
1548                 } else if (!strcmp(speedstr, "auto")) {
1549                         *speed = ETH_LINK_SPEED_AUTONEG;
1550                 } else {
1551                         printf("Unknown speed parameter\n");
1552                         return -1;
1553                 }
1554         }
1555
1556         return 0;
1557 }
1558
1559 static void
1560 cmd_config_speed_all_parsed(void *parsed_result,
1561                         __attribute__((unused)) struct cmdline *cl,
1562                         __attribute__((unused)) void *data)
1563 {
1564         struct cmd_config_speed_all *res = parsed_result;
1565         uint32_t link_speed;
1566         portid_t pid;
1567
1568         if (!all_ports_stopped()) {
1569                 printf("Please stop all ports first\n");
1570                 return;
1571         }
1572
1573         if (parse_and_check_speed_duplex(res->value1, res->value2,
1574                         &link_speed) < 0)
1575                 return;
1576
1577         RTE_ETH_FOREACH_DEV(pid) {
1578                 ports[pid].dev_conf.link_speeds = link_speed;
1579         }
1580
1581         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1582 }
1583
1584 cmdline_parse_token_string_t cmd_config_speed_all_port =
1585         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1586 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1587         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1588                                                         "config");
1589 cmdline_parse_token_string_t cmd_config_speed_all_all =
1590         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1591 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1592         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1593 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1594         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1595                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1596 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1597         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1598 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1599         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1600                                                 "half#full#auto");
1601
1602 cmdline_parse_inst_t cmd_config_speed_all = {
1603         .f = cmd_config_speed_all_parsed,
1604         .data = NULL,
1605         .help_str = "port config all speed "
1606                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1607                                                         "half|full|auto",
1608         .tokens = {
1609                 (void *)&cmd_config_speed_all_port,
1610                 (void *)&cmd_config_speed_all_keyword,
1611                 (void *)&cmd_config_speed_all_all,
1612                 (void *)&cmd_config_speed_all_item1,
1613                 (void *)&cmd_config_speed_all_value1,
1614                 (void *)&cmd_config_speed_all_item2,
1615                 (void *)&cmd_config_speed_all_value2,
1616                 NULL,
1617         },
1618 };
1619
1620 /* *** configure speed for specific port *** */
1621 struct cmd_config_speed_specific {
1622         cmdline_fixed_string_t port;
1623         cmdline_fixed_string_t keyword;
1624         portid_t id;
1625         cmdline_fixed_string_t item1;
1626         cmdline_fixed_string_t item2;
1627         cmdline_fixed_string_t value1;
1628         cmdline_fixed_string_t value2;
1629 };
1630
1631 static void
1632 cmd_config_speed_specific_parsed(void *parsed_result,
1633                                 __attribute__((unused)) struct cmdline *cl,
1634                                 __attribute__((unused)) void *data)
1635 {
1636         struct cmd_config_speed_specific *res = parsed_result;
1637         uint32_t link_speed;
1638
1639         if (!all_ports_stopped()) {
1640                 printf("Please stop all ports first\n");
1641                 return;
1642         }
1643
1644         if (port_id_is_invalid(res->id, ENABLED_WARN))
1645                 return;
1646
1647         if (parse_and_check_speed_duplex(res->value1, res->value2,
1648                         &link_speed) < 0)
1649                 return;
1650
1651         ports[res->id].dev_conf.link_speeds = link_speed;
1652
1653         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1654 }
1655
1656
1657 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1659                                                                 "port");
1660 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1662                                                                 "config");
1663 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1664         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1665 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1667                                                                 "speed");
1668 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1669         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1670                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1671 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1673                                                                 "duplex");
1674 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1676                                                         "half#full#auto");
1677
1678 cmdline_parse_inst_t cmd_config_speed_specific = {
1679         .f = cmd_config_speed_specific_parsed,
1680         .data = NULL,
1681         .help_str = "port config <port_id> speed "
1682                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1683                                                         "half|full|auto",
1684         .tokens = {
1685                 (void *)&cmd_config_speed_specific_port,
1686                 (void *)&cmd_config_speed_specific_keyword,
1687                 (void *)&cmd_config_speed_specific_id,
1688                 (void *)&cmd_config_speed_specific_item1,
1689                 (void *)&cmd_config_speed_specific_value1,
1690                 (void *)&cmd_config_speed_specific_item2,
1691                 (void *)&cmd_config_speed_specific_value2,
1692                 NULL,
1693         },
1694 };
1695
1696 /* *** configure loopback for all ports *** */
1697 struct cmd_config_loopback_all {
1698         cmdline_fixed_string_t port;
1699         cmdline_fixed_string_t keyword;
1700         cmdline_fixed_string_t all;
1701         cmdline_fixed_string_t item;
1702         uint32_t mode;
1703 };
1704
1705 static void
1706 cmd_config_loopback_all_parsed(void *parsed_result,
1707                         __attribute__((unused)) struct cmdline *cl,
1708                         __attribute__((unused)) void *data)
1709 {
1710         struct cmd_config_loopback_all *res = parsed_result;
1711         portid_t pid;
1712
1713         if (!all_ports_stopped()) {
1714                 printf("Please stop all ports first\n");
1715                 return;
1716         }
1717
1718         RTE_ETH_FOREACH_DEV(pid) {
1719                 ports[pid].dev_conf.lpbk_mode = res->mode;
1720         }
1721
1722         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1723 }
1724
1725 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1727 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1729                                                         "config");
1730 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1732 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1734                                                         "loopback");
1735 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1736         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1737
1738 cmdline_parse_inst_t cmd_config_loopback_all = {
1739         .f = cmd_config_loopback_all_parsed,
1740         .data = NULL,
1741         .help_str = "port config all loopback <mode>",
1742         .tokens = {
1743                 (void *)&cmd_config_loopback_all_port,
1744                 (void *)&cmd_config_loopback_all_keyword,
1745                 (void *)&cmd_config_loopback_all_all,
1746                 (void *)&cmd_config_loopback_all_item,
1747                 (void *)&cmd_config_loopback_all_mode,
1748                 NULL,
1749         },
1750 };
1751
1752 /* *** configure loopback for specific port *** */
1753 struct cmd_config_loopback_specific {
1754         cmdline_fixed_string_t port;
1755         cmdline_fixed_string_t keyword;
1756         uint16_t port_id;
1757         cmdline_fixed_string_t item;
1758         uint32_t mode;
1759 };
1760
1761 static void
1762 cmd_config_loopback_specific_parsed(void *parsed_result,
1763                                 __attribute__((unused)) struct cmdline *cl,
1764                                 __attribute__((unused)) void *data)
1765 {
1766         struct cmd_config_loopback_specific *res = parsed_result;
1767
1768         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1769                 return;
1770
1771         if (!port_is_stopped(res->port_id)) {
1772                 printf("Please stop port %u first\n", res->port_id);
1773                 return;
1774         }
1775
1776         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1777
1778         cmd_reconfig_device_queue(res->port_id, 1, 1);
1779 }
1780
1781
1782 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1783         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1784                                                                 "port");
1785 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1787                                                                 "config");
1788 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1789         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1790                                                                 UINT16);
1791 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1793                                                                 "loopback");
1794 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1795         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1796                               UINT32);
1797
1798 cmdline_parse_inst_t cmd_config_loopback_specific = {
1799         .f = cmd_config_loopback_specific_parsed,
1800         .data = NULL,
1801         .help_str = "port config <port_id> loopback <mode>",
1802         .tokens = {
1803                 (void *)&cmd_config_loopback_specific_port,
1804                 (void *)&cmd_config_loopback_specific_keyword,
1805                 (void *)&cmd_config_loopback_specific_id,
1806                 (void *)&cmd_config_loopback_specific_item,
1807                 (void *)&cmd_config_loopback_specific_mode,
1808                 NULL,
1809         },
1810 };
1811
1812 /* *** configure txq/rxq, txd/rxd *** */
1813 struct cmd_config_rx_tx {
1814         cmdline_fixed_string_t port;
1815         cmdline_fixed_string_t keyword;
1816         cmdline_fixed_string_t all;
1817         cmdline_fixed_string_t name;
1818         uint16_t value;
1819 };
1820
1821 static void
1822 cmd_config_rx_tx_parsed(void *parsed_result,
1823                         __attribute__((unused)) struct cmdline *cl,
1824                         __attribute__((unused)) void *data)
1825 {
1826         struct cmd_config_rx_tx *res = parsed_result;
1827
1828         if (!all_ports_stopped()) {
1829                 printf("Please stop all ports first\n");
1830                 return;
1831         }
1832         if (!strcmp(res->name, "rxq")) {
1833                 if (!res->value && !nb_txq) {
1834                         printf("Warning: Either rx or tx queues should be non zero\n");
1835                         return;
1836                 }
1837                 if (check_nb_rxq(res->value) != 0)
1838                         return;
1839                 nb_rxq = res->value;
1840         }
1841         else if (!strcmp(res->name, "txq")) {
1842                 if (!res->value && !nb_rxq) {
1843                         printf("Warning: Either rx or tx queues should be non zero\n");
1844                         return;
1845                 }
1846                 if (check_nb_txq(res->value) != 0)
1847                         return;
1848                 nb_txq = res->value;
1849         }
1850         else if (!strcmp(res->name, "rxd")) {
1851                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1852                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1853                                         res->value, RTE_TEST_RX_DESC_MAX);
1854                         return;
1855                 }
1856                 nb_rxd = res->value;
1857         } else if (!strcmp(res->name, "txd")) {
1858                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1859                         printf("txd %d invalid - must be > 0 && <= %d\n",
1860                                         res->value, RTE_TEST_TX_DESC_MAX);
1861                         return;
1862                 }
1863                 nb_txd = res->value;
1864         } else {
1865                 printf("Unknown parameter\n");
1866                 return;
1867         }
1868
1869         fwd_config_setup();
1870
1871         init_port_config();
1872
1873         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1874 }
1875
1876 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1878 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1879         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1880 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1881         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1882 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1883         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1884                                                 "rxq#txq#rxd#txd");
1885 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1886         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1887
1888 cmdline_parse_inst_t cmd_config_rx_tx = {
1889         .f = cmd_config_rx_tx_parsed,
1890         .data = NULL,
1891         .help_str = "port config all rxq|txq|rxd|txd <value>",
1892         .tokens = {
1893                 (void *)&cmd_config_rx_tx_port,
1894                 (void *)&cmd_config_rx_tx_keyword,
1895                 (void *)&cmd_config_rx_tx_all,
1896                 (void *)&cmd_config_rx_tx_name,
1897                 (void *)&cmd_config_rx_tx_value,
1898                 NULL,
1899         },
1900 };
1901
1902 /* *** config max packet length *** */
1903 struct cmd_config_max_pkt_len_result {
1904         cmdline_fixed_string_t port;
1905         cmdline_fixed_string_t keyword;
1906         cmdline_fixed_string_t all;
1907         cmdline_fixed_string_t name;
1908         uint32_t value;
1909 };
1910
1911 static void
1912 cmd_config_max_pkt_len_parsed(void *parsed_result,
1913                                 __attribute__((unused)) struct cmdline *cl,
1914                                 __attribute__((unused)) void *data)
1915 {
1916         struct cmd_config_max_pkt_len_result *res = parsed_result;
1917         portid_t pid;
1918
1919         if (!all_ports_stopped()) {
1920                 printf("Please stop all ports first\n");
1921                 return;
1922         }
1923
1924         RTE_ETH_FOREACH_DEV(pid) {
1925                 struct rte_port *port = &ports[pid];
1926                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1927
1928                 if (!strcmp(res->name, "max-pkt-len")) {
1929                         if (res->value < RTE_ETHER_MIN_LEN) {
1930                                 printf("max-pkt-len can not be less than %d\n",
1931                                                 RTE_ETHER_MIN_LEN);
1932                                 return;
1933                         }
1934                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1935                                 return;
1936
1937                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1938                         if (res->value > RTE_ETHER_MAX_LEN)
1939                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1940                         else
1941                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1942                         port->dev_conf.rxmode.offloads = rx_offloads;
1943                 } else {
1944                         printf("Unknown parameter\n");
1945                         return;
1946                 }
1947         }
1948
1949         init_port_config();
1950
1951         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1952 }
1953
1954 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1956                                                                 "port");
1957 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1959                                                                 "config");
1960 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1962                                                                 "all");
1963 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1965                                                                 "max-pkt-len");
1966 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1967         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1968                                                                 UINT32);
1969
1970 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1971         .f = cmd_config_max_pkt_len_parsed,
1972         .data = NULL,
1973         .help_str = "port config all max-pkt-len <value>",
1974         .tokens = {
1975                 (void *)&cmd_config_max_pkt_len_port,
1976                 (void *)&cmd_config_max_pkt_len_keyword,
1977                 (void *)&cmd_config_max_pkt_len_all,
1978                 (void *)&cmd_config_max_pkt_len_name,
1979                 (void *)&cmd_config_max_pkt_len_value,
1980                 NULL,
1981         },
1982 };
1983
1984 /* *** configure port MTU *** */
1985 struct cmd_config_mtu_result {
1986         cmdline_fixed_string_t port;
1987         cmdline_fixed_string_t keyword;
1988         cmdline_fixed_string_t mtu;
1989         portid_t port_id;
1990         uint16_t value;
1991 };
1992
1993 static void
1994 cmd_config_mtu_parsed(void *parsed_result,
1995                       __attribute__((unused)) struct cmdline *cl,
1996                       __attribute__((unused)) void *data)
1997 {
1998         struct cmd_config_mtu_result *res = parsed_result;
1999
2000         if (res->value < RTE_ETHER_MIN_LEN) {
2001                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2002                 return;
2003         }
2004         port_mtu_set(res->port_id, res->value);
2005 }
2006
2007 cmdline_parse_token_string_t cmd_config_mtu_port =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2009                                  "port");
2010 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2012                                  "config");
2013 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2015                                  "mtu");
2016 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2017         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2018 cmdline_parse_token_num_t cmd_config_mtu_value =
2019         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2020
2021 cmdline_parse_inst_t cmd_config_mtu = {
2022         .f = cmd_config_mtu_parsed,
2023         .data = NULL,
2024         .help_str = "port config mtu <port_id> <value>",
2025         .tokens = {
2026                 (void *)&cmd_config_mtu_port,
2027                 (void *)&cmd_config_mtu_keyword,
2028                 (void *)&cmd_config_mtu_mtu,
2029                 (void *)&cmd_config_mtu_port_id,
2030                 (void *)&cmd_config_mtu_value,
2031                 NULL,
2032         },
2033 };
2034
2035 /* *** configure rx mode *** */
2036 struct cmd_config_rx_mode_flag {
2037         cmdline_fixed_string_t port;
2038         cmdline_fixed_string_t keyword;
2039         cmdline_fixed_string_t all;
2040         cmdline_fixed_string_t name;
2041         cmdline_fixed_string_t value;
2042 };
2043
2044 static void
2045 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2046                                 __attribute__((unused)) struct cmdline *cl,
2047                                 __attribute__((unused)) void *data)
2048 {
2049         struct cmd_config_rx_mode_flag *res = parsed_result;
2050         portid_t pid;
2051         int k;
2052
2053         if (!all_ports_stopped()) {
2054                 printf("Please stop all ports first\n");
2055                 return;
2056         }
2057
2058         RTE_ETH_FOREACH_DEV(pid) {
2059                 struct rte_port *port;
2060                 uint64_t rx_offloads;
2061
2062                 port = &ports[pid];
2063                 rx_offloads = port->dev_conf.rxmode.offloads;
2064                 if (!strcmp(res->name, "crc-strip")) {
2065                         if (!strcmp(res->value, "on")) {
2066                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
2067                         } else if (!strcmp(res->value, "off")) {
2068                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
2069                         } else {
2070                                 printf("Unknown parameter\n");
2071                                 return;
2072                         }
2073                 } else if (!strcmp(res->name, "scatter")) {
2074                         if (!strcmp(res->value, "on")) {
2075                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
2076                         } else if (!strcmp(res->value, "off")) {
2077                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
2078                         } else {
2079                                 printf("Unknown parameter\n");
2080                                 return;
2081                         }
2082                 } else if (!strcmp(res->name, "rx-cksum")) {
2083                         if (!strcmp(res->value, "on"))
2084                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
2085                         else if (!strcmp(res->value, "off"))
2086                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
2087                         else {
2088                                 printf("Unknown parameter\n");
2089                                 return;
2090                         }
2091                 } else if (!strcmp(res->name, "rx-timestamp")) {
2092                         if (!strcmp(res->value, "on"))
2093                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
2094                         else if (!strcmp(res->value, "off"))
2095                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2096                         else {
2097                                 printf("Unknown parameter\n");
2098                                 return;
2099                         }
2100                 } else if (!strcmp(res->name, "hw-vlan")) {
2101                         if (!strcmp(res->value, "on")) {
2102                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2103                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2104                         } else if (!strcmp(res->value, "off")) {
2105                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2106                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2107                         } else {
2108                                 printf("Unknown parameter\n");
2109                                 return;
2110                         }
2111                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2112                         if (!strcmp(res->value, "on"))
2113                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2114                         else if (!strcmp(res->value, "off"))
2115                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2116                         else {
2117                                 printf("Unknown parameter\n");
2118                                 return;
2119                         }
2120                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2121                         if (!strcmp(res->value, "on"))
2122                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2123                         else if (!strcmp(res->value, "off"))
2124                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2125                         else {
2126                                 printf("Unknown parameter\n");
2127                                 return;
2128                         }
2129                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2130                         if (!strcmp(res->value, "on"))
2131                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2132                         else if (!strcmp(res->value, "off"))
2133                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2134                         else {
2135                                 printf("Unknown parameter\n");
2136                                 return;
2137                         }
2138                 } else if (!strcmp(res->name, "drop-en")) {
2139                         if (!strcmp(res->value, "on"))
2140                                 rx_drop_en = 1;
2141                         else if (!strcmp(res->value, "off"))
2142                                 rx_drop_en = 0;
2143                         else {
2144                                 printf("Unknown parameter\n");
2145                                 return;
2146                         }
2147                 } else {
2148                         printf("Unknown parameter\n");
2149                         return;
2150                 }
2151                 port->dev_conf.rxmode.offloads = rx_offloads;
2152                 /* Apply Rx offloads configuration */
2153                 for (k = 0; k < port->dev_info.max_rx_queues; k++)
2154                         port->rx_conf[k].offloads =
2155                                 port->dev_conf.rxmode.offloads;
2156         }
2157
2158         init_port_config();
2159
2160         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2161 }
2162
2163 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2164         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2165 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2166         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2167                                                                 "config");
2168 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2170 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2171         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2172                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2173                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2174 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2175         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2176                                                         "on#off");
2177
2178 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2179         .f = cmd_config_rx_mode_flag_parsed,
2180         .data = NULL,
2181         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2182                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2183         .tokens = {
2184                 (void *)&cmd_config_rx_mode_flag_port,
2185                 (void *)&cmd_config_rx_mode_flag_keyword,
2186                 (void *)&cmd_config_rx_mode_flag_all,
2187                 (void *)&cmd_config_rx_mode_flag_name,
2188                 (void *)&cmd_config_rx_mode_flag_value,
2189                 NULL,
2190         },
2191 };
2192
2193 /* *** configure rss *** */
2194 struct cmd_config_rss {
2195         cmdline_fixed_string_t port;
2196         cmdline_fixed_string_t keyword;
2197         cmdline_fixed_string_t all;
2198         cmdline_fixed_string_t name;
2199         cmdline_fixed_string_t value;
2200 };
2201
2202 static void
2203 cmd_config_rss_parsed(void *parsed_result,
2204                         __attribute__((unused)) struct cmdline *cl,
2205                         __attribute__((unused)) void *data)
2206 {
2207         struct cmd_config_rss *res = parsed_result;
2208         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2209         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2210         int use_default = 0;
2211         int all_updated = 1;
2212         int diag;
2213         uint16_t i;
2214
2215         if (!strcmp(res->value, "all"))
2216                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2217                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2218                                         ETH_RSS_L2_PAYLOAD;
2219         else if (!strcmp(res->value, "ip"))
2220                 rss_conf.rss_hf = ETH_RSS_IP;
2221         else if (!strcmp(res->value, "udp"))
2222                 rss_conf.rss_hf = ETH_RSS_UDP;
2223         else if (!strcmp(res->value, "tcp"))
2224                 rss_conf.rss_hf = ETH_RSS_TCP;
2225         else if (!strcmp(res->value, "sctp"))
2226                 rss_conf.rss_hf = ETH_RSS_SCTP;
2227         else if (!strcmp(res->value, "ether"))
2228                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2229         else if (!strcmp(res->value, "port"))
2230                 rss_conf.rss_hf = ETH_RSS_PORT;
2231         else if (!strcmp(res->value, "vxlan"))
2232                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2233         else if (!strcmp(res->value, "geneve"))
2234                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2235         else if (!strcmp(res->value, "nvgre"))
2236                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2237         else if (!strcmp(res->value, "none"))
2238                 rss_conf.rss_hf = 0;
2239         else if (!strcmp(res->value, "default"))
2240                 use_default = 1;
2241         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2242                                                 atoi(res->value) < 64)
2243                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2244         else {
2245                 printf("Unknown parameter\n");
2246                 return;
2247         }
2248         rss_conf.rss_key = NULL;
2249         /* Update global configuration for RSS types. */
2250         RTE_ETH_FOREACH_DEV(i) {
2251                 struct rte_eth_rss_conf local_rss_conf;
2252
2253                 rte_eth_dev_info_get(i, &dev_info);
2254                 if (use_default)
2255                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2256
2257                 local_rss_conf = rss_conf;
2258                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2259                         dev_info.flow_type_rss_offloads;
2260                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2261                         printf("Port %u modified RSS hash function based on hardware support,"
2262                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2263                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2264                 }
2265                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2266                 if (diag < 0) {
2267                         all_updated = 0;
2268                         printf("Configuration of RSS hash at ethernet port %d "
2269                                 "failed with error (%d): %s.\n",
2270                                 i, -diag, strerror(-diag));
2271                 }
2272         }
2273         if (all_updated && !use_default)
2274                 rss_hf = rss_conf.rss_hf;
2275 }
2276
2277 cmdline_parse_token_string_t cmd_config_rss_port =
2278         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2279 cmdline_parse_token_string_t cmd_config_rss_keyword =
2280         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2281 cmdline_parse_token_string_t cmd_config_rss_all =
2282         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2283 cmdline_parse_token_string_t cmd_config_rss_name =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2285 cmdline_parse_token_string_t cmd_config_rss_value =
2286         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2287
2288 cmdline_parse_inst_t cmd_config_rss = {
2289         .f = cmd_config_rss_parsed,
2290         .data = NULL,
2291         .help_str = "port config all rss "
2292                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2293         .tokens = {
2294                 (void *)&cmd_config_rss_port,
2295                 (void *)&cmd_config_rss_keyword,
2296                 (void *)&cmd_config_rss_all,
2297                 (void *)&cmd_config_rss_name,
2298                 (void *)&cmd_config_rss_value,
2299                 NULL,
2300         },
2301 };
2302
2303 /* *** configure rss hash key *** */
2304 struct cmd_config_rss_hash_key {
2305         cmdline_fixed_string_t port;
2306         cmdline_fixed_string_t config;
2307         portid_t port_id;
2308         cmdline_fixed_string_t rss_hash_key;
2309         cmdline_fixed_string_t rss_type;
2310         cmdline_fixed_string_t key;
2311 };
2312
2313 static uint8_t
2314 hexa_digit_to_value(char hexa_digit)
2315 {
2316         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2317                 return (uint8_t) (hexa_digit - '0');
2318         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2319                 return (uint8_t) ((hexa_digit - 'a') + 10);
2320         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2321                 return (uint8_t) ((hexa_digit - 'A') + 10);
2322         /* Invalid hexa digit */
2323         return 0xFF;
2324 }
2325
2326 static uint8_t
2327 parse_and_check_key_hexa_digit(char *key, int idx)
2328 {
2329         uint8_t hexa_v;
2330
2331         hexa_v = hexa_digit_to_value(key[idx]);
2332         if (hexa_v == 0xFF)
2333                 printf("invalid key: character %c at position %d is not a "
2334                        "valid hexa digit\n", key[idx], idx);
2335         return hexa_v;
2336 }
2337
2338 static void
2339 cmd_config_rss_hash_key_parsed(void *parsed_result,
2340                                __attribute__((unused)) struct cmdline *cl,
2341                                __attribute__((unused)) void *data)
2342 {
2343         struct cmd_config_rss_hash_key *res = parsed_result;
2344         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2345         uint8_t xdgt0;
2346         uint8_t xdgt1;
2347         int i;
2348         struct rte_eth_dev_info dev_info;
2349         uint8_t hash_key_size;
2350         uint32_t key_len;
2351
2352         memset(&dev_info, 0, sizeof(dev_info));
2353         rte_eth_dev_info_get(res->port_id, &dev_info);
2354         if (dev_info.hash_key_size > 0 &&
2355                         dev_info.hash_key_size <= sizeof(hash_key))
2356                 hash_key_size = dev_info.hash_key_size;
2357         else {
2358                 printf("dev_info did not provide a valid hash key size\n");
2359                 return;
2360         }
2361         /* Check the length of the RSS hash key */
2362         key_len = strlen(res->key);
2363         if (key_len != (hash_key_size * 2)) {
2364                 printf("key length: %d invalid - key must be a string of %d"
2365                            " hexa-decimal numbers\n",
2366                            (int) key_len, hash_key_size * 2);
2367                 return;
2368         }
2369         /* Translate RSS hash key into binary representation */
2370         for (i = 0; i < hash_key_size; i++) {
2371                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2372                 if (xdgt0 == 0xFF)
2373                         return;
2374                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2375                 if (xdgt1 == 0xFF)
2376                         return;
2377                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2378         }
2379         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2380                         hash_key_size);
2381 }
2382
2383 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2385 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2387                                  "config");
2388 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2389         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2390 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2391         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2392                                  rss_hash_key, "rss-hash-key");
2393 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2394         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2395                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2396                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2397                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2398                                  "ipv6-tcp-ex#ipv6-udp-ex");
2399 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2400         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2401
2402 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2403         .f = cmd_config_rss_hash_key_parsed,
2404         .data = NULL,
2405         .help_str = "port config <port_id> rss-hash-key "
2406                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2407                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2408                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2409                 "<string of hex digits (variable length, NIC dependent)>",
2410         .tokens = {
2411                 (void *)&cmd_config_rss_hash_key_port,
2412                 (void *)&cmd_config_rss_hash_key_config,
2413                 (void *)&cmd_config_rss_hash_key_port_id,
2414                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2415                 (void *)&cmd_config_rss_hash_key_rss_type,
2416                 (void *)&cmd_config_rss_hash_key_value,
2417                 NULL,
2418         },
2419 };
2420
2421 /* *** configure port rxq/txq ring size *** */
2422 struct cmd_config_rxtx_ring_size {
2423         cmdline_fixed_string_t port;
2424         cmdline_fixed_string_t config;
2425         portid_t portid;
2426         cmdline_fixed_string_t rxtxq;
2427         uint16_t qid;
2428         cmdline_fixed_string_t rsize;
2429         uint16_t size;
2430 };
2431
2432 static void
2433 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2434                                  __attribute__((unused)) struct cmdline *cl,
2435                                  __attribute__((unused)) void *data)
2436 {
2437         struct cmd_config_rxtx_ring_size *res = parsed_result;
2438         struct rte_port *port;
2439         uint8_t isrx;
2440
2441         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2442                 return;
2443
2444         if (res->portid == (portid_t)RTE_PORT_ALL) {
2445                 printf("Invalid port id\n");
2446                 return;
2447         }
2448
2449         port = &ports[res->portid];
2450
2451         if (!strcmp(res->rxtxq, "rxq"))
2452                 isrx = 1;
2453         else if (!strcmp(res->rxtxq, "txq"))
2454                 isrx = 0;
2455         else {
2456                 printf("Unknown parameter\n");
2457                 return;
2458         }
2459
2460         if (isrx && rx_queue_id_is_invalid(res->qid))
2461                 return;
2462         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2463                 return;
2464
2465         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2466                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2467                        rx_free_thresh);
2468                 return;
2469         }
2470
2471         if (isrx)
2472                 port->nb_rx_desc[res->qid] = res->size;
2473         else
2474                 port->nb_tx_desc[res->qid] = res->size;
2475
2476         cmd_reconfig_device_queue(res->portid, 0, 1);
2477 }
2478
2479 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2481                                  port, "port");
2482 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2483         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2484                                  config, "config");
2485 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2486         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2487                                  portid, UINT16);
2488 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2490                                  rxtxq, "rxq#txq");
2491 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2492         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2493                               qid, UINT16);
2494 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2496                                  rsize, "ring_size");
2497 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2498         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2499                               size, UINT16);
2500
2501 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2502         .f = cmd_config_rxtx_ring_size_parsed,
2503         .data = NULL,
2504         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2505         .tokens = {
2506                 (void *)&cmd_config_rxtx_ring_size_port,
2507                 (void *)&cmd_config_rxtx_ring_size_config,
2508                 (void *)&cmd_config_rxtx_ring_size_portid,
2509                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2510                 (void *)&cmd_config_rxtx_ring_size_qid,
2511                 (void *)&cmd_config_rxtx_ring_size_rsize,
2512                 (void *)&cmd_config_rxtx_ring_size_size,
2513                 NULL,
2514         },
2515 };
2516
2517 /* *** configure port rxq/txq start/stop *** */
2518 struct cmd_config_rxtx_queue {
2519         cmdline_fixed_string_t port;
2520         portid_t portid;
2521         cmdline_fixed_string_t rxtxq;
2522         uint16_t qid;
2523         cmdline_fixed_string_t opname;
2524 };
2525
2526 static void
2527 cmd_config_rxtx_queue_parsed(void *parsed_result,
2528                         __attribute__((unused)) struct cmdline *cl,
2529                         __attribute__((unused)) void *data)
2530 {
2531         struct cmd_config_rxtx_queue *res = parsed_result;
2532         uint8_t isrx;
2533         uint8_t isstart;
2534         int ret = 0;
2535
2536         if (test_done == 0) {
2537                 printf("Please stop forwarding first\n");
2538                 return;
2539         }
2540
2541         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2542                 return;
2543
2544         if (port_is_started(res->portid) != 1) {
2545                 printf("Please start port %u first\n", res->portid);
2546                 return;
2547         }
2548
2549         if (!strcmp(res->rxtxq, "rxq"))
2550                 isrx = 1;
2551         else if (!strcmp(res->rxtxq, "txq"))
2552                 isrx = 0;
2553         else {
2554                 printf("Unknown parameter\n");
2555                 return;
2556         }
2557
2558         if (isrx && rx_queue_id_is_invalid(res->qid))
2559                 return;
2560         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2561                 return;
2562
2563         if (!strcmp(res->opname, "start"))
2564                 isstart = 1;
2565         else if (!strcmp(res->opname, "stop"))
2566                 isstart = 0;
2567         else {
2568                 printf("Unknown parameter\n");
2569                 return;
2570         }
2571
2572         if (isstart && isrx)
2573                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2574         else if (!isstart && isrx)
2575                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2576         else if (isstart && !isrx)
2577                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2578         else
2579                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2580
2581         if (ret == -ENOTSUP)
2582                 printf("Function not supported in PMD driver\n");
2583 }
2584
2585 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2586         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2587 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2588         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2589 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2590         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2591 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2592         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2593 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2595                                                 "start#stop");
2596
2597 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2598         .f = cmd_config_rxtx_queue_parsed,
2599         .data = NULL,
2600         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2601         .tokens = {
2602                 (void *)&cmd_config_rxtx_queue_port,
2603                 (void *)&cmd_config_rxtx_queue_portid,
2604                 (void *)&cmd_config_rxtx_queue_rxtxq,
2605                 (void *)&cmd_config_rxtx_queue_qid,
2606                 (void *)&cmd_config_rxtx_queue_opname,
2607                 NULL,
2608         },
2609 };
2610
2611 /* *** configure port rxq/txq deferred start on/off *** */
2612 struct cmd_config_deferred_start_rxtx_queue {
2613         cmdline_fixed_string_t port;
2614         portid_t port_id;
2615         cmdline_fixed_string_t rxtxq;
2616         uint16_t qid;
2617         cmdline_fixed_string_t opname;
2618         cmdline_fixed_string_t state;
2619 };
2620
2621 static void
2622 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2623                         __attribute__((unused)) struct cmdline *cl,
2624                         __attribute__((unused)) void *data)
2625 {
2626         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2627         struct rte_port *port;
2628         uint8_t isrx;
2629         uint8_t ison;
2630         uint8_t needreconfig = 0;
2631
2632         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2633                 return;
2634
2635         if (port_is_started(res->port_id) != 0) {
2636                 printf("Please stop port %u first\n", res->port_id);
2637                 return;
2638         }
2639
2640         port = &ports[res->port_id];
2641
2642         isrx = !strcmp(res->rxtxq, "rxq");
2643
2644         if (isrx && rx_queue_id_is_invalid(res->qid))
2645                 return;
2646         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2647                 return;
2648
2649         ison = !strcmp(res->state, "on");
2650
2651         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2652                 port->rx_conf[res->qid].rx_deferred_start = ison;
2653                 needreconfig = 1;
2654         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2655                 port->tx_conf[res->qid].tx_deferred_start = ison;
2656                 needreconfig = 1;
2657         }
2658
2659         if (needreconfig)
2660                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2661 }
2662
2663 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2664         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2665                                                 port, "port");
2666 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2667         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2668                                                 port_id, UINT16);
2669 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2671                                                 rxtxq, "rxq#txq");
2672 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2673         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2674                                                 qid, UINT16);
2675 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2676         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2677                                                 opname, "deferred_start");
2678 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2679         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2680                                                 state, "on#off");
2681
2682 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2683         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2684         .data = NULL,
2685         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2686         .tokens = {
2687                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2688                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2689                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2690                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2691                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2692                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2693                 NULL,
2694         },
2695 };
2696
2697 /* *** configure port rxq/txq setup *** */
2698 struct cmd_setup_rxtx_queue {
2699         cmdline_fixed_string_t port;
2700         portid_t portid;
2701         cmdline_fixed_string_t rxtxq;
2702         uint16_t qid;
2703         cmdline_fixed_string_t setup;
2704 };
2705
2706 /* Common CLI fields for queue setup */
2707 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2708         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2709 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2710         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2711 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2712         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2713 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2714         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2715 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2716         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2717
2718 static void
2719 cmd_setup_rxtx_queue_parsed(
2720         void *parsed_result,
2721         __attribute__((unused)) struct cmdline *cl,
2722         __attribute__((unused)) void *data)
2723 {
2724         struct cmd_setup_rxtx_queue *res = parsed_result;
2725         struct rte_port *port;
2726         struct rte_mempool *mp;
2727         unsigned int socket_id;
2728         uint8_t isrx = 0;
2729         int ret;
2730
2731         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2732                 return;
2733
2734         if (res->portid == (portid_t)RTE_PORT_ALL) {
2735                 printf("Invalid port id\n");
2736                 return;
2737         }
2738
2739         if (!strcmp(res->rxtxq, "rxq"))
2740                 isrx = 1;
2741         else if (!strcmp(res->rxtxq, "txq"))
2742                 isrx = 0;
2743         else {
2744                 printf("Unknown parameter\n");
2745                 return;
2746         }
2747
2748         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2749                 printf("Invalid rx queue\n");
2750                 return;
2751         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2752                 printf("Invalid tx queue\n");
2753                 return;
2754         }
2755
2756         port = &ports[res->portid];
2757         if (isrx) {
2758                 socket_id = rxring_numa[res->portid];
2759                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2760                         socket_id = port->socket_id;
2761
2762                 mp = mbuf_pool_find(socket_id);
2763                 if (mp == NULL) {
2764                         printf("Failed to setup RX queue: "
2765                                 "No mempool allocation"
2766                                 " on the socket %d\n",
2767                                 rxring_numa[res->portid]);
2768                         return;
2769                 }
2770                 ret = rte_eth_rx_queue_setup(res->portid,
2771                                              res->qid,
2772                                              port->nb_rx_desc[res->qid],
2773                                              socket_id,
2774                                              &port->rx_conf[res->qid],
2775                                              mp);
2776                 if (ret)
2777                         printf("Failed to setup RX queue\n");
2778         } else {
2779                 socket_id = txring_numa[res->portid];
2780                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2781                         socket_id = port->socket_id;
2782
2783                 ret = rte_eth_tx_queue_setup(res->portid,
2784                                              res->qid,
2785                                              port->nb_tx_desc[res->qid],
2786                                              socket_id,
2787                                              &port->tx_conf[res->qid]);
2788                 if (ret)
2789                         printf("Failed to setup TX queue\n");
2790         }
2791 }
2792
2793 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2794         .f = cmd_setup_rxtx_queue_parsed,
2795         .data = NULL,
2796         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2797         .tokens = {
2798                 (void *)&cmd_setup_rxtx_queue_port,
2799                 (void *)&cmd_setup_rxtx_queue_portid,
2800                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2801                 (void *)&cmd_setup_rxtx_queue_qid,
2802                 (void *)&cmd_setup_rxtx_queue_setup,
2803                 NULL,
2804         },
2805 };
2806
2807
2808 /* *** Configure RSS RETA *** */
2809 struct cmd_config_rss_reta {
2810         cmdline_fixed_string_t port;
2811         cmdline_fixed_string_t keyword;
2812         portid_t port_id;
2813         cmdline_fixed_string_t name;
2814         cmdline_fixed_string_t list_name;
2815         cmdline_fixed_string_t list_of_items;
2816 };
2817
2818 static int
2819 parse_reta_config(const char *str,
2820                   struct rte_eth_rss_reta_entry64 *reta_conf,
2821                   uint16_t nb_entries)
2822 {
2823         int i;
2824         unsigned size;
2825         uint16_t hash_index, idx, shift;
2826         uint16_t nb_queue;
2827         char s[256];
2828         const char *p, *p0 = str;
2829         char *end;
2830         enum fieldnames {
2831                 FLD_HASH_INDEX = 0,
2832                 FLD_QUEUE,
2833                 _NUM_FLD
2834         };
2835         unsigned long int_fld[_NUM_FLD];
2836         char *str_fld[_NUM_FLD];
2837
2838         while ((p = strchr(p0,'(')) != NULL) {
2839                 ++p;
2840                 if((p0 = strchr(p,')')) == NULL)
2841                         return -1;
2842
2843                 size = p0 - p;
2844                 if(size >= sizeof(s))
2845                         return -1;
2846
2847                 snprintf(s, sizeof(s), "%.*s", size, p);
2848                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2849                         return -1;
2850                 for (i = 0; i < _NUM_FLD; i++) {
2851                         errno = 0;
2852                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2853                         if (errno != 0 || end == str_fld[i] ||
2854                                         int_fld[i] > 65535)
2855                                 return -1;
2856                 }
2857
2858                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2859                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2860
2861                 if (hash_index >= nb_entries) {
2862                         printf("Invalid RETA hash index=%d\n", hash_index);
2863                         return -1;
2864                 }
2865
2866                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2867                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2868                 reta_conf[idx].mask |= (1ULL << shift);
2869                 reta_conf[idx].reta[shift] = nb_queue;
2870         }
2871
2872         return 0;
2873 }
2874
2875 static void
2876 cmd_set_rss_reta_parsed(void *parsed_result,
2877                         __attribute__((unused)) struct cmdline *cl,
2878                         __attribute__((unused)) void *data)
2879 {
2880         int ret;
2881         struct rte_eth_dev_info dev_info;
2882         struct rte_eth_rss_reta_entry64 reta_conf[8];
2883         struct cmd_config_rss_reta *res = parsed_result;
2884
2885         memset(&dev_info, 0, sizeof(dev_info));
2886         rte_eth_dev_info_get(res->port_id, &dev_info);
2887         if (dev_info.reta_size == 0) {
2888                 printf("Redirection table size is 0 which is "
2889                                         "invalid for RSS\n");
2890                 return;
2891         } else
2892                 printf("The reta size of port %d is %u\n",
2893                         res->port_id, dev_info.reta_size);
2894         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2895                 printf("Currently do not support more than %u entries of "
2896                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2897                 return;
2898         }
2899
2900         memset(reta_conf, 0, sizeof(reta_conf));
2901         if (!strcmp(res->list_name, "reta")) {
2902                 if (parse_reta_config(res->list_of_items, reta_conf,
2903                                                 dev_info.reta_size)) {
2904                         printf("Invalid RSS Redirection Table "
2905                                         "config entered\n");
2906                         return;
2907                 }
2908                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2909                                 reta_conf, dev_info.reta_size);
2910                 if (ret != 0)
2911                         printf("Bad redirection table parameter, "
2912                                         "return code = %d \n", ret);
2913         }
2914 }
2915
2916 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2917         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2918 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2919         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2920 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2921         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2922 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2923         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2924 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2925         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2926 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2927         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2928                                  NULL);
2929 cmdline_parse_inst_t cmd_config_rss_reta = {
2930         .f = cmd_set_rss_reta_parsed,
2931         .data = NULL,
2932         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2933         .tokens = {
2934                 (void *)&cmd_config_rss_reta_port,
2935                 (void *)&cmd_config_rss_reta_keyword,
2936                 (void *)&cmd_config_rss_reta_port_id,
2937                 (void *)&cmd_config_rss_reta_name,
2938                 (void *)&cmd_config_rss_reta_list_name,
2939                 (void *)&cmd_config_rss_reta_list_of_items,
2940                 NULL,
2941         },
2942 };
2943
2944 /* *** SHOW PORT RETA INFO *** */
2945 struct cmd_showport_reta {
2946         cmdline_fixed_string_t show;
2947         cmdline_fixed_string_t port;
2948         portid_t port_id;
2949         cmdline_fixed_string_t rss;
2950         cmdline_fixed_string_t reta;
2951         uint16_t size;
2952         cmdline_fixed_string_t list_of_items;
2953 };
2954
2955 static int
2956 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2957                            uint16_t nb_entries,
2958                            char *str)
2959 {
2960         uint32_t size;
2961         const char *p, *p0 = str;
2962         char s[256];
2963         char *end;
2964         char *str_fld[8];
2965         uint16_t i;
2966         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2967                         RTE_RETA_GROUP_SIZE;
2968         int ret;
2969
2970         p = strchr(p0, '(');
2971         if (p == NULL)
2972                 return -1;
2973         p++;
2974         p0 = strchr(p, ')');
2975         if (p0 == NULL)
2976                 return -1;
2977         size = p0 - p;
2978         if (size >= sizeof(s)) {
2979                 printf("The string size exceeds the internal buffer size\n");
2980                 return -1;
2981         }
2982         snprintf(s, sizeof(s), "%.*s", size, p);
2983         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2984         if (ret <= 0 || ret != num) {
2985                 printf("The bits of masks do not match the number of "
2986                                         "reta entries: %u\n", num);
2987                 return -1;
2988         }
2989         for (i = 0; i < ret; i++)
2990                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2991
2992         return 0;
2993 }
2994
2995 static void
2996 cmd_showport_reta_parsed(void *parsed_result,
2997                          __attribute__((unused)) struct cmdline *cl,
2998                          __attribute__((unused)) void *data)
2999 {
3000         struct cmd_showport_reta *res = parsed_result;
3001         struct rte_eth_rss_reta_entry64 reta_conf[8];
3002         struct rte_eth_dev_info dev_info;
3003         uint16_t max_reta_size;
3004
3005         memset(&dev_info, 0, sizeof(dev_info));
3006         rte_eth_dev_info_get(res->port_id, &dev_info);
3007         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3008         if (res->size == 0 || res->size > max_reta_size) {
3009                 printf("Invalid redirection table size: %u (1-%u)\n",
3010                         res->size, max_reta_size);
3011                 return;
3012         }
3013
3014         memset(reta_conf, 0, sizeof(reta_conf));
3015         if (showport_parse_reta_config(reta_conf, res->size,
3016                                 res->list_of_items) < 0) {
3017                 printf("Invalid string: %s for reta masks\n",
3018                                         res->list_of_items);
3019                 return;
3020         }
3021         port_rss_reta_info(res->port_id, reta_conf, res->size);
3022 }
3023
3024 cmdline_parse_token_string_t cmd_showport_reta_show =
3025         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3026 cmdline_parse_token_string_t cmd_showport_reta_port =
3027         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3028 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3029         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3030 cmdline_parse_token_string_t cmd_showport_reta_rss =
3031         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3032 cmdline_parse_token_string_t cmd_showport_reta_reta =
3033         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3034 cmdline_parse_token_num_t cmd_showport_reta_size =
3035         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3036 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3037         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3038                                         list_of_items, NULL);
3039
3040 cmdline_parse_inst_t cmd_showport_reta = {
3041         .f = cmd_showport_reta_parsed,
3042         .data = NULL,
3043         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3044         .tokens = {
3045                 (void *)&cmd_showport_reta_show,
3046                 (void *)&cmd_showport_reta_port,
3047                 (void *)&cmd_showport_reta_port_id,
3048                 (void *)&cmd_showport_reta_rss,
3049                 (void *)&cmd_showport_reta_reta,
3050                 (void *)&cmd_showport_reta_size,
3051                 (void *)&cmd_showport_reta_list_of_items,
3052                 NULL,
3053         },
3054 };
3055
3056 /* *** Show RSS hash configuration *** */
3057 struct cmd_showport_rss_hash {
3058         cmdline_fixed_string_t show;
3059         cmdline_fixed_string_t port;
3060         portid_t port_id;
3061         cmdline_fixed_string_t rss_hash;
3062         cmdline_fixed_string_t rss_type;
3063         cmdline_fixed_string_t key; /* optional argument */
3064 };
3065
3066 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3067                                 __attribute__((unused)) struct cmdline *cl,
3068                                 void *show_rss_key)
3069 {
3070         struct cmd_showport_rss_hash *res = parsed_result;
3071
3072         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3073 }
3074
3075 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3076         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3077 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3078         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3079 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3080         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3081 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3082         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3083                                  "rss-hash");
3084 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3085         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3086
3087 cmdline_parse_inst_t cmd_showport_rss_hash = {
3088         .f = cmd_showport_rss_hash_parsed,
3089         .data = NULL,
3090         .help_str = "show port <port_id> rss-hash",
3091         .tokens = {
3092                 (void *)&cmd_showport_rss_hash_show,
3093                 (void *)&cmd_showport_rss_hash_port,
3094                 (void *)&cmd_showport_rss_hash_port_id,
3095                 (void *)&cmd_showport_rss_hash_rss_hash,
3096                 NULL,
3097         },
3098 };
3099
3100 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3101         .f = cmd_showport_rss_hash_parsed,
3102         .data = (void *)1,
3103         .help_str = "show port <port_id> rss-hash key",
3104         .tokens = {
3105                 (void *)&cmd_showport_rss_hash_show,
3106                 (void *)&cmd_showport_rss_hash_port,
3107                 (void *)&cmd_showport_rss_hash_port_id,
3108                 (void *)&cmd_showport_rss_hash_rss_hash,
3109                 (void *)&cmd_showport_rss_hash_rss_key,
3110                 NULL,
3111         },
3112 };
3113
3114 /* *** Configure DCB *** */
3115 struct cmd_config_dcb {
3116         cmdline_fixed_string_t port;
3117         cmdline_fixed_string_t config;
3118         portid_t port_id;
3119         cmdline_fixed_string_t dcb;
3120         cmdline_fixed_string_t vt;
3121         cmdline_fixed_string_t vt_en;
3122         uint8_t num_tcs;
3123         cmdline_fixed_string_t pfc;
3124         cmdline_fixed_string_t pfc_en;
3125 };
3126
3127 static void
3128 cmd_config_dcb_parsed(void *parsed_result,
3129                         __attribute__((unused)) struct cmdline *cl,
3130                         __attribute__((unused)) void *data)
3131 {
3132         struct cmd_config_dcb *res = parsed_result;
3133         portid_t port_id = res->port_id;
3134         struct rte_port *port;
3135         uint8_t pfc_en;
3136         int ret;
3137
3138         port = &ports[port_id];
3139         /** Check if the port is not started **/
3140         if (port->port_status != RTE_PORT_STOPPED) {
3141                 printf("Please stop port %d first\n", port_id);
3142                 return;
3143         }
3144
3145         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3146                 printf("The invalid number of traffic class,"
3147                         " only 4 or 8 allowed.\n");
3148                 return;
3149         }
3150
3151         if (nb_fwd_lcores < res->num_tcs) {
3152                 printf("nb_cores shouldn't be less than number of TCs.\n");
3153                 return;
3154         }
3155         if (!strncmp(res->pfc_en, "on", 2))
3156                 pfc_en = 1;
3157         else
3158                 pfc_en = 0;
3159
3160         /* DCB in VT mode */
3161         if (!strncmp(res->vt_en, "on", 2))
3162                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3163                                 (enum rte_eth_nb_tcs)res->num_tcs,
3164                                 pfc_en);
3165         else
3166                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3167                                 (enum rte_eth_nb_tcs)res->num_tcs,
3168                                 pfc_en);
3169
3170
3171         if (ret != 0) {
3172                 printf("Cannot initialize network ports.\n");
3173                 return;
3174         }
3175
3176         cmd_reconfig_device_queue(port_id, 1, 1);
3177 }
3178
3179 cmdline_parse_token_string_t cmd_config_dcb_port =
3180         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3181 cmdline_parse_token_string_t cmd_config_dcb_config =
3182         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3183 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3184         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3185 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3186         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3187 cmdline_parse_token_string_t cmd_config_dcb_vt =
3188         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3189 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3190         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3191 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3192         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3193 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3194         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3195 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3196         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3197
3198 cmdline_parse_inst_t cmd_config_dcb = {
3199         .f = cmd_config_dcb_parsed,
3200         .data = NULL,
3201         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3202         .tokens = {
3203                 (void *)&cmd_config_dcb_port,
3204                 (void *)&cmd_config_dcb_config,
3205                 (void *)&cmd_config_dcb_port_id,
3206                 (void *)&cmd_config_dcb_dcb,
3207                 (void *)&cmd_config_dcb_vt,
3208                 (void *)&cmd_config_dcb_vt_en,
3209                 (void *)&cmd_config_dcb_num_tcs,
3210                 (void *)&cmd_config_dcb_pfc,
3211                 (void *)&cmd_config_dcb_pfc_en,
3212                 NULL,
3213         },
3214 };
3215
3216 /* *** configure number of packets per burst *** */
3217 struct cmd_config_burst {
3218         cmdline_fixed_string_t port;
3219         cmdline_fixed_string_t keyword;
3220         cmdline_fixed_string_t all;
3221         cmdline_fixed_string_t name;
3222         uint16_t value;
3223 };
3224
3225 static void
3226 cmd_config_burst_parsed(void *parsed_result,
3227                         __attribute__((unused)) struct cmdline *cl,
3228                         __attribute__((unused)) void *data)
3229 {
3230         struct cmd_config_burst *res = parsed_result;
3231         struct rte_eth_dev_info dev_info;
3232         uint16_t rec_nb_pkts;
3233
3234         if (!all_ports_stopped()) {
3235                 printf("Please stop all ports first\n");
3236                 return;
3237         }
3238
3239         if (!strcmp(res->name, "burst")) {
3240                 if (res->value == 0) {
3241                         /* If user gives a value of zero, query the PMD for
3242                          * its recommended Rx burst size. Testpmd uses a single
3243                          * size for all ports, so assume all ports are the same
3244                          * NIC model and use the values from Port 0.
3245                          */
3246                         rte_eth_dev_info_get(0, &dev_info);
3247                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3248
3249                         if (rec_nb_pkts == 0) {
3250                                 printf("PMD does not recommend a burst size.\n"
3251                                         "User provided value must be between"
3252                                         " 1 and %d\n", MAX_PKT_BURST);
3253                                 return;
3254                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3255                                 printf("PMD recommended burst size of %d"
3256                                         " exceeds maximum value of %d\n",
3257                                         rec_nb_pkts, MAX_PKT_BURST);
3258                                 return;
3259                         }
3260                         printf("Using PMD-provided burst value of %d\n",
3261                                 rec_nb_pkts);
3262                         nb_pkt_per_burst = rec_nb_pkts;
3263                 } else if (res->value > MAX_PKT_BURST) {
3264                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3265                         return;
3266                 } else
3267                         nb_pkt_per_burst = res->value;
3268         } else {
3269                 printf("Unknown parameter\n");
3270                 return;
3271         }
3272
3273         init_port_config();
3274
3275         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3276 }
3277
3278 cmdline_parse_token_string_t cmd_config_burst_port =
3279         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3280 cmdline_parse_token_string_t cmd_config_burst_keyword =
3281         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3282 cmdline_parse_token_string_t cmd_config_burst_all =
3283         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3284 cmdline_parse_token_string_t cmd_config_burst_name =
3285         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3286 cmdline_parse_token_num_t cmd_config_burst_value =
3287         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3288
3289 cmdline_parse_inst_t cmd_config_burst = {
3290         .f = cmd_config_burst_parsed,
3291         .data = NULL,
3292         .help_str = "port config all burst <value>",
3293         .tokens = {
3294                 (void *)&cmd_config_burst_port,
3295                 (void *)&cmd_config_burst_keyword,
3296                 (void *)&cmd_config_burst_all,
3297                 (void *)&cmd_config_burst_name,
3298                 (void *)&cmd_config_burst_value,
3299                 NULL,
3300         },
3301 };
3302
3303 /* *** configure rx/tx queues *** */
3304 struct cmd_config_thresh {
3305         cmdline_fixed_string_t port;
3306         cmdline_fixed_string_t keyword;
3307         cmdline_fixed_string_t all;
3308         cmdline_fixed_string_t name;
3309         uint8_t value;
3310 };
3311
3312 static void
3313 cmd_config_thresh_parsed(void *parsed_result,
3314                         __attribute__((unused)) struct cmdline *cl,
3315                         __attribute__((unused)) void *data)
3316 {
3317         struct cmd_config_thresh *res = parsed_result;
3318
3319         if (!all_ports_stopped()) {
3320                 printf("Please stop all ports first\n");
3321                 return;
3322         }
3323
3324         if (!strcmp(res->name, "txpt"))
3325                 tx_pthresh = res->value;
3326         else if(!strcmp(res->name, "txht"))
3327                 tx_hthresh = res->value;
3328         else if(!strcmp(res->name, "txwt"))
3329                 tx_wthresh = res->value;
3330         else if(!strcmp(res->name, "rxpt"))
3331                 rx_pthresh = res->value;
3332         else if(!strcmp(res->name, "rxht"))
3333                 rx_hthresh = res->value;
3334         else if(!strcmp(res->name, "rxwt"))
3335                 rx_wthresh = res->value;
3336         else {
3337                 printf("Unknown parameter\n");
3338                 return;
3339         }
3340
3341         init_port_config();
3342
3343         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3344 }
3345
3346 cmdline_parse_token_string_t cmd_config_thresh_port =
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3348 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3349         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3350 cmdline_parse_token_string_t cmd_config_thresh_all =
3351         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3352 cmdline_parse_token_string_t cmd_config_thresh_name =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3354                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3355 cmdline_parse_token_num_t cmd_config_thresh_value =
3356         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3357
3358 cmdline_parse_inst_t cmd_config_thresh = {
3359         .f = cmd_config_thresh_parsed,
3360         .data = NULL,
3361         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3362         .tokens = {
3363                 (void *)&cmd_config_thresh_port,
3364                 (void *)&cmd_config_thresh_keyword,
3365                 (void *)&cmd_config_thresh_all,
3366                 (void *)&cmd_config_thresh_name,
3367                 (void *)&cmd_config_thresh_value,
3368                 NULL,
3369         },
3370 };
3371
3372 /* *** configure free/rs threshold *** */
3373 struct cmd_config_threshold {
3374         cmdline_fixed_string_t port;
3375         cmdline_fixed_string_t keyword;
3376         cmdline_fixed_string_t all;
3377         cmdline_fixed_string_t name;
3378         uint16_t value;
3379 };
3380
3381 static void
3382 cmd_config_threshold_parsed(void *parsed_result,
3383                         __attribute__((unused)) struct cmdline *cl,
3384                         __attribute__((unused)) void *data)
3385 {
3386         struct cmd_config_threshold *res = parsed_result;
3387
3388         if (!all_ports_stopped()) {
3389                 printf("Please stop all ports first\n");
3390                 return;
3391         }
3392
3393         if (!strcmp(res->name, "txfreet"))
3394                 tx_free_thresh = res->value;
3395         else if (!strcmp(res->name, "txrst"))
3396                 tx_rs_thresh = res->value;
3397         else if (!strcmp(res->name, "rxfreet"))
3398                 rx_free_thresh = res->value;
3399         else {
3400                 printf("Unknown parameter\n");
3401                 return;
3402         }
3403
3404         init_port_config();
3405
3406         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3407 }
3408
3409 cmdline_parse_token_string_t cmd_config_threshold_port =
3410         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3411 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3412         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3413                                                                 "config");
3414 cmdline_parse_token_string_t cmd_config_threshold_all =
3415         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3416 cmdline_parse_token_string_t cmd_config_threshold_name =
3417         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3418                                                 "txfreet#txrst#rxfreet");
3419 cmdline_parse_token_num_t cmd_config_threshold_value =
3420         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3421
3422 cmdline_parse_inst_t cmd_config_threshold = {
3423         .f = cmd_config_threshold_parsed,
3424         .data = NULL,
3425         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3426         .tokens = {
3427                 (void *)&cmd_config_threshold_port,
3428                 (void *)&cmd_config_threshold_keyword,
3429                 (void *)&cmd_config_threshold_all,
3430                 (void *)&cmd_config_threshold_name,
3431                 (void *)&cmd_config_threshold_value,
3432                 NULL,
3433         },
3434 };
3435
3436 /* *** stop *** */
3437 struct cmd_stop_result {
3438         cmdline_fixed_string_t stop;
3439 };
3440
3441 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3442                             __attribute__((unused)) struct cmdline *cl,
3443                             __attribute__((unused)) void *data)
3444 {
3445         stop_packet_forwarding();
3446 }
3447
3448 cmdline_parse_token_string_t cmd_stop_stop =
3449         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3450
3451 cmdline_parse_inst_t cmd_stop = {
3452         .f = cmd_stop_parsed,
3453         .data = NULL,
3454         .help_str = "stop: Stop packet forwarding",
3455         .tokens = {
3456                 (void *)&cmd_stop_stop,
3457                 NULL,
3458         },
3459 };
3460
3461 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3462
3463 unsigned int
3464 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3465                 unsigned int *parsed_items, int check_unique_values)
3466 {
3467         unsigned int nb_item;
3468         unsigned int value;
3469         unsigned int i;
3470         unsigned int j;
3471         int value_ok;
3472         char c;
3473
3474         /*
3475          * First parse all items in the list and store their value.
3476          */
3477         value = 0;
3478         nb_item = 0;
3479         value_ok = 0;
3480         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3481                 c = str[i];
3482                 if ((c >= '0') && (c <= '9')) {
3483                         value = (unsigned int) (value * 10 + (c - '0'));
3484                         value_ok = 1;
3485                         continue;
3486                 }
3487                 if (c != ',') {
3488                         printf("character %c is not a decimal digit\n", c);
3489                         return 0;
3490                 }
3491                 if (! value_ok) {
3492                         printf("No valid value before comma\n");
3493                         return 0;
3494                 }
3495                 if (nb_item < max_items) {
3496                         parsed_items[nb_item] = value;
3497                         value_ok = 0;
3498                         value = 0;
3499                 }
3500                 nb_item++;
3501         }
3502         if (nb_item >= max_items) {
3503                 printf("Number of %s = %u > %u (maximum items)\n",
3504                        item_name, nb_item + 1, max_items);
3505                 return 0;
3506         }
3507         parsed_items[nb_item++] = value;
3508         if (! check_unique_values)
3509                 return nb_item;
3510
3511         /*
3512          * Then, check that all values in the list are differents.
3513          * No optimization here...
3514          */
3515         for (i = 0; i < nb_item; i++) {
3516                 for (j = i + 1; j < nb_item; j++) {
3517                         if (parsed_items[j] == parsed_items[i]) {
3518                                 printf("duplicated %s %u at index %u and %u\n",
3519                                        item_name, parsed_items[i], i, j);
3520                                 return 0;
3521                         }
3522                 }
3523         }
3524         return nb_item;
3525 }
3526
3527 struct cmd_set_list_result {
3528         cmdline_fixed_string_t cmd_keyword;
3529         cmdline_fixed_string_t list_name;
3530         cmdline_fixed_string_t list_of_items;
3531 };
3532
3533 static void cmd_set_list_parsed(void *parsed_result,
3534                                 __attribute__((unused)) struct cmdline *cl,
3535                                 __attribute__((unused)) void *data)
3536 {
3537         struct cmd_set_list_result *res;
3538         union {
3539                 unsigned int lcorelist[RTE_MAX_LCORE];
3540                 unsigned int portlist[RTE_MAX_ETHPORTS];
3541         } parsed_items;
3542         unsigned int nb_item;
3543
3544         if (test_done == 0) {
3545                 printf("Please stop forwarding first\n");
3546                 return;
3547         }
3548
3549         res = parsed_result;
3550         if (!strcmp(res->list_name, "corelist")) {
3551                 nb_item = parse_item_list(res->list_of_items, "core",
3552                                           RTE_MAX_LCORE,
3553                                           parsed_items.lcorelist, 1);
3554                 if (nb_item > 0) {
3555                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3556                         fwd_config_setup();
3557                 }
3558                 return;
3559         }
3560         if (!strcmp(res->list_name, "portlist")) {
3561                 nb_item = parse_item_list(res->list_of_items, "port",
3562                                           RTE_MAX_ETHPORTS,
3563                                           parsed_items.portlist, 1);
3564                 if (nb_item > 0) {
3565                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3566                         fwd_config_setup();
3567                 }
3568         }
3569 }
3570
3571 cmdline_parse_token_string_t cmd_set_list_keyword =
3572         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3573                                  "set");
3574 cmdline_parse_token_string_t cmd_set_list_name =
3575         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3576                                  "corelist#portlist");
3577 cmdline_parse_token_string_t cmd_set_list_of_items =
3578         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3579                                  NULL);
3580
3581 cmdline_parse_inst_t cmd_set_fwd_list = {
3582         .f = cmd_set_list_parsed,
3583         .data = NULL,
3584         .help_str = "set corelist|portlist <list0[,list1]*>",
3585         .tokens = {
3586                 (void *)&cmd_set_list_keyword,
3587                 (void *)&cmd_set_list_name,
3588                 (void *)&cmd_set_list_of_items,
3589                 NULL,
3590         },
3591 };
3592
3593 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3594
3595 struct cmd_setmask_result {
3596         cmdline_fixed_string_t set;
3597         cmdline_fixed_string_t mask;
3598         uint64_t hexavalue;
3599 };
3600
3601 static void cmd_set_mask_parsed(void *parsed_result,
3602                                 __attribute__((unused)) struct cmdline *cl,
3603                                 __attribute__((unused)) void *data)
3604 {
3605         struct cmd_setmask_result *res = parsed_result;
3606
3607         if (test_done == 0) {
3608                 printf("Please stop forwarding first\n");
3609                 return;
3610         }
3611         if (!strcmp(res->mask, "coremask")) {
3612                 set_fwd_lcores_mask(res->hexavalue);
3613                 fwd_config_setup();
3614         } else if (!strcmp(res->mask, "portmask")) {
3615                 set_fwd_ports_mask(res->hexavalue);
3616                 fwd_config_setup();
3617         }
3618 }
3619
3620 cmdline_parse_token_string_t cmd_setmask_set =
3621         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3622 cmdline_parse_token_string_t cmd_setmask_mask =
3623         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3624                                  "coremask#portmask");
3625 cmdline_parse_token_num_t cmd_setmask_value =
3626         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3627
3628 cmdline_parse_inst_t cmd_set_fwd_mask = {
3629         .f = cmd_set_mask_parsed,
3630         .data = NULL,
3631         .help_str = "set coremask|portmask <hexadecimal value>",
3632         .tokens = {
3633                 (void *)&cmd_setmask_set,
3634                 (void *)&cmd_setmask_mask,
3635                 (void *)&cmd_setmask_value,
3636                 NULL,
3637         },
3638 };
3639
3640 /*
3641  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3642  */
3643 struct cmd_set_result {
3644         cmdline_fixed_string_t set;
3645         cmdline_fixed_string_t what;
3646         uint16_t value;
3647 };
3648
3649 static void cmd_set_parsed(void *parsed_result,
3650                            __attribute__((unused)) struct cmdline *cl,
3651                            __attribute__((unused)) void *data)
3652 {
3653         struct cmd_set_result *res = parsed_result;
3654         if (!strcmp(res->what, "nbport")) {
3655                 set_fwd_ports_number(res->value);
3656                 fwd_config_setup();
3657         } else if (!strcmp(res->what, "nbcore")) {
3658                 set_fwd_lcores_number(res->value);
3659                 fwd_config_setup();
3660         } else if (!strcmp(res->what, "burst"))
3661                 set_nb_pkt_per_burst(res->value);
3662         else if (!strcmp(res->what, "verbose"))
3663                 set_verbose_level(res->value);
3664 }
3665
3666 cmdline_parse_token_string_t cmd_set_set =
3667         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3668 cmdline_parse_token_string_t cmd_set_what =
3669         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3670                                  "nbport#nbcore#burst#verbose");
3671 cmdline_parse_token_num_t cmd_set_value =
3672         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3673
3674 cmdline_parse_inst_t cmd_set_numbers = {
3675         .f = cmd_set_parsed,
3676         .data = NULL,
3677         .help_str = "set nbport|nbcore|burst|verbose <value>",
3678         .tokens = {
3679                 (void *)&cmd_set_set,
3680                 (void *)&cmd_set_what,
3681                 (void *)&cmd_set_value,
3682                 NULL,
3683         },
3684 };
3685
3686 /* *** SET LOG LEVEL CONFIGURATION *** */
3687
3688 struct cmd_set_log_result {
3689         cmdline_fixed_string_t set;
3690         cmdline_fixed_string_t log;
3691         cmdline_fixed_string_t type;
3692         uint32_t level;
3693 };
3694
3695 static void
3696 cmd_set_log_parsed(void *parsed_result,
3697                    __attribute__((unused)) struct cmdline *cl,
3698                    __attribute__((unused)) void *data)
3699 {
3700         struct cmd_set_log_result *res;
3701         int ret;
3702
3703         res = parsed_result;
3704         if (!strcmp(res->type, "global"))
3705                 rte_log_set_global_level(res->level);
3706         else {
3707                 ret = rte_log_set_level_regexp(res->type, res->level);
3708                 if (ret < 0)
3709                         printf("Unable to set log level\n");
3710         }
3711 }
3712
3713 cmdline_parse_token_string_t cmd_set_log_set =
3714         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3715 cmdline_parse_token_string_t cmd_set_log_log =
3716         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3717 cmdline_parse_token_string_t cmd_set_log_type =
3718         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3719 cmdline_parse_token_num_t cmd_set_log_level =
3720         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3721
3722 cmdline_parse_inst_t cmd_set_log = {
3723         .f = cmd_set_log_parsed,
3724         .data = NULL,
3725         .help_str = "set log global|<type> <level>",
3726         .tokens = {
3727                 (void *)&cmd_set_log_set,
3728                 (void *)&cmd_set_log_log,
3729                 (void *)&cmd_set_log_type,
3730                 (void *)&cmd_set_log_level,
3731                 NULL,
3732         },
3733 };
3734
3735 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3736
3737 struct cmd_set_txpkts_result {
3738         cmdline_fixed_string_t cmd_keyword;
3739         cmdline_fixed_string_t txpkts;
3740         cmdline_fixed_string_t seg_lengths;
3741 };
3742
3743 static void
3744 cmd_set_txpkts_parsed(void *parsed_result,
3745                       __attribute__((unused)) struct cmdline *cl,
3746                       __attribute__((unused)) void *data)
3747 {
3748         struct cmd_set_txpkts_result *res;
3749         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3750         unsigned int nb_segs;
3751
3752         res = parsed_result;
3753         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3754                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3755         if (nb_segs > 0)
3756                 set_tx_pkt_segments(seg_lengths, nb_segs);
3757 }
3758
3759 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3760         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3761                                  cmd_keyword, "set");
3762 cmdline_parse_token_string_t cmd_set_txpkts_name =
3763         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3764                                  txpkts, "txpkts");
3765 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3766         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3767                                  seg_lengths, NULL);
3768
3769 cmdline_parse_inst_t cmd_set_txpkts = {
3770         .f = cmd_set_txpkts_parsed,
3771         .data = NULL,
3772         .help_str = "set txpkts <len0[,len1]*>",
3773         .tokens = {
3774                 (void *)&cmd_set_txpkts_keyword,
3775                 (void *)&cmd_set_txpkts_name,
3776                 (void *)&cmd_set_txpkts_lengths,
3777                 NULL,
3778         },
3779 };
3780
3781 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3782
3783 struct cmd_set_txsplit_result {
3784         cmdline_fixed_string_t cmd_keyword;
3785         cmdline_fixed_string_t txsplit;
3786         cmdline_fixed_string_t mode;
3787 };
3788
3789 static void
3790 cmd_set_txsplit_parsed(void *parsed_result,
3791                       __attribute__((unused)) struct cmdline *cl,
3792                       __attribute__((unused)) void *data)
3793 {
3794         struct cmd_set_txsplit_result *res;
3795
3796         res = parsed_result;
3797         set_tx_pkt_split(res->mode);
3798 }
3799
3800 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3801         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3802                                  cmd_keyword, "set");
3803 cmdline_parse_token_string_t cmd_set_txsplit_name =
3804         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3805                                  txsplit, "txsplit");
3806 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3807         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3808                                  mode, NULL);
3809
3810 cmdline_parse_inst_t cmd_set_txsplit = {
3811         .f = cmd_set_txsplit_parsed,
3812         .data = NULL,
3813         .help_str = "set txsplit on|off|rand",
3814         .tokens = {
3815                 (void *)&cmd_set_txsplit_keyword,
3816                 (void *)&cmd_set_txsplit_name,
3817                 (void *)&cmd_set_txsplit_mode,
3818                 NULL,
3819         },
3820 };
3821
3822 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3823 struct cmd_rx_vlan_filter_all_result {
3824         cmdline_fixed_string_t rx_vlan;
3825         cmdline_fixed_string_t what;
3826         cmdline_fixed_string_t all;
3827         portid_t port_id;
3828 };
3829
3830 static void
3831 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3832                               __attribute__((unused)) struct cmdline *cl,
3833                               __attribute__((unused)) void *data)
3834 {
3835         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3836
3837         if (!strcmp(res->what, "add"))
3838                 rx_vlan_all_filter_set(res->port_id, 1);
3839         else
3840                 rx_vlan_all_filter_set(res->port_id, 0);
3841 }
3842
3843 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3844         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3845                                  rx_vlan, "rx_vlan");
3846 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3847         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3848                                  what, "add#rm");
3849 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3850         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3851                                  all, "all");
3852 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3853         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3854                               port_id, UINT16);
3855
3856 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3857         .f = cmd_rx_vlan_filter_all_parsed,
3858         .data = NULL,
3859         .help_str = "rx_vlan add|rm all <port_id>: "
3860                 "Add/Remove all identifiers to/from the set of VLAN "
3861                 "identifiers filtered by a port",
3862         .tokens = {
3863                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3864                 (void *)&cmd_rx_vlan_filter_all_what,
3865                 (void *)&cmd_rx_vlan_filter_all_all,
3866                 (void *)&cmd_rx_vlan_filter_all_portid,
3867                 NULL,
3868         },
3869 };
3870
3871 /* *** VLAN OFFLOAD SET ON A PORT *** */
3872 struct cmd_vlan_offload_result {
3873         cmdline_fixed_string_t vlan;
3874         cmdline_fixed_string_t set;
3875         cmdline_fixed_string_t vlan_type;
3876         cmdline_fixed_string_t what;
3877         cmdline_fixed_string_t on;
3878         cmdline_fixed_string_t port_id;
3879 };
3880
3881 static void
3882 cmd_vlan_offload_parsed(void *parsed_result,
3883                           __attribute__((unused)) struct cmdline *cl,
3884                           __attribute__((unused)) void *data)
3885 {
3886         int on;
3887         struct cmd_vlan_offload_result *res = parsed_result;
3888         char *str;
3889         int i, len = 0;
3890         portid_t port_id = 0;
3891         unsigned int tmp;
3892
3893         str = res->port_id;
3894         len = strnlen(str, STR_TOKEN_SIZE);
3895         i = 0;
3896         /* Get port_id first */
3897         while(i < len){
3898                 if(str[i] == ',')
3899                         break;
3900
3901                 i++;
3902         }
3903         str[i]='\0';
3904         tmp = strtoul(str, NULL, 0);
3905         /* If port_id greater that what portid_t can represent, return */
3906         if(tmp >= RTE_MAX_ETHPORTS)
3907                 return;
3908         port_id = (portid_t)tmp;
3909
3910         if (!strcmp(res->on, "on"))
3911                 on = 1;
3912         else
3913                 on = 0;
3914
3915         if (!strcmp(res->what, "strip"))
3916                 rx_vlan_strip_set(port_id,  on);
3917         else if(!strcmp(res->what, "stripq")){
3918                 uint16_t queue_id = 0;
3919
3920                 /* No queue_id, return */
3921                 if(i + 1 >= len) {
3922                         printf("must specify (port,queue_id)\n");
3923                         return;
3924                 }
3925                 tmp = strtoul(str + i + 1, NULL, 0);
3926                 /* If queue_id greater that what 16-bits can represent, return */
3927                 if(tmp > 0xffff)
3928                         return;
3929
3930                 queue_id = (uint16_t)tmp;
3931                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3932         }
3933         else if (!strcmp(res->what, "filter"))
3934                 rx_vlan_filter_set(port_id, on);
3935         else
3936                 vlan_extend_set(port_id, on);
3937
3938         return;
3939 }
3940
3941 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3942         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3943                                  vlan, "vlan");
3944 cmdline_parse_token_string_t cmd_vlan_offload_set =
3945         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3946                                  set, "set");
3947 cmdline_parse_token_string_t cmd_vlan_offload_what =
3948         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3949                                  what, "strip#filter#qinq#stripq");
3950 cmdline_parse_token_string_t cmd_vlan_offload_on =
3951         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3952                               on, "on#off");
3953 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3954         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3955                               port_id, NULL);
3956
3957 cmdline_parse_inst_t cmd_vlan_offload = {
3958         .f = cmd_vlan_offload_parsed,
3959         .data = NULL,
3960         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3961                 "<port_id[,queue_id]>: "
3962                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3963         .tokens = {
3964                 (void *)&cmd_vlan_offload_vlan,
3965                 (void *)&cmd_vlan_offload_set,
3966                 (void *)&cmd_vlan_offload_what,
3967                 (void *)&cmd_vlan_offload_on,
3968                 (void *)&cmd_vlan_offload_portid,
3969                 NULL,
3970         },
3971 };
3972
3973 /* *** VLAN TPID SET ON A PORT *** */
3974 struct cmd_vlan_tpid_result {
3975         cmdline_fixed_string_t vlan;
3976         cmdline_fixed_string_t set;
3977         cmdline_fixed_string_t vlan_type;
3978         cmdline_fixed_string_t what;
3979         uint16_t tp_id;
3980         portid_t port_id;
3981 };
3982
3983 static void
3984 cmd_vlan_tpid_parsed(void *parsed_result,
3985                           __attribute__((unused)) struct cmdline *cl,
3986                           __attribute__((unused)) void *data)
3987 {
3988         struct cmd_vlan_tpid_result *res = parsed_result;
3989         enum rte_vlan_type vlan_type;
3990
3991         if (!strcmp(res->vlan_type, "inner"))
3992                 vlan_type = ETH_VLAN_TYPE_INNER;
3993         else if (!strcmp(res->vlan_type, "outer"))
3994                 vlan_type = ETH_VLAN_TYPE_OUTER;
3995         else {
3996                 printf("Unknown vlan type\n");
3997                 return;
3998         }
3999         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4000 }
4001
4002 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4003         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4004                                  vlan, "vlan");
4005 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4006         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4007                                  set, "set");
4008 cmdline_parse_token_string_t cmd_vlan_type =
4009         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4010                                  vlan_type, "inner#outer");
4011 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4012         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4013                                  what, "tpid");
4014 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4015         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4016                               tp_id, UINT16);
4017 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4018         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4019                               port_id, UINT16);
4020
4021 cmdline_parse_inst_t cmd_vlan_tpid = {
4022         .f = cmd_vlan_tpid_parsed,
4023         .data = NULL,
4024         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4025                 "Set the VLAN Ether type",
4026         .tokens = {
4027                 (void *)&cmd_vlan_tpid_vlan,
4028                 (void *)&cmd_vlan_tpid_set,
4029                 (void *)&cmd_vlan_type,
4030                 (void *)&cmd_vlan_tpid_what,
4031                 (void *)&cmd_vlan_tpid_tpid,
4032                 (void *)&cmd_vlan_tpid_portid,
4033                 NULL,
4034         },
4035 };
4036
4037 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4038 struct cmd_rx_vlan_filter_result {
4039         cmdline_fixed_string_t rx_vlan;
4040         cmdline_fixed_string_t what;
4041         uint16_t vlan_id;
4042         portid_t port_id;
4043 };
4044
4045 static void
4046 cmd_rx_vlan_filter_parsed(void *parsed_result,
4047                           __attribute__((unused)) struct cmdline *cl,
4048                           __attribute__((unused)) void *data)
4049 {
4050         struct cmd_rx_vlan_filter_result *res = parsed_result;
4051
4052         if (!strcmp(res->what, "add"))
4053                 rx_vft_set(res->port_id, res->vlan_id, 1);
4054         else
4055                 rx_vft_set(res->port_id, res->vlan_id, 0);
4056 }
4057
4058 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4059         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4060                                  rx_vlan, "rx_vlan");
4061 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4062         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4063                                  what, "add#rm");
4064 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4065         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4066                               vlan_id, UINT16);
4067 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4068         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4069                               port_id, UINT16);
4070
4071 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4072         .f = cmd_rx_vlan_filter_parsed,
4073         .data = NULL,
4074         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4075                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4076                 "identifiers filtered by a port",
4077         .tokens = {
4078                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4079                 (void *)&cmd_rx_vlan_filter_what,
4080                 (void *)&cmd_rx_vlan_filter_vlanid,
4081                 (void *)&cmd_rx_vlan_filter_portid,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4087 struct cmd_tx_vlan_set_result {
4088         cmdline_fixed_string_t tx_vlan;
4089         cmdline_fixed_string_t set;
4090         portid_t port_id;
4091         uint16_t vlan_id;
4092 };
4093
4094 static void
4095 cmd_tx_vlan_set_parsed(void *parsed_result,
4096                        __attribute__((unused)) struct cmdline *cl,
4097                        __attribute__((unused)) void *data)
4098 {
4099         struct cmd_tx_vlan_set_result *res = parsed_result;
4100
4101         if (!port_is_stopped(res->port_id)) {
4102                 printf("Please stop port %d first\n", res->port_id);
4103                 return;
4104         }
4105
4106         tx_vlan_set(res->port_id, res->vlan_id);
4107
4108         cmd_reconfig_device_queue(res->port_id, 1, 1);
4109 }
4110
4111 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4112         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4113                                  tx_vlan, "tx_vlan");
4114 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4115         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4116                                  set, "set");
4117 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4119                               port_id, UINT16);
4120 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4121         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4122                               vlan_id, UINT16);
4123
4124 cmdline_parse_inst_t cmd_tx_vlan_set = {
4125         .f = cmd_tx_vlan_set_parsed,
4126         .data = NULL,
4127         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4128                 "Enable hardware insertion of a single VLAN header "
4129                 "with a given TAG Identifier in packets sent on a port",
4130         .tokens = {
4131                 (void *)&cmd_tx_vlan_set_tx_vlan,
4132                 (void *)&cmd_tx_vlan_set_set,
4133                 (void *)&cmd_tx_vlan_set_portid,
4134                 (void *)&cmd_tx_vlan_set_vlanid,
4135                 NULL,
4136         },
4137 };
4138
4139 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4140 struct cmd_tx_vlan_set_qinq_result {
4141         cmdline_fixed_string_t tx_vlan;
4142         cmdline_fixed_string_t set;
4143         portid_t port_id;
4144         uint16_t vlan_id;
4145         uint16_t vlan_id_outer;
4146 };
4147
4148 static void
4149 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4150                             __attribute__((unused)) struct cmdline *cl,
4151                             __attribute__((unused)) void *data)
4152 {
4153         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4154
4155         if (!port_is_stopped(res->port_id)) {
4156                 printf("Please stop port %d first\n", res->port_id);
4157                 return;
4158         }
4159
4160         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4161
4162         cmd_reconfig_device_queue(res->port_id, 1, 1);
4163 }
4164
4165 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4166         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4167                 tx_vlan, "tx_vlan");
4168 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4169         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4170                 set, "set");
4171 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4172         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4173                 port_id, UINT16);
4174 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4175         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4176                 vlan_id, UINT16);
4177 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4178         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4179                 vlan_id_outer, UINT16);
4180
4181 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4182         .f = cmd_tx_vlan_set_qinq_parsed,
4183         .data = NULL,
4184         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4185                 "Enable hardware insertion of double VLAN header "
4186                 "with given TAG Identifiers in packets sent on a port",
4187         .tokens = {
4188                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4189                 (void *)&cmd_tx_vlan_set_qinq_set,
4190                 (void *)&cmd_tx_vlan_set_qinq_portid,
4191                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4192                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4193                 NULL,
4194         },
4195 };
4196
4197 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4198 struct cmd_tx_vlan_set_pvid_result {
4199         cmdline_fixed_string_t tx_vlan;
4200         cmdline_fixed_string_t set;
4201         cmdline_fixed_string_t pvid;
4202         portid_t port_id;
4203         uint16_t vlan_id;
4204         cmdline_fixed_string_t mode;
4205 };
4206
4207 static void
4208 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4209                             __attribute__((unused)) struct cmdline *cl,
4210                             __attribute__((unused)) void *data)
4211 {
4212         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4213
4214         if (strcmp(res->mode, "on") == 0)
4215                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4216         else
4217                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4218 }
4219
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4222                                  tx_vlan, "tx_vlan");
4223 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4224         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4225                                  set, "set");
4226 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4227         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4228                                  pvid, "pvid");
4229 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4230         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4231                              port_id, UINT16);
4232 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4233         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4234                               vlan_id, UINT16);
4235 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4236         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4237                                  mode, "on#off");
4238
4239 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4240         .f = cmd_tx_vlan_set_pvid_parsed,
4241         .data = NULL,
4242         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4243         .tokens = {
4244                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4245                 (void *)&cmd_tx_vlan_set_pvid_set,
4246                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4247                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4248                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4249                 (void *)&cmd_tx_vlan_set_pvid_mode,
4250                 NULL,
4251         },
4252 };
4253
4254 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4255 struct cmd_tx_vlan_reset_result {
4256         cmdline_fixed_string_t tx_vlan;
4257         cmdline_fixed_string_t reset;
4258         portid_t port_id;
4259 };
4260
4261 static void
4262 cmd_tx_vlan_reset_parsed(void *parsed_result,
4263                          __attribute__((unused)) struct cmdline *cl,
4264                          __attribute__((unused)) void *data)
4265 {
4266         struct cmd_tx_vlan_reset_result *res = parsed_result;
4267
4268         if (!port_is_stopped(res->port_id)) {
4269                 printf("Please stop port %d first\n", res->port_id);
4270                 return;
4271         }
4272
4273         tx_vlan_reset(res->port_id);
4274
4275         cmd_reconfig_device_queue(res->port_id, 1, 1);
4276 }
4277
4278 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4279         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4280                                  tx_vlan, "tx_vlan");
4281 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4282         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4283                                  reset, "reset");
4284 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4286                               port_id, UINT16);
4287
4288 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4289         .f = cmd_tx_vlan_reset_parsed,
4290         .data = NULL,
4291         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4292                 "VLAN header in packets sent on a port",
4293         .tokens = {
4294                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4295                 (void *)&cmd_tx_vlan_reset_reset,
4296                 (void *)&cmd_tx_vlan_reset_portid,
4297                 NULL,
4298         },
4299 };
4300
4301
4302 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4303 struct cmd_csum_result {
4304         cmdline_fixed_string_t csum;
4305         cmdline_fixed_string_t mode;
4306         cmdline_fixed_string_t proto;
4307         cmdline_fixed_string_t hwsw;
4308         portid_t port_id;
4309 };
4310
4311 static void
4312 csum_show(int port_id)
4313 {
4314         struct rte_eth_dev_info dev_info;
4315         uint64_t tx_offloads;
4316
4317         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4318         printf("Parse tunnel is %s\n",
4319                 (ports[port_id].parse_tunnel) ? "on" : "off");
4320         printf("IP checksum offload is %s\n",
4321                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4322         printf("UDP checksum offload is %s\n",
4323                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4324         printf("TCP checksum offload is %s\n",
4325                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4326         printf("SCTP checksum offload is %s\n",
4327                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4328         printf("Outer-Ip checksum offload is %s\n",
4329                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4330         printf("Outer-Udp checksum offload is %s\n",
4331                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4332
4333         /* display warnings if configuration is not supported by the NIC */
4334         rte_eth_dev_info_get(port_id, &dev_info);
4335         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4336                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4337                 printf("Warning: hardware IP checksum enabled but not "
4338                         "supported by port %d\n", port_id);
4339         }
4340         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4341                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4342                 printf("Warning: hardware UDP checksum enabled but not "
4343                         "supported by port %d\n", port_id);
4344         }
4345         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4346                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4347                 printf("Warning: hardware TCP checksum enabled but not "
4348                         "supported by port %d\n", port_id);
4349         }
4350         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4351                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4352                 printf("Warning: hardware SCTP checksum enabled but not "
4353                         "supported by port %d\n", port_id);
4354         }
4355         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4356                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4357                 printf("Warning: hardware outer IP checksum enabled but not "
4358                         "supported by port %d\n", port_id);
4359         }
4360         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4361                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4362                         == 0) {
4363                 printf("Warning: hardware outer UDP checksum enabled but not "
4364                         "supported by port %d\n", port_id);
4365         }
4366 }
4367
4368 static void
4369 cmd_config_queue_tx_offloads(struct rte_port *port)
4370 {
4371         int k;
4372
4373         /* Apply queue tx offloads configuration */
4374         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4375                 port->tx_conf[k].offloads =
4376                         port->dev_conf.txmode.offloads;
4377 }
4378
4379 static void
4380 cmd_csum_parsed(void *parsed_result,
4381                        __attribute__((unused)) struct cmdline *cl,
4382                        __attribute__((unused)) void *data)
4383 {
4384         struct cmd_csum_result *res = parsed_result;
4385         int hw = 0;
4386         uint64_t csum_offloads = 0;
4387         struct rte_eth_dev_info dev_info;
4388
4389         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4390                 printf("invalid port %d\n", res->port_id);
4391                 return;
4392         }
4393         if (!port_is_stopped(res->port_id)) {
4394                 printf("Please stop port %d first\n", res->port_id);
4395                 return;
4396         }
4397
4398         rte_eth_dev_info_get(res->port_id, &dev_info);
4399         if (!strcmp(res->mode, "set")) {
4400
4401                 if (!strcmp(res->hwsw, "hw"))
4402                         hw = 1;
4403
4404                 if (!strcmp(res->proto, "ip")) {
4405                         if (hw == 0 || (dev_info.tx_offload_capa &
4406                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4407                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4408                         } else {
4409                                 printf("IP checksum offload is not supported "
4410                                        "by port %u\n", res->port_id);
4411                         }
4412                 } else if (!strcmp(res->proto, "udp")) {
4413                         if (hw == 0 || (dev_info.tx_offload_capa &
4414                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4415                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4416                         } else {
4417                                 printf("UDP checksum offload is not supported "
4418                                        "by port %u\n", res->port_id);
4419                         }
4420                 } else if (!strcmp(res->proto, "tcp")) {
4421                         if (hw == 0 || (dev_info.tx_offload_capa &
4422                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4423                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4424                         } else {
4425                                 printf("TCP checksum offload is not supported "
4426                                        "by port %u\n", res->port_id);
4427                         }
4428                 } else if (!strcmp(res->proto, "sctp")) {
4429                         if (hw == 0 || (dev_info.tx_offload_capa &
4430                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4431                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4432                         } else {
4433                                 printf("SCTP checksum offload is not supported "
4434                                        "by port %u\n", res->port_id);
4435                         }
4436                 } else if (!strcmp(res->proto, "outer-ip")) {
4437                         if (hw == 0 || (dev_info.tx_offload_capa &
4438                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4439                                 csum_offloads |=
4440                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4441                         } else {
4442                                 printf("Outer IP checksum offload is not "
4443                                        "supported by port %u\n", res->port_id);
4444                         }
4445                 } else if (!strcmp(res->proto, "outer-udp")) {
4446                         if (hw == 0 || (dev_info.tx_offload_capa &
4447                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4448                                 csum_offloads |=
4449                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4450                         } else {
4451                                 printf("Outer UDP checksum offload is not "
4452                                        "supported by port %u\n", res->port_id);
4453                         }
4454                 }
4455
4456                 if (hw) {
4457                         ports[res->port_id].dev_conf.txmode.offloads |=
4458                                                         csum_offloads;
4459                 } else {
4460                         ports[res->port_id].dev_conf.txmode.offloads &=
4461                                                         (~csum_offloads);
4462                 }
4463                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4464         }
4465         csum_show(res->port_id);
4466
4467         cmd_reconfig_device_queue(res->port_id, 1, 1);
4468 }
4469
4470 cmdline_parse_token_string_t cmd_csum_csum =
4471         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4472                                 csum, "csum");
4473 cmdline_parse_token_string_t cmd_csum_mode =
4474         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4475                                 mode, "set");
4476 cmdline_parse_token_string_t cmd_csum_proto =
4477         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4478                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4479 cmdline_parse_token_string_t cmd_csum_hwsw =
4480         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4481                                 hwsw, "hw#sw");
4482 cmdline_parse_token_num_t cmd_csum_portid =
4483         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4484                                 port_id, UINT16);
4485
4486 cmdline_parse_inst_t cmd_csum_set = {
4487         .f = cmd_csum_parsed,
4488         .data = NULL,
4489         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4490                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4491                 "using csum forward engine",
4492         .tokens = {
4493                 (void *)&cmd_csum_csum,
4494                 (void *)&cmd_csum_mode,
4495                 (void *)&cmd_csum_proto,
4496                 (void *)&cmd_csum_hwsw,
4497                 (void *)&cmd_csum_portid,
4498                 NULL,
4499         },
4500 };
4501
4502 cmdline_parse_token_string_t cmd_csum_mode_show =
4503         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4504                                 mode, "show");
4505
4506 cmdline_parse_inst_t cmd_csum_show = {
4507         .f = cmd_csum_parsed,
4508         .data = NULL,
4509         .help_str = "csum show <port_id>: Show checksum offload configuration",
4510         .tokens = {
4511                 (void *)&cmd_csum_csum,
4512                 (void *)&cmd_csum_mode_show,
4513                 (void *)&cmd_csum_portid,
4514                 NULL,
4515         },
4516 };
4517
4518 /* Enable/disable tunnel parsing */
4519 struct cmd_csum_tunnel_result {
4520         cmdline_fixed_string_t csum;
4521         cmdline_fixed_string_t parse;
4522         cmdline_fixed_string_t onoff;
4523         portid_t port_id;
4524 };
4525
4526 static void
4527 cmd_csum_tunnel_parsed(void *parsed_result,
4528                        __attribute__((unused)) struct cmdline *cl,
4529                        __attribute__((unused)) void *data)
4530 {
4531         struct cmd_csum_tunnel_result *res = parsed_result;
4532
4533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4534                 return;
4535
4536         if (!strcmp(res->onoff, "on"))
4537                 ports[res->port_id].parse_tunnel = 1;
4538         else
4539                 ports[res->port_id].parse_tunnel = 0;
4540
4541         csum_show(res->port_id);
4542 }
4543
4544 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4545         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4546                                 csum, "csum");
4547 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4548         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4549                                 parse, "parse-tunnel");
4550 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4551         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4552                                 onoff, "on#off");
4553 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4554         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4555                                 port_id, UINT16);
4556
4557 cmdline_parse_inst_t cmd_csum_tunnel = {
4558         .f = cmd_csum_tunnel_parsed,
4559         .data = NULL,
4560         .help_str = "csum parse-tunnel on|off <port_id>: "
4561                 "Enable/Disable parsing of tunnels for csum engine",
4562         .tokens = {
4563                 (void *)&cmd_csum_tunnel_csum,
4564                 (void *)&cmd_csum_tunnel_parse,
4565                 (void *)&cmd_csum_tunnel_onoff,
4566                 (void *)&cmd_csum_tunnel_portid,
4567                 NULL,
4568         },
4569 };
4570
4571 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4572 struct cmd_tso_set_result {
4573         cmdline_fixed_string_t tso;
4574         cmdline_fixed_string_t mode;
4575         uint16_t tso_segsz;
4576         portid_t port_id;
4577 };
4578
4579 static void
4580 cmd_tso_set_parsed(void *parsed_result,
4581                        __attribute__((unused)) struct cmdline *cl,
4582                        __attribute__((unused)) void *data)
4583 {
4584         struct cmd_tso_set_result *res = parsed_result;
4585         struct rte_eth_dev_info dev_info;
4586
4587         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4588                 return;
4589         if (!port_is_stopped(res->port_id)) {
4590                 printf("Please stop port %d first\n", res->port_id);
4591                 return;
4592         }
4593
4594         if (!strcmp(res->mode, "set"))
4595                 ports[res->port_id].tso_segsz = res->tso_segsz;
4596
4597         rte_eth_dev_info_get(res->port_id, &dev_info);
4598         if ((ports[res->port_id].tso_segsz != 0) &&
4599                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4600                 printf("Error: TSO is not supported by port %d\n",
4601                        res->port_id);
4602                 return;
4603         }
4604
4605         if (ports[res->port_id].tso_segsz == 0) {
4606                 ports[res->port_id].dev_conf.txmode.offloads &=
4607                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4608                 printf("TSO for non-tunneled packets is disabled\n");
4609         } else {
4610                 ports[res->port_id].dev_conf.txmode.offloads |=
4611                                                 DEV_TX_OFFLOAD_TCP_TSO;
4612                 printf("TSO segment size for non-tunneled packets is %d\n",
4613                         ports[res->port_id].tso_segsz);
4614         }
4615         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4616
4617         /* display warnings if configuration is not supported by the NIC */
4618         rte_eth_dev_info_get(res->port_id, &dev_info);
4619         if ((ports[res->port_id].tso_segsz != 0) &&
4620                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4621                 printf("Warning: TSO enabled but not "
4622                         "supported by port %d\n", res->port_id);
4623         }
4624
4625         cmd_reconfig_device_queue(res->port_id, 1, 1);
4626 }
4627
4628 cmdline_parse_token_string_t cmd_tso_set_tso =
4629         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4630                                 tso, "tso");
4631 cmdline_parse_token_string_t cmd_tso_set_mode =
4632         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4633                                 mode, "set");
4634 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4635         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4636                                 tso_segsz, UINT16);
4637 cmdline_parse_token_num_t cmd_tso_set_portid =
4638         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4639                                 port_id, UINT16);
4640
4641 cmdline_parse_inst_t cmd_tso_set = {
4642         .f = cmd_tso_set_parsed,
4643         .data = NULL,
4644         .help_str = "tso set <tso_segsz> <port_id>: "
4645                 "Set TSO segment size of non-tunneled packets for csum engine "
4646                 "(0 to disable)",
4647         .tokens = {
4648                 (void *)&cmd_tso_set_tso,
4649                 (void *)&cmd_tso_set_mode,
4650                 (void *)&cmd_tso_set_tso_segsz,
4651                 (void *)&cmd_tso_set_portid,
4652                 NULL,
4653         },
4654 };
4655
4656 cmdline_parse_token_string_t cmd_tso_show_mode =
4657         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4658                                 mode, "show");
4659
4660
4661 cmdline_parse_inst_t cmd_tso_show = {
4662         .f = cmd_tso_set_parsed,
4663         .data = NULL,
4664         .help_str = "tso show <port_id>: "
4665                 "Show TSO segment size of non-tunneled packets for csum engine",
4666         .tokens = {
4667                 (void *)&cmd_tso_set_tso,
4668                 (void *)&cmd_tso_show_mode,
4669                 (void *)&cmd_tso_set_portid,
4670                 NULL,
4671         },
4672 };
4673
4674 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4675 struct cmd_tunnel_tso_set_result {
4676         cmdline_fixed_string_t tso;
4677         cmdline_fixed_string_t mode;
4678         uint16_t tso_segsz;
4679         portid_t port_id;
4680 };
4681
4682 static struct rte_eth_dev_info
4683 check_tunnel_tso_nic_support(portid_t port_id)
4684 {
4685         struct rte_eth_dev_info dev_info;
4686
4687         rte_eth_dev_info_get(port_id, &dev_info);
4688         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4689                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4690                        "not enabled for port %d\n", port_id);
4691         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4692                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4693                        "not enabled for port %d\n", port_id);
4694         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4695                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4696                        "not enabled for port %d\n", port_id);
4697         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4698                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4699                        "not enabled for port %d\n", port_id);
4700         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4701                 printf("Warning: IP TUNNEL TSO not supported therefore "
4702                        "not enabled for port %d\n", port_id);
4703         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4704                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4705                        "not enabled for port %d\n", port_id);
4706         return dev_info;
4707 }
4708
4709 static void
4710 cmd_tunnel_tso_set_parsed(void *parsed_result,
4711                           __attribute__((unused)) struct cmdline *cl,
4712                           __attribute__((unused)) void *data)
4713 {
4714         struct cmd_tunnel_tso_set_result *res = parsed_result;
4715         struct rte_eth_dev_info dev_info;
4716
4717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4718                 return;
4719         if (!port_is_stopped(res->port_id)) {
4720                 printf("Please stop port %d first\n", res->port_id);
4721                 return;
4722         }
4723
4724         if (!strcmp(res->mode, "set"))
4725                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4726
4727         dev_info = check_tunnel_tso_nic_support(res->port_id);
4728         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4729                 ports[res->port_id].dev_conf.txmode.offloads &=
4730                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4731                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4732                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4733                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4734                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4735                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4736                 printf("TSO for tunneled packets is disabled\n");
4737         } else {
4738                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4739                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4740                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4741                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4742                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4743                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4744
4745                 ports[res->port_id].dev_conf.txmode.offloads |=
4746                         (tso_offloads & dev_info.tx_offload_capa);
4747                 printf("TSO segment size for tunneled packets is %d\n",
4748                         ports[res->port_id].tunnel_tso_segsz);
4749
4750                 /* Below conditions are needed to make it work:
4751                  * (1) tunnel TSO is supported by the NIC;
4752                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4753                  * are recognized;
4754                  * (3) for tunneled pkts with outer L3 of IPv4,
4755                  * "csum set outer-ip" must be set to hw, because after tso,
4756                  * total_len of outer IP header is changed, and the checksum
4757                  * of outer IP header calculated by sw should be wrong; that
4758                  * is not necessary for IPv6 tunneled pkts because there's no
4759                  * checksum in IP header anymore.
4760                  */
4761
4762                 if (!ports[res->port_id].parse_tunnel)
4763                         printf("Warning: csum parse_tunnel must be set "
4764                                 "so that tunneled packets are recognized\n");
4765                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4766                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4767                         printf("Warning: csum set outer-ip must be set to hw "
4768                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4769         }
4770
4771         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4772         cmd_reconfig_device_queue(res->port_id, 1, 1);
4773 }
4774
4775 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4776         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4777                                 tso, "tunnel_tso");
4778 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4779         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4780                                 mode, "set");
4781 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4782         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4783                                 tso_segsz, UINT16);
4784 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4785         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4786                                 port_id, UINT16);
4787
4788 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4789         .f = cmd_tunnel_tso_set_parsed,
4790         .data = NULL,
4791         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4792                 "Set TSO segment size of tunneled packets for csum engine "
4793                 "(0 to disable)",
4794         .tokens = {
4795                 (void *)&cmd_tunnel_tso_set_tso,
4796                 (void *)&cmd_tunnel_tso_set_mode,
4797                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4798                 (void *)&cmd_tunnel_tso_set_portid,
4799                 NULL,
4800         },
4801 };
4802
4803 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4804         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4805                                 mode, "show");
4806
4807
4808 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4809         .f = cmd_tunnel_tso_set_parsed,
4810         .data = NULL,
4811         .help_str = "tunnel_tso show <port_id> "
4812                 "Show TSO segment size of tunneled packets for csum engine",
4813         .tokens = {
4814                 (void *)&cmd_tunnel_tso_set_tso,
4815                 (void *)&cmd_tunnel_tso_show_mode,
4816                 (void *)&cmd_tunnel_tso_set_portid,
4817                 NULL,
4818         },
4819 };
4820
4821 /* *** SET GRO FOR A PORT *** */
4822 struct cmd_gro_enable_result {
4823         cmdline_fixed_string_t cmd_set;
4824         cmdline_fixed_string_t cmd_port;
4825         cmdline_fixed_string_t cmd_keyword;
4826         cmdline_fixed_string_t cmd_onoff;
4827         portid_t cmd_pid;
4828 };
4829
4830 static void
4831 cmd_gro_enable_parsed(void *parsed_result,
4832                 __attribute__((unused)) struct cmdline *cl,
4833                 __attribute__((unused)) void *data)
4834 {
4835         struct cmd_gro_enable_result *res;
4836
4837         res = parsed_result;
4838         if (!strcmp(res->cmd_keyword, "gro"))
4839                 setup_gro(res->cmd_onoff, res->cmd_pid);
4840 }
4841
4842 cmdline_parse_token_string_t cmd_gro_enable_set =
4843         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4844                         cmd_set, "set");
4845 cmdline_parse_token_string_t cmd_gro_enable_port =
4846         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4847                         cmd_keyword, "port");
4848 cmdline_parse_token_num_t cmd_gro_enable_pid =
4849         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4850                         cmd_pid, UINT16);
4851 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4852         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4853                         cmd_keyword, "gro");
4854 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4855         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4856                         cmd_onoff, "on#off");
4857
4858 cmdline_parse_inst_t cmd_gro_enable = {
4859         .f = cmd_gro_enable_parsed,
4860         .data = NULL,
4861         .help_str = "set port <port_id> gro on|off",
4862         .tokens = {
4863                 (void *)&cmd_gro_enable_set,
4864                 (void *)&cmd_gro_enable_port,
4865                 (void *)&cmd_gro_enable_pid,
4866                 (void *)&cmd_gro_enable_keyword,
4867                 (void *)&cmd_gro_enable_onoff,
4868                 NULL,
4869         },
4870 };
4871
4872 /* *** DISPLAY GRO CONFIGURATION *** */
4873 struct cmd_gro_show_result {
4874         cmdline_fixed_string_t cmd_show;
4875         cmdline_fixed_string_t cmd_port;
4876         cmdline_fixed_string_t cmd_keyword;
4877         portid_t cmd_pid;
4878 };
4879
4880 static void
4881 cmd_gro_show_parsed(void *parsed_result,
4882                 __attribute__((unused)) struct cmdline *cl,
4883                 __attribute__((unused)) void *data)
4884 {
4885         struct cmd_gro_show_result *res;
4886
4887         res = parsed_result;
4888         if (!strcmp(res->cmd_keyword, "gro"))
4889                 show_gro(res->cmd_pid);
4890 }
4891
4892 cmdline_parse_token_string_t cmd_gro_show_show =
4893         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4894                         cmd_show, "show");
4895 cmdline_parse_token_string_t cmd_gro_show_port =
4896         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4897                         cmd_port, "port");
4898 cmdline_parse_token_num_t cmd_gro_show_pid =
4899         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4900                         cmd_pid, UINT16);
4901 cmdline_parse_token_string_t cmd_gro_show_keyword =
4902         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4903                         cmd_keyword, "gro");
4904
4905 cmdline_parse_inst_t cmd_gro_show = {
4906         .f = cmd_gro_show_parsed,
4907         .data = NULL,
4908         .help_str = "show port <port_id> gro",
4909         .tokens = {
4910                 (void *)&cmd_gro_show_show,
4911                 (void *)&cmd_gro_show_port,
4912                 (void *)&cmd_gro_show_pid,
4913                 (void *)&cmd_gro_show_keyword,
4914                 NULL,
4915         },
4916 };
4917
4918 /* *** SET FLUSH CYCLES FOR GRO *** */
4919 struct cmd_gro_flush_result {
4920         cmdline_fixed_string_t cmd_set;
4921         cmdline_fixed_string_t cmd_keyword;
4922         cmdline_fixed_string_t cmd_flush;
4923         uint8_t cmd_cycles;
4924 };
4925
4926 static void
4927 cmd_gro_flush_parsed(void *parsed_result,
4928                 __attribute__((unused)) struct cmdline *cl,
4929                 __attribute__((unused)) void *data)
4930 {
4931         struct cmd_gro_flush_result *res;
4932
4933         res = parsed_result;
4934         if ((!strcmp(res->cmd_keyword, "gro")) &&
4935                         (!strcmp(res->cmd_flush, "flush")))
4936                 setup_gro_flush_cycles(res->cmd_cycles);
4937 }
4938
4939 cmdline_parse_token_string_t cmd_gro_flush_set =
4940         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4941                         cmd_set, "set");
4942 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4943         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4944                         cmd_keyword, "gro");
4945 cmdline_parse_token_string_t cmd_gro_flush_flush =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4947                         cmd_flush, "flush");
4948 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4949         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4950                         cmd_cycles, UINT8);
4951
4952 cmdline_parse_inst_t cmd_gro_flush = {
4953         .f = cmd_gro_flush_parsed,
4954         .data = NULL,
4955         .help_str = "set gro flush <cycles>",
4956         .tokens = {
4957                 (void *)&cmd_gro_flush_set,
4958                 (void *)&cmd_gro_flush_keyword,
4959                 (void *)&cmd_gro_flush_flush,
4960                 (void *)&cmd_gro_flush_cycles,
4961                 NULL,
4962         },
4963 };
4964
4965 /* *** ENABLE/DISABLE GSO *** */
4966 struct cmd_gso_enable_result {
4967         cmdline_fixed_string_t cmd_set;
4968         cmdline_fixed_string_t cmd_port;
4969         cmdline_fixed_string_t cmd_keyword;
4970         cmdline_fixed_string_t cmd_mode;
4971         portid_t cmd_pid;
4972 };
4973
4974 static void
4975 cmd_gso_enable_parsed(void *parsed_result,
4976                 __attribute__((unused)) struct cmdline *cl,
4977                 __attribute__((unused)) void *data)
4978 {
4979         struct cmd_gso_enable_result *res;
4980
4981         res = parsed_result;
4982         if (!strcmp(res->cmd_keyword, "gso"))
4983                 setup_gso(res->cmd_mode, res->cmd_pid);
4984 }
4985
4986 cmdline_parse_token_string_t cmd_gso_enable_set =
4987         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4988                         cmd_set, "set");
4989 cmdline_parse_token_string_t cmd_gso_enable_port =
4990         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4991                         cmd_port, "port");
4992 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4993         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4994                         cmd_keyword, "gso");
4995 cmdline_parse_token_string_t cmd_gso_enable_mode =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4997                         cmd_mode, "on#off");
4998 cmdline_parse_token_num_t cmd_gso_enable_pid =
4999         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5000                         cmd_pid, UINT16);
5001
5002 cmdline_parse_inst_t cmd_gso_enable = {
5003         .f = cmd_gso_enable_parsed,
5004         .data = NULL,
5005         .help_str = "set port <port_id> gso on|off",
5006         .tokens = {
5007                 (void *)&cmd_gso_enable_set,
5008                 (void *)&cmd_gso_enable_port,
5009                 (void *)&cmd_gso_enable_pid,
5010                 (void *)&cmd_gso_enable_keyword,
5011                 (void *)&cmd_gso_enable_mode,
5012                 NULL,
5013         },
5014 };
5015
5016 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5017 struct cmd_gso_size_result {
5018         cmdline_fixed_string_t cmd_set;
5019         cmdline_fixed_string_t cmd_keyword;
5020         cmdline_fixed_string_t cmd_segsz;
5021         uint16_t cmd_size;
5022 };
5023
5024 static void
5025 cmd_gso_size_parsed(void *parsed_result,
5026                        __attribute__((unused)) struct cmdline *cl,
5027                        __attribute__((unused)) void *data)
5028 {
5029         struct cmd_gso_size_result *res = parsed_result;
5030
5031         if (test_done == 0) {
5032                 printf("Before setting GSO segsz, please first"
5033                                 " stop fowarding\n");
5034                 return;
5035         }
5036
5037         if (!strcmp(res->cmd_keyword, "gso") &&
5038                         !strcmp(res->cmd_segsz, "segsz")) {
5039                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5040                         printf("gso_size should be larger than %zu."
5041                                         " Please input a legal value\n",
5042                                         RTE_GSO_SEG_SIZE_MIN);
5043                 else
5044                         gso_max_segment_size = res->cmd_size;
5045         }
5046 }
5047
5048 cmdline_parse_token_string_t cmd_gso_size_set =
5049         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5050                                 cmd_set, "set");
5051 cmdline_parse_token_string_t cmd_gso_size_keyword =
5052         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5053                                 cmd_keyword, "gso");
5054 cmdline_parse_token_string_t cmd_gso_size_segsz =
5055         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5056                                 cmd_segsz, "segsz");
5057 cmdline_parse_token_num_t cmd_gso_size_size =
5058         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5059                                 cmd_size, UINT16);
5060
5061 cmdline_parse_inst_t cmd_gso_size = {
5062         .f = cmd_gso_size_parsed,
5063         .data = NULL,
5064         .help_str = "set gso segsz <length>",
5065         .tokens = {
5066                 (void *)&cmd_gso_size_set,
5067                 (void *)&cmd_gso_size_keyword,
5068                 (void *)&cmd_gso_size_segsz,
5069                 (void *)&cmd_gso_size_size,
5070                 NULL,
5071         },
5072 };
5073
5074 /* *** SHOW GSO CONFIGURATION *** */
5075 struct cmd_gso_show_result {
5076         cmdline_fixed_string_t cmd_show;
5077         cmdline_fixed_string_t cmd_port;
5078         cmdline_fixed_string_t cmd_keyword;
5079         portid_t cmd_pid;
5080 };
5081
5082 static void
5083 cmd_gso_show_parsed(void *parsed_result,
5084                        __attribute__((unused)) struct cmdline *cl,
5085                        __attribute__((unused)) void *data)
5086 {
5087         struct cmd_gso_show_result *res = parsed_result;
5088
5089         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5090                 printf("invalid port id %u\n", res->cmd_pid);
5091                 return;
5092         }
5093         if (!strcmp(res->cmd_keyword, "gso")) {
5094                 if (gso_ports[res->cmd_pid].enable) {
5095                         printf("Max GSO'd packet size: %uB\n"
5096                                         "Supported GSO types: TCP/IPv4, "
5097                                         "UDP/IPv4, VxLAN with inner "
5098                                         "TCP/IPv4 packet, GRE with inner "
5099                                         "TCP/IPv4 packet\n",
5100                                         gso_max_segment_size);
5101                 } else
5102                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5103         }
5104 }
5105
5106 cmdline_parse_token_string_t cmd_gso_show_show =
5107 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5108                 cmd_show, "show");
5109 cmdline_parse_token_string_t cmd_gso_show_port =
5110 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5111                 cmd_port, "port");
5112 cmdline_parse_token_string_t cmd_gso_show_keyword =
5113         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5114                                 cmd_keyword, "gso");
5115 cmdline_parse_token_num_t cmd_gso_show_pid =
5116         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5117                                 cmd_pid, UINT16);
5118
5119 cmdline_parse_inst_t cmd_gso_show = {
5120         .f = cmd_gso_show_parsed,
5121         .data = NULL,
5122         .help_str = "show port <port_id> gso",
5123         .tokens = {
5124                 (void *)&cmd_gso_show_show,
5125                 (void *)&cmd_gso_show_port,
5126                 (void *)&cmd_gso_show_pid,
5127                 (void *)&cmd_gso_show_keyword,
5128                 NULL,
5129         },
5130 };
5131
5132 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5133 struct cmd_set_flush_rx {
5134         cmdline_fixed_string_t set;
5135         cmdline_fixed_string_t flush_rx;
5136         cmdline_fixed_string_t mode;
5137 };
5138
5139 static void
5140 cmd_set_flush_rx_parsed(void *parsed_result,
5141                 __attribute__((unused)) struct cmdline *cl,
5142                 __attribute__((unused)) void *data)
5143 {
5144         struct cmd_set_flush_rx *res = parsed_result;
5145         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5146 }
5147
5148 cmdline_parse_token_string_t cmd_setflushrx_set =
5149         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5150                         set, "set");
5151 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5152         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5153                         flush_rx, "flush_rx");
5154 cmdline_parse_token_string_t cmd_setflushrx_mode =
5155         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5156                         mode, "on#off");
5157
5158
5159 cmdline_parse_inst_t cmd_set_flush_rx = {
5160         .f = cmd_set_flush_rx_parsed,
5161         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5162         .data = NULL,
5163         .tokens = {
5164                 (void *)&cmd_setflushrx_set,
5165                 (void *)&cmd_setflushrx_flush_rx,
5166                 (void *)&cmd_setflushrx_mode,
5167                 NULL,
5168         },
5169 };
5170
5171 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5172 struct cmd_set_link_check {
5173         cmdline_fixed_string_t set;
5174         cmdline_fixed_string_t link_check;
5175         cmdline_fixed_string_t mode;
5176 };
5177
5178 static void
5179 cmd_set_link_check_parsed(void *parsed_result,
5180                 __attribute__((unused)) struct cmdline *cl,
5181                 __attribute__((unused)) void *data)
5182 {
5183         struct cmd_set_link_check *res = parsed_result;
5184         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5185 }
5186
5187 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5188         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5189                         set, "set");
5190 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5191         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5192                         link_check, "link_check");
5193 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5194         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5195                         mode, "on#off");
5196
5197
5198 cmdline_parse_inst_t cmd_set_link_check = {
5199         .f = cmd_set_link_check_parsed,
5200         .help_str = "set link_check on|off: Enable/Disable link status check "
5201                     "when starting/stopping a port",
5202         .data = NULL,
5203         .tokens = {
5204                 (void *)&cmd_setlinkcheck_set,
5205                 (void *)&cmd_setlinkcheck_link_check,
5206                 (void *)&cmd_setlinkcheck_mode,
5207                 NULL,
5208         },
5209 };
5210
5211 /* *** SET NIC BYPASS MODE *** */
5212 struct cmd_set_bypass_mode_result {
5213         cmdline_fixed_string_t set;
5214         cmdline_fixed_string_t bypass;
5215         cmdline_fixed_string_t mode;
5216         cmdline_fixed_string_t value;
5217         portid_t port_id;
5218 };
5219
5220 static void
5221 cmd_set_bypass_mode_parsed(void *parsed_result,
5222                 __attribute__((unused)) struct cmdline *cl,
5223                 __attribute__((unused)) void *data)
5224 {
5225         struct cmd_set_bypass_mode_result *res = parsed_result;
5226         portid_t port_id = res->port_id;
5227         int32_t rc = -EINVAL;
5228
5229 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5230         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5231
5232         if (!strcmp(res->value, "bypass"))
5233                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5234         else if (!strcmp(res->value, "isolate"))
5235                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5236         else
5237                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5238
5239         /* Set the bypass mode for the relevant port. */
5240         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5241 #endif
5242         if (rc != 0)
5243                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5244 }
5245
5246 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5247         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5248                         set, "set");
5249 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5251                         bypass, "bypass");
5252 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5254                         mode, "mode");
5255 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5257                         value, "normal#bypass#isolate");
5258 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5259         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5260                                 port_id, UINT16);
5261
5262 cmdline_parse_inst_t cmd_set_bypass_mode = {
5263         .f = cmd_set_bypass_mode_parsed,
5264         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5265                     "Set the NIC bypass mode for port_id",
5266         .data = NULL,
5267         .tokens = {
5268                 (void *)&cmd_setbypass_mode_set,
5269                 (void *)&cmd_setbypass_mode_bypass,
5270                 (void *)&cmd_setbypass_mode_mode,
5271                 (void *)&cmd_setbypass_mode_value,
5272                 (void *)&cmd_setbypass_mode_port,
5273                 NULL,
5274         },
5275 };
5276
5277 /* *** SET NIC BYPASS EVENT *** */
5278 struct cmd_set_bypass_event_result {
5279         cmdline_fixed_string_t set;
5280         cmdline_fixed_string_t bypass;
5281         cmdline_fixed_string_t event;
5282         cmdline_fixed_string_t event_value;
5283         cmdline_fixed_string_t mode;
5284         cmdline_fixed_string_t mode_value;
5285         portid_t port_id;
5286 };
5287
5288 static void
5289 cmd_set_bypass_event_parsed(void *parsed_result,
5290                 __attribute__((unused)) struct cmdline *cl,
5291                 __attribute__((unused)) void *data)
5292 {
5293         int32_t rc = -EINVAL;
5294         struct cmd_set_bypass_event_result *res = parsed_result;
5295         portid_t port_id = res->port_id;
5296
5297 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5298         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5299         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5300
5301         if (!strcmp(res->event_value, "timeout"))
5302                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5303         else if (!strcmp(res->event_value, "os_on"))
5304                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5305         else if (!strcmp(res->event_value, "os_off"))
5306                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5307         else if (!strcmp(res->event_value, "power_on"))
5308                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5309         else if (!strcmp(res->event_value, "power_off"))
5310                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5311         else
5312                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5313
5314         if (!strcmp(res->mode_value, "bypass"))
5315                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5316         else if (!strcmp(res->mode_value, "isolate"))
5317                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5318         else
5319                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5320
5321         /* Set the watchdog timeout. */
5322         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5323
5324                 rc = -EINVAL;
5325                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5326                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5327                                                            bypass_timeout);
5328                 }
5329                 if (rc != 0) {
5330                         printf("Failed to set timeout value %u "
5331                         "for port %d, errto code: %d.\n",
5332                         bypass_timeout, port_id, rc);
5333                 }
5334         }
5335
5336         /* Set the bypass event to transition to bypass mode. */
5337         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5338                                               bypass_mode);
5339 #endif
5340
5341         if (rc != 0)
5342                 printf("\t Failed to set bypass event for port = %d.\n",
5343                        port_id);
5344 }
5345
5346 cmdline_parse_token_string_t cmd_setbypass_event_set =
5347         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5348                         set, "set");
5349 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5350         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5351                         bypass, "bypass");
5352 cmdline_parse_token_string_t cmd_setbypass_event_event =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5354                         event, "event");
5355 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5357                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5358 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5360                         mode, "mode");
5361 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5362         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5363                         mode_value, "normal#bypass#isolate");
5364 cmdline_parse_token_num_t cmd_setbypass_event_port =
5365         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5366                                 port_id, UINT16);
5367
5368 cmdline_parse_inst_t cmd_set_bypass_event = {
5369         .f = cmd_set_bypass_event_parsed,
5370         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5371                 "power_off mode normal|bypass|isolate <port_id>: "
5372                 "Set the NIC bypass event mode for port_id",
5373         .data = NULL,
5374         .tokens = {
5375                 (void *)&cmd_setbypass_event_set,
5376                 (void *)&cmd_setbypass_event_bypass,
5377                 (void *)&cmd_setbypass_event_event,
5378                 (void *)&cmd_setbypass_event_event_value,
5379                 (void *)&cmd_setbypass_event_mode,
5380                 (void *)&cmd_setbypass_event_mode_value,
5381                 (void *)&cmd_setbypass_event_port,
5382                 NULL,
5383         },
5384 };
5385
5386
5387 /* *** SET NIC BYPASS TIMEOUT *** */
5388 struct cmd_set_bypass_timeout_result {
5389         cmdline_fixed_string_t set;
5390         cmdline_fixed_string_t bypass;
5391         cmdline_fixed_string_t timeout;
5392         cmdline_fixed_string_t value;
5393 };
5394
5395 static void
5396 cmd_set_bypass_timeout_parsed(void *parsed_result,
5397                 __attribute__((unused)) struct cmdline *cl,
5398                 __attribute__((unused)) void *data)
5399 {
5400         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5401
5402 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5403         if (!strcmp(res->value, "1.5"))
5404                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5405         else if (!strcmp(res->value, "2"))
5406                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5407         else if (!strcmp(res->value, "3"))
5408                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5409         else if (!strcmp(res->value, "4"))
5410                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5411         else if (!strcmp(res->value, "8"))
5412                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5413         else if (!strcmp(res->value, "16"))
5414                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5415         else if (!strcmp(res->value, "32"))
5416                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5417         else
5418                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5419 #endif
5420 }
5421
5422 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5423         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5424                         set, "set");
5425 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5426         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5427                         bypass, "bypass");
5428 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5429         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5430                         timeout, "timeout");
5431 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5433                         value, "0#1.5#2#3#4#8#16#32");
5434
5435 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5436         .f = cmd_set_bypass_timeout_parsed,
5437         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5438                 "Set the NIC bypass watchdog timeout in seconds",
5439         .data = NULL,
5440         .tokens = {
5441                 (void *)&cmd_setbypass_timeout_set,
5442                 (void *)&cmd_setbypass_timeout_bypass,
5443                 (void *)&cmd_setbypass_timeout_timeout,
5444                 (void *)&cmd_setbypass_timeout_value,
5445                 NULL,
5446         },
5447 };
5448
5449 /* *** SHOW NIC BYPASS MODE *** */
5450 struct cmd_show_bypass_config_result {
5451         cmdline_fixed_string_t show;
5452         cmdline_fixed_string_t bypass;
5453         cmdline_fixed_string_t config;
5454         portid_t port_id;
5455 };
5456
5457 static void
5458 cmd_show_bypass_config_parsed(void *parsed_result,
5459                 __attribute__((unused)) struct cmdline *cl,
5460                 __attribute__((unused)) void *data)
5461 {
5462         struct cmd_show_bypass_config_result *res = parsed_result;
5463         portid_t port_id = res->port_id;
5464         int rc = -EINVAL;
5465 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5466         uint32_t event_mode;
5467         uint32_t bypass_mode;
5468         uint32_t timeout = bypass_timeout;
5469         int i;
5470
5471         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5472                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5473         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5474                 {"UNKNOWN", "normal", "bypass", "isolate"};
5475         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5476                 "NONE",
5477                 "OS/board on",
5478                 "power supply on",
5479                 "OS/board off",
5480                 "power supply off",
5481                 "timeout"};
5482         int num_events = (sizeof events) / (sizeof events[0]);
5483
5484         /* Display the bypass mode.*/
5485         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5486                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5487                 return;
5488         }
5489         else {
5490                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5491                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5492
5493                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5494         }
5495
5496         /* Display the bypass timeout.*/
5497         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5498                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5499
5500         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5501
5502         /* Display the bypass events and associated modes. */
5503         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5504
5505                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5506                         printf("\tFailed to get bypass mode for event = %s\n",
5507                                 events[i]);
5508                 } else {
5509                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5510                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5511
5512                         printf("\tbypass event: %-16s = %s\n", events[i],
5513                                 modes[event_mode]);
5514                 }
5515         }
5516 #endif
5517         if (rc != 0)
5518                 printf("\tFailed to get bypass configuration for port = %d\n",
5519                        port_id);
5520 }
5521
5522 cmdline_parse_token_string_t cmd_showbypass_config_show =
5523         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5524                         show, "show");
5525 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5526         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5527                         bypass, "bypass");
5528 cmdline_parse_token_string_t cmd_showbypass_config_config =
5529         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5530                         config, "config");
5531 cmdline_parse_token_num_t cmd_showbypass_config_port =
5532         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5533                                 port_id, UINT16);
5534
5535 cmdline_parse_inst_t cmd_show_bypass_config = {
5536         .f = cmd_show_bypass_config_parsed,
5537         .help_str = "show bypass config <port_id>: "
5538                     "Show the NIC bypass config for port_id",
5539         .data = NULL,
5540         .tokens = {
5541                 (void *)&cmd_showbypass_config_show,
5542                 (void *)&cmd_showbypass_config_bypass,
5543                 (void *)&cmd_showbypass_config_config,
5544                 (void *)&cmd_showbypass_config_port,
5545                 NULL,
5546         },
5547 };
5548
5549 #ifdef RTE_LIBRTE_PMD_BOND
5550 /* *** SET BONDING MODE *** */
5551 struct cmd_set_bonding_mode_result {
5552         cmdline_fixed_string_t set;
5553         cmdline_fixed_string_t bonding;
5554         cmdline_fixed_string_t mode;
5555         uint8_t value;
5556         portid_t port_id;
5557 };
5558
5559 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5560                 __attribute__((unused))  struct cmdline *cl,
5561                 __attribute__((unused)) void *data)
5562 {
5563         struct cmd_set_bonding_mode_result *res = parsed_result;
5564         portid_t port_id = res->port_id;
5565
5566         /* Set the bonding mode for the relevant port. */
5567         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5568                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5569 }
5570
5571 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5572 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5573                 set, "set");
5574 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5575 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5576                 bonding, "bonding");
5577 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5578 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5579                 mode, "mode");
5580 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5581 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5582                 value, UINT8);
5583 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5584 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5585                 port_id, UINT16);
5586
5587 cmdline_parse_inst_t cmd_set_bonding_mode = {
5588                 .f = cmd_set_bonding_mode_parsed,
5589                 .help_str = "set bonding mode <mode_value> <port_id>: "
5590                         "Set the bonding mode for port_id",
5591                 .data = NULL,
5592                 .tokens = {
5593                                 (void *) &cmd_setbonding_mode_set,
5594                                 (void *) &cmd_setbonding_mode_bonding,
5595                                 (void *) &cmd_setbonding_mode_mode,
5596                                 (void *) &cmd_setbonding_mode_value,
5597                                 (void *) &cmd_setbonding_mode_port,
5598                                 NULL
5599                 }
5600 };
5601
5602 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5603 struct cmd_set_bonding_lacp_dedicated_queues_result {
5604         cmdline_fixed_string_t set;
5605         cmdline_fixed_string_t bonding;
5606         cmdline_fixed_string_t lacp;
5607         cmdline_fixed_string_t dedicated_queues;
5608         portid_t port_id;
5609         cmdline_fixed_string_t mode;
5610 };
5611
5612 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5613                 __attribute__((unused))  struct cmdline *cl,
5614                 __attribute__((unused)) void *data)
5615 {
5616         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5617         portid_t port_id = res->port_id;
5618         struct rte_port *port;
5619
5620         port = &ports[port_id];
5621
5622         /** Check if the port is not started **/
5623         if (port->port_status != RTE_PORT_STOPPED) {
5624                 printf("Please stop port %d first\n", port_id);
5625                 return;
5626         }
5627
5628         if (!strcmp(res->mode, "enable")) {
5629                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5630                         printf("Dedicate queues for LACP control packets"
5631                                         " enabled\n");
5632                 else
5633                         printf("Enabling dedicate queues for LACP control "
5634                                         "packets on port %d failed\n", port_id);
5635         } else if (!strcmp(res->mode, "disable")) {
5636                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5637                         printf("Dedicated queues for LACP control packets "
5638                                         "disabled\n");
5639                 else
5640                         printf("Disabling dedicated queues for LACP control "
5641                                         "traffic on port %d failed\n", port_id);
5642         }
5643 }
5644
5645 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5646 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5647                 set, "set");
5648 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5649 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5650                 bonding, "bonding");
5651 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5652 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5653                 lacp, "lacp");
5654 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5655 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5656                 dedicated_queues, "dedicated_queues");
5657 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5658 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5659                 port_id, UINT16);
5660 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5661 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5662                 mode, "enable#disable");
5663
5664 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5665                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5666                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5667                         "enable|disable: "
5668                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5669                 .data = NULL,
5670                 .tokens = {
5671                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5672                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5673                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5674                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5675                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5676                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5677                         NULL
5678                 }
5679 };
5680
5681 /* *** SET BALANCE XMIT POLICY *** */
5682 struct cmd_set_bonding_balance_xmit_policy_result {
5683         cmdline_fixed_string_t set;
5684         cmdline_fixed_string_t bonding;
5685         cmdline_fixed_string_t balance_xmit_policy;
5686         portid_t port_id;
5687         cmdline_fixed_string_t policy;
5688 };
5689
5690 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5691                 __attribute__((unused))  struct cmdline *cl,
5692                 __attribute__((unused)) void *data)
5693 {
5694         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5695         portid_t port_id = res->port_id;
5696         uint8_t policy;
5697
5698         if (!strcmp(res->policy, "l2")) {
5699                 policy = BALANCE_XMIT_POLICY_LAYER2;
5700         } else if (!strcmp(res->policy, "l23")) {
5701                 policy = BALANCE_XMIT_POLICY_LAYER23;
5702         } else if (!strcmp(res->policy, "l34")) {
5703                 policy = BALANCE_XMIT_POLICY_LAYER34;
5704         } else {
5705                 printf("\t Invalid xmit policy selection");
5706                 return;
5707         }
5708
5709         /* Set the bonding mode for the relevant port. */
5710         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5711                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5712                                 port_id);
5713         }
5714 }
5715
5716 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5717 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5718                 set, "set");
5719 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5720 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5721                 bonding, "bonding");
5722 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5724                 balance_xmit_policy, "balance_xmit_policy");
5725 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5726 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5727                 port_id, UINT16);
5728 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5729 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5730                 policy, "l2#l23#l34");
5731
5732 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5733                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5734                 .help_str = "set bonding balance_xmit_policy <port_id> "
5735                         "l2|l23|l34: "
5736                         "Set the bonding balance_xmit_policy for port_id",
5737                 .data = NULL,
5738                 .tokens = {
5739                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5740                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5741                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5742                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5743                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5744                                 NULL
5745                 }
5746 };
5747
5748 /* *** SHOW NIC BONDING CONFIGURATION *** */
5749 struct cmd_show_bonding_config_result {
5750         cmdline_fixed_string_t show;
5751         cmdline_fixed_string_t bonding;
5752         cmdline_fixed_string_t config;
5753         portid_t port_id;
5754 };
5755
5756 static void cmd_show_bonding_config_parsed(void *parsed_result,
5757                 __attribute__((unused))  struct cmdline *cl,
5758                 __attribute__((unused)) void *data)
5759 {
5760         struct cmd_show_bonding_config_result *res = parsed_result;
5761         int bonding_mode, agg_mode;
5762         portid_t slaves[RTE_MAX_ETHPORTS];
5763         int num_slaves, num_active_slaves;
5764         int primary_id;
5765         int i;
5766         portid_t port_id = res->port_id;
5767
5768         /* Display the bonding mode.*/
5769         bonding_mode = rte_eth_bond_mode_get(port_id);
5770         if (bonding_mode < 0) {
5771                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5772                 return;
5773         } else
5774                 printf("\tBonding mode: %d\n", bonding_mode);
5775
5776         if (bonding_mode == BONDING_MODE_BALANCE) {
5777                 int balance_xmit_policy;
5778
5779                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5780                 if (balance_xmit_policy < 0) {
5781                         printf("\tFailed to get balance xmit policy for port = %d\n",
5782                                         port_id);
5783                         return;
5784                 } else {
5785                         printf("\tBalance Xmit Policy: ");
5786
5787                         switch (balance_xmit_policy) {
5788                         case BALANCE_XMIT_POLICY_LAYER2:
5789                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5790                                 break;
5791                         case BALANCE_XMIT_POLICY_LAYER23:
5792                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5793                                 break;
5794                         case BALANCE_XMIT_POLICY_LAYER34:
5795                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5796                                 break;
5797                         }
5798                         printf("\n");
5799                 }
5800         }
5801
5802         if (bonding_mode == BONDING_MODE_8023AD) {
5803                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5804                 printf("\tIEEE802.3AD Aggregator Mode: ");
5805                 switch (agg_mode) {
5806                 case AGG_BANDWIDTH:
5807                         printf("bandwidth");
5808                         break;
5809                 case AGG_STABLE:
5810                         printf("stable");
5811                         break;
5812                 case AGG_COUNT:
5813                         printf("count");
5814                         break;
5815                 }
5816                 printf("\n");
5817         }
5818
5819         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5820
5821         if (num_slaves < 0) {
5822                 printf("\tFailed to get slave list for port = %d\n", port_id);
5823                 return;
5824         }
5825         if (num_slaves > 0) {
5826                 printf("\tSlaves (%d): [", num_slaves);
5827                 for (i = 0; i < num_slaves - 1; i++)
5828                         printf("%d ", slaves[i]);
5829
5830                 printf("%d]\n", slaves[num_slaves - 1]);
5831         } else {
5832                 printf("\tSlaves: []\n");
5833
5834         }
5835
5836         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5837                         RTE_MAX_ETHPORTS);
5838
5839         if (num_active_slaves < 0) {
5840                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5841                 return;
5842         }
5843         if (num_active_slaves > 0) {
5844                 printf("\tActive Slaves (%d): [", num_active_slaves);
5845                 for (i = 0; i < num_active_slaves - 1; i++)
5846                         printf("%d ", slaves[i]);
5847
5848                 printf("%d]\n", slaves[num_active_slaves - 1]);
5849
5850         } else {
5851                 printf("\tActive Slaves: []\n");
5852
5853         }
5854
5855         primary_id = rte_eth_bond_primary_get(port_id);
5856         if (primary_id < 0) {
5857                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5858                 return;
5859         } else
5860                 printf("\tPrimary: [%d]\n", primary_id);
5861
5862 }
5863
5864 cmdline_parse_token_string_t cmd_showbonding_config_show =
5865 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5866                 show, "show");
5867 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5868 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5869                 bonding, "bonding");
5870 cmdline_parse_token_string_t cmd_showbonding_config_config =
5871 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5872                 config, "config");
5873 cmdline_parse_token_num_t cmd_showbonding_config_port =
5874 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5875                 port_id, UINT16);
5876
5877 cmdline_parse_inst_t cmd_show_bonding_config = {
5878                 .f = cmd_show_bonding_config_parsed,
5879                 .help_str = "show bonding config <port_id>: "
5880                         "Show the bonding config for port_id",
5881                 .data = NULL,
5882                 .tokens = {
5883                                 (void *)&cmd_showbonding_config_show,
5884                                 (void *)&cmd_showbonding_config_bonding,
5885                                 (void *)&cmd_showbonding_config_config,
5886                                 (void *)&cmd_showbonding_config_port,
5887                                 NULL
5888                 }
5889 };
5890
5891 /* *** SET BONDING PRIMARY *** */
5892 struct cmd_set_bonding_primary_result {
5893         cmdline_fixed_string_t set;
5894         cmdline_fixed_string_t bonding;
5895         cmdline_fixed_string_t primary;
5896         portid_t slave_id;
5897         portid_t port_id;
5898 };
5899
5900 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5901                 __attribute__((unused))  struct cmdline *cl,
5902                 __attribute__((unused)) void *data)
5903 {
5904         struct cmd_set_bonding_primary_result *res = parsed_result;
5905         portid_t master_port_id = res->port_id;
5906         portid_t slave_port_id = res->slave_id;
5907
5908         /* Set the primary slave for a bonded device. */
5909         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5910                 printf("\t Failed to set primary slave for port = %d.\n",
5911                                 master_port_id);
5912                 return;
5913         }
5914         init_port_config();
5915 }
5916
5917 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5919                 set, "set");
5920 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5922                 bonding, "bonding");
5923 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5925                 primary, "primary");
5926 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5927 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5928                 slave_id, UINT16);
5929 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5930 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5931                 port_id, UINT16);
5932
5933 cmdline_parse_inst_t cmd_set_bonding_primary = {
5934                 .f = cmd_set_bonding_primary_parsed,
5935                 .help_str = "set bonding primary <slave_id> <port_id>: "
5936                         "Set the primary slave for port_id",
5937                 .data = NULL,
5938                 .tokens = {
5939                                 (void *)&cmd_setbonding_primary_set,
5940                                 (void *)&cmd_setbonding_primary_bonding,
5941                                 (void *)&cmd_setbonding_primary_primary,
5942                                 (void *)&cmd_setbonding_primary_slave,
5943                                 (void *)&cmd_setbonding_primary_port,
5944                                 NULL
5945                 }
5946 };
5947
5948 /* *** ADD SLAVE *** */
5949 struct cmd_add_bonding_slave_result {
5950         cmdline_fixed_string_t add;
5951         cmdline_fixed_string_t bonding;
5952         cmdline_fixed_string_t slave;
5953         portid_t slave_id;
5954         portid_t port_id;
5955 };
5956
5957 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5958                 __attribute__((unused))  struct cmdline *cl,
5959                 __attribute__((unused)) void *data)
5960 {
5961         struct cmd_add_bonding_slave_result *res = parsed_result;
5962         portid_t master_port_id = res->port_id;
5963         portid_t slave_port_id = res->slave_id;
5964
5965         /* add the slave for a bonded device. */
5966         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5967                 printf("\t Failed to add slave %d to master port = %d.\n",
5968                                 slave_port_id, master_port_id);
5969                 return;
5970         }
5971         init_port_config();
5972         set_port_slave_flag(slave_port_id);
5973 }
5974
5975 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5976 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5977                 add, "add");
5978 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5979 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5980                 bonding, "bonding");
5981 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5982 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5983                 slave, "slave");
5984 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5985 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5986                 slave_id, UINT16);
5987 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5988 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5989                 port_id, UINT16);
5990
5991 cmdline_parse_inst_t cmd_add_bonding_slave = {
5992                 .f = cmd_add_bonding_slave_parsed,
5993                 .help_str = "add bonding slave <slave_id> <port_id>: "
5994                         "Add a slave device to a bonded device",
5995                 .data = NULL,
5996                 .tokens = {
5997                                 (void *)&cmd_addbonding_slave_add,
5998                                 (void *)&cmd_addbonding_slave_bonding,
5999                                 (void *)&cmd_addbonding_slave_slave,
6000                                 (void *)&cmd_addbonding_slave_slaveid,
6001                                 (void *)&cmd_addbonding_slave_port,
6002                                 NULL
6003                 }
6004 };
6005
6006 /* *** REMOVE SLAVE *** */
6007 struct cmd_remove_bonding_slave_result {
6008         cmdline_fixed_string_t remove;
6009         cmdline_fixed_string_t bonding;
6010         cmdline_fixed_string_t slave;
6011         portid_t slave_id;
6012         portid_t port_id;
6013 };
6014
6015 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6016                 __attribute__((unused))  struct cmdline *cl,
6017                 __attribute__((unused)) void *data)
6018 {
6019         struct cmd_remove_bonding_slave_result *res = parsed_result;
6020         portid_t master_port_id = res->port_id;
6021         portid_t slave_port_id = res->slave_id;
6022
6023         /* remove the slave from a bonded device. */
6024         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6025                 printf("\t Failed to remove slave %d from master port = %d.\n",
6026                                 slave_port_id, master_port_id);
6027                 return;
6028         }
6029         init_port_config();
6030         clear_port_slave_flag(slave_port_id);
6031 }
6032
6033 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6034                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6035                                 remove, "remove");
6036 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6037                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6038                                 bonding, "bonding");
6039 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6040                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6041                                 slave, "slave");
6042 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6043                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6044                                 slave_id, UINT16);
6045 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6046                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6047                                 port_id, UINT16);
6048
6049 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6050                 .f = cmd_remove_bonding_slave_parsed,
6051                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6052                         "Remove a slave device from a bonded device",
6053                 .data = NULL,
6054                 .tokens = {
6055                                 (void *)&cmd_removebonding_slave_remove,
6056                                 (void *)&cmd_removebonding_slave_bonding,
6057                                 (void *)&cmd_removebonding_slave_slave,
6058                                 (void *)&cmd_removebonding_slave_slaveid,
6059                                 (void *)&cmd_removebonding_slave_port,
6060                                 NULL
6061                 }
6062 };
6063
6064 /* *** CREATE BONDED DEVICE *** */
6065 struct cmd_create_bonded_device_result {
6066         cmdline_fixed_string_t create;
6067         cmdline_fixed_string_t bonded;
6068         cmdline_fixed_string_t device;
6069         uint8_t mode;
6070         uint8_t socket;
6071 };
6072
6073 static int bond_dev_num = 0;
6074
6075 static void cmd_create_bonded_device_parsed(void *parsed_result,
6076                 __attribute__((unused))  struct cmdline *cl,
6077                 __attribute__((unused)) void *data)
6078 {
6079         struct cmd_create_bonded_device_result *res = parsed_result;
6080         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6081         int port_id;
6082
6083         if (test_done == 0) {
6084                 printf("Please stop forwarding first\n");
6085                 return;
6086         }
6087
6088         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6089                         bond_dev_num++);
6090
6091         /* Create a new bonded device. */
6092         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6093         if (port_id < 0) {
6094                 printf("\t Failed to create bonded device.\n");
6095                 return;
6096         } else {
6097                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6098                                 port_id);
6099
6100                 /* Update number of ports */
6101                 nb_ports = rte_eth_dev_count_avail();
6102                 reconfig(port_id, res->socket);
6103                 rte_eth_promiscuous_enable(port_id);
6104                 ports[port_id].need_setup = 0;
6105                 ports[port_id].port_status = RTE_PORT_STOPPED;
6106         }
6107
6108 }
6109
6110 cmdline_parse_token_string_t cmd_createbonded_device_create =
6111                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6112                                 create, "create");
6113 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6114                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6115                                 bonded, "bonded");
6116 cmdline_parse_token_string_t cmd_createbonded_device_device =
6117                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6118                                 device, "device");
6119 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6120                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6121                                 mode, UINT8);
6122 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6123                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6124                                 socket, UINT8);
6125
6126 cmdline_parse_inst_t cmd_create_bonded_device = {
6127                 .f = cmd_create_bonded_device_parsed,
6128                 .help_str = "create bonded device <mode> <socket>: "
6129                         "Create a new bonded device with specific bonding mode and socket",
6130                 .data = NULL,
6131                 .tokens = {
6132                                 (void *)&cmd_createbonded_device_create,
6133                                 (void *)&cmd_createbonded_device_bonded,
6134                                 (void *)&cmd_createbonded_device_device,
6135                                 (void *)&cmd_createbonded_device_mode,
6136                                 (void *)&cmd_createbonded_device_socket,
6137                                 NULL
6138                 }
6139 };
6140
6141 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6142 struct cmd_set_bond_mac_addr_result {
6143         cmdline_fixed_string_t set;
6144         cmdline_fixed_string_t bonding;
6145         cmdline_fixed_string_t mac_addr;
6146         uint16_t port_num;
6147         struct rte_ether_addr address;
6148 };
6149
6150 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6151                 __attribute__((unused))  struct cmdline *cl,
6152                 __attribute__((unused)) void *data)
6153 {
6154         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6155         int ret;
6156
6157         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6158                 return;
6159
6160         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6161
6162         /* check the return value and print it if is < 0 */
6163         if (ret < 0)
6164                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6165 }
6166
6167 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6168                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6169 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6170                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6171                                 "bonding");
6172 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6173                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6174                                 "mac_addr");
6175 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6176                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6177                                 port_num, UINT16);
6178 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6179                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6180
6181 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6182                 .f = cmd_set_bond_mac_addr_parsed,
6183                 .data = (void *) 0,
6184                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6185                 .tokens = {
6186                                 (void *)&cmd_set_bond_mac_addr_set,
6187                                 (void *)&cmd_set_bond_mac_addr_bonding,
6188                                 (void *)&cmd_set_bond_mac_addr_mac,
6189                                 (void *)&cmd_set_bond_mac_addr_portnum,
6190                                 (void *)&cmd_set_bond_mac_addr_addr,
6191                                 NULL
6192                 }
6193 };
6194
6195
6196 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6197 struct cmd_set_bond_mon_period_result {
6198         cmdline_fixed_string_t set;
6199         cmdline_fixed_string_t bonding;
6200         cmdline_fixed_string_t mon_period;
6201         uint16_t port_num;
6202         uint32_t period_ms;
6203 };
6204
6205 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6206                 __attribute__((unused))  struct cmdline *cl,
6207                 __attribute__((unused)) void *data)
6208 {
6209         struct cmd_set_bond_mon_period_result *res = parsed_result;
6210         int ret;
6211
6212         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6213
6214         /* check the return value and print it if is < 0 */
6215         if (ret < 0)
6216                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6217 }
6218
6219 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6220                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6221                                 set, "set");
6222 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6223                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6224                                 bonding, "bonding");
6225 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6226                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6227                                 mon_period,     "mon_period");
6228 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6229                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6230                                 port_num, UINT16);
6231 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6232                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6233                                 period_ms, UINT32);
6234
6235 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6236                 .f = cmd_set_bond_mon_period_parsed,
6237                 .data = (void *) 0,
6238                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6239                 .tokens = {
6240                                 (void *)&cmd_set_bond_mon_period_set,
6241                                 (void *)&cmd_set_bond_mon_period_bonding,
6242                                 (void *)&cmd_set_bond_mon_period_mon_period,
6243                                 (void *)&cmd_set_bond_mon_period_portnum,
6244                                 (void *)&cmd_set_bond_mon_period_period_ms,
6245                                 NULL
6246                 }
6247 };
6248
6249
6250
6251 struct cmd_set_bonding_agg_mode_policy_result {
6252         cmdline_fixed_string_t set;
6253         cmdline_fixed_string_t bonding;
6254         cmdline_fixed_string_t agg_mode;
6255         uint16_t port_num;
6256         cmdline_fixed_string_t policy;
6257 };
6258
6259
6260 static void
6261 cmd_set_bonding_agg_mode(void *parsed_result,
6262                 __attribute__((unused)) struct cmdline *cl,
6263                 __attribute__((unused)) void *data)
6264 {
6265         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6266         uint8_t policy = AGG_BANDWIDTH;
6267
6268         if (!strcmp(res->policy, "bandwidth"))
6269                 policy = AGG_BANDWIDTH;
6270         else if (!strcmp(res->policy, "stable"))
6271                 policy = AGG_STABLE;
6272         else if (!strcmp(res->policy, "count"))
6273                 policy = AGG_COUNT;
6274
6275         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6276 }
6277
6278
6279 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6280         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6281                                 set, "set");
6282 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6283         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6284                                 bonding, "bonding");
6285
6286 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6287         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6288                                 agg_mode, "agg_mode");
6289
6290 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6291         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6292                                 port_num, UINT16);
6293
6294 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6295         TOKEN_STRING_INITIALIZER(
6296                         struct cmd_set_bonding_balance_xmit_policy_result,
6297                 policy, "stable#bandwidth#count");
6298
6299 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6300         .f = cmd_set_bonding_agg_mode,
6301         .data = (void *) 0,
6302         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6303         .tokens = {
6304                         (void *)&cmd_set_bonding_agg_mode_set,
6305                         (void *)&cmd_set_bonding_agg_mode_bonding,
6306                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6307                         (void *)&cmd_set_bonding_agg_mode_portnum,
6308                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6309                         NULL
6310                 }
6311 };
6312
6313
6314 #endif /* RTE_LIBRTE_PMD_BOND */
6315
6316 /* *** SET FORWARDING MODE *** */
6317 struct cmd_set_fwd_mode_result {
6318         cmdline_fixed_string_t set;
6319         cmdline_fixed_string_t fwd;
6320         cmdline_fixed_string_t mode;
6321 };
6322
6323 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6324                                     __attribute__((unused)) struct cmdline *cl,
6325                                     __attribute__((unused)) void *data)
6326 {
6327         struct cmd_set_fwd_mode_result *res = parsed_result;
6328
6329         retry_enabled = 0;
6330         set_pkt_forwarding_mode(res->mode);
6331 }
6332
6333 cmdline_parse_token_string_t cmd_setfwd_set =
6334         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6335 cmdline_parse_token_string_t cmd_setfwd_fwd =
6336         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6337 cmdline_parse_token_string_t cmd_setfwd_mode =
6338         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6339                 "" /* defined at init */);
6340
6341 cmdline_parse_inst_t cmd_set_fwd_mode = {
6342         .f = cmd_set_fwd_mode_parsed,
6343         .data = NULL,
6344         .help_str = NULL, /* defined at init */
6345         .tokens = {
6346                 (void *)&cmd_setfwd_set,
6347                 (void *)&cmd_setfwd_fwd,
6348                 (void *)&cmd_setfwd_mode,
6349                 NULL,
6350         },
6351 };
6352
6353 static void cmd_set_fwd_mode_init(void)
6354 {
6355         char *modes, *c;
6356         static char token[128];
6357         static char help[256];
6358         cmdline_parse_token_string_t *token_struct;
6359
6360         modes = list_pkt_forwarding_modes();
6361         snprintf(help, sizeof(help), "set fwd %s: "
6362                 "Set packet forwarding mode", modes);
6363         cmd_set_fwd_mode.help_str = help;
6364
6365         /* string token separator is # */
6366         for (c = token; *modes != '\0'; modes++)
6367                 if (*modes == '|')
6368                         *c++ = '#';
6369                 else
6370                         *c++ = *modes;
6371         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6372         token_struct->string_data.str = token;
6373 }
6374
6375 /* *** SET RETRY FORWARDING MODE *** */
6376 struct cmd_set_fwd_retry_mode_result {
6377         cmdline_fixed_string_t set;
6378         cmdline_fixed_string_t fwd;
6379         cmdline_fixed_string_t mode;
6380         cmdline_fixed_string_t retry;
6381 };
6382
6383 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6384                             __attribute__((unused)) struct cmdline *cl,
6385                             __attribute__((unused)) void *data)
6386 {
6387         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6388
6389         retry_enabled = 1;
6390         set_pkt_forwarding_mode(res->mode);
6391 }
6392
6393 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6394         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6395                         set, "set");
6396 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6397         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6398                         fwd, "fwd");
6399 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6400         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6401                         mode,
6402                 "" /* defined at init */);
6403 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6404         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6405                         retry, "retry");
6406
6407 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6408         .f = cmd_set_fwd_retry_mode_parsed,
6409         .data = NULL,
6410         .help_str = NULL, /* defined at init */
6411         .tokens = {
6412                 (void *)&cmd_setfwd_retry_set,
6413                 (void *)&cmd_setfwd_retry_fwd,
6414                 (void *)&cmd_setfwd_retry_mode,
6415                 (void *)&cmd_setfwd_retry_retry,
6416                 NULL,
6417         },
6418 };
6419
6420 static void cmd_set_fwd_retry_mode_init(void)
6421 {
6422         char *modes, *c;
6423         static char token[128];
6424         static char help[256];
6425         cmdline_parse_token_string_t *token_struct;
6426
6427         modes = list_pkt_forwarding_retry_modes();
6428         snprintf(help, sizeof(help), "set fwd %s retry: "
6429                 "Set packet forwarding mode with retry", modes);
6430         cmd_set_fwd_retry_mode.help_str = help;
6431
6432         /* string token separator is # */
6433         for (c = token; *modes != '\0'; modes++)
6434                 if (*modes == '|')
6435                         *c++ = '#';
6436                 else
6437                         *c++ = *modes;
6438         token_struct = (cmdline_parse_token_string_t *)
6439                 cmd_set_fwd_retry_mode.tokens[2];
6440         token_struct->string_data.str = token;
6441 }
6442
6443 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6444 struct cmd_set_burst_tx_retry_result {
6445         cmdline_fixed_string_t set;
6446         cmdline_fixed_string_t burst;
6447         cmdline_fixed_string_t tx;
6448         cmdline_fixed_string_t delay;
6449         uint32_t time;
6450         cmdline_fixed_string_t retry;
6451         uint32_t retry_num;
6452 };
6453
6454 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6455                                         __attribute__((unused)) struct cmdline *cl,
6456                                         __attribute__((unused)) void *data)
6457 {
6458         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6459
6460         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6461                 && !strcmp(res->tx, "tx")) {
6462                 if (!strcmp(res->delay, "delay"))
6463                         burst_tx_delay_time = res->time;
6464                 if (!strcmp(res->retry, "retry"))
6465                         burst_tx_retry_num = res->retry_num;
6466         }
6467
6468 }
6469
6470 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6471         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6472 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6473         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6474                                  "burst");
6475 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6476         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6477 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6478         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6479 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6480         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6481 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6483 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6484         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6485
6486 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6487         .f = cmd_set_burst_tx_retry_parsed,
6488         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6489         .tokens = {
6490                 (void *)&cmd_set_burst_tx_retry_set,
6491                 (void *)&cmd_set_burst_tx_retry_burst,
6492                 (void *)&cmd_set_burst_tx_retry_tx,
6493                 (void *)&cmd_set_burst_tx_retry_delay,
6494                 (void *)&cmd_set_burst_tx_retry_time,
6495                 (void *)&cmd_set_burst_tx_retry_retry,
6496                 (void *)&cmd_set_burst_tx_retry_retry_num,
6497                 NULL,
6498         },
6499 };
6500
6501 /* *** SET PROMISC MODE *** */
6502 struct cmd_set_promisc_mode_result {
6503         cmdline_fixed_string_t set;
6504         cmdline_fixed_string_t promisc;
6505         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6506         uint16_t port_num;               /* valid if "allports" argument == 0 */
6507         cmdline_fixed_string_t mode;
6508 };
6509
6510 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6511                                         __attribute__((unused)) struct cmdline *cl,
6512                                         void *allports)
6513 {
6514         struct cmd_set_promisc_mode_result *res = parsed_result;
6515         int enable;
6516         portid_t i;
6517
6518         if (!strcmp(res->mode, "on"))
6519                 enable = 1;
6520         else
6521                 enable = 0;
6522
6523         /* all ports */
6524         if (allports) {
6525                 RTE_ETH_FOREACH_DEV(i) {
6526                         if (enable)
6527                                 rte_eth_promiscuous_enable(i);
6528                         else
6529                                 rte_eth_promiscuous_disable(i);
6530                 }
6531         }
6532         else {
6533                 if (enable)
6534                         rte_eth_promiscuous_enable(res->port_num);
6535                 else
6536                         rte_eth_promiscuous_disable(res->port_num);
6537         }
6538 }
6539
6540 cmdline_parse_token_string_t cmd_setpromisc_set =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6542 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6544                                  "promisc");
6545 cmdline_parse_token_string_t cmd_setpromisc_portall =
6546         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6547                                  "all");
6548 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6549         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6550                               UINT16);
6551 cmdline_parse_token_string_t cmd_setpromisc_mode =
6552         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6553                                  "on#off");
6554
6555 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6556         .f = cmd_set_promisc_mode_parsed,
6557         .data = (void *)1,
6558         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6559         .tokens = {
6560                 (void *)&cmd_setpromisc_set,
6561                 (void *)&cmd_setpromisc_promisc,
6562                 (void *)&cmd_setpromisc_portall,
6563                 (void *)&cmd_setpromisc_mode,
6564                 NULL,
6565         },
6566 };
6567
6568 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6569         .f = cmd_set_promisc_mode_parsed,
6570         .data = (void *)0,
6571         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6572         .tokens = {
6573                 (void *)&cmd_setpromisc_set,
6574                 (void *)&cmd_setpromisc_promisc,
6575                 (void *)&cmd_setpromisc_portnum,
6576                 (void *)&cmd_setpromisc_mode,
6577                 NULL,
6578         },
6579 };
6580
6581 /* *** SET ALLMULTI MODE *** */
6582 struct cmd_set_allmulti_mode_result {
6583         cmdline_fixed_string_t set;
6584         cmdline_fixed_string_t allmulti;
6585         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6586         uint16_t port_num;               /* valid if "allports" argument == 0 */
6587         cmdline_fixed_string_t mode;
6588 };
6589
6590 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6591                                         __attribute__((unused)) struct cmdline *cl,
6592                                         void *allports)
6593 {
6594         struct cmd_set_allmulti_mode_result *res = parsed_result;
6595         int enable;
6596         portid_t i;
6597
6598         if (!strcmp(res->mode, "on"))
6599                 enable = 1;
6600         else
6601                 enable = 0;
6602
6603         /* all ports */
6604         if (allports) {
6605                 RTE_ETH_FOREACH_DEV(i) {
6606                         if (enable)
6607                                 rte_eth_allmulticast_enable(i);
6608                         else
6609                                 rte_eth_allmulticast_disable(i);
6610                 }
6611         }
6612         else {
6613                 if (enable)
6614                         rte_eth_allmulticast_enable(res->port_num);
6615                 else
6616                         rte_eth_allmulticast_disable(res->port_num);
6617         }
6618 }
6619
6620 cmdline_parse_token_string_t cmd_setallmulti_set =
6621         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6622 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6624                                  "allmulti");
6625 cmdline_parse_token_string_t cmd_setallmulti_portall =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6627                                  "all");
6628 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6629         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6630                               UINT16);
6631 cmdline_parse_token_string_t cmd_setallmulti_mode =
6632         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6633                                  "on#off");
6634
6635 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6636         .f = cmd_set_allmulti_mode_parsed,
6637         .data = (void *)1,
6638         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6639         .tokens = {
6640                 (void *)&cmd_setallmulti_set,
6641                 (void *)&cmd_setallmulti_allmulti,
6642                 (void *)&cmd_setallmulti_portall,
6643                 (void *)&cmd_setallmulti_mode,
6644                 NULL,
6645         },
6646 };
6647
6648 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6649         .f = cmd_set_allmulti_mode_parsed,
6650         .data = (void *)0,
6651         .help_str = "set allmulti <port_id> on|off: "
6652                 "Set allmulti mode on port_id",
6653         .tokens = {
6654                 (void *)&cmd_setallmulti_set,
6655                 (void *)&cmd_setallmulti_allmulti,
6656                 (void *)&cmd_setallmulti_portnum,
6657                 (void *)&cmd_setallmulti_mode,
6658                 NULL,
6659         },
6660 };
6661
6662 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6663 struct cmd_link_flow_ctrl_set_result {
6664         cmdline_fixed_string_t set;
6665         cmdline_fixed_string_t flow_ctrl;
6666         cmdline_fixed_string_t rx;
6667         cmdline_fixed_string_t rx_lfc_mode;
6668         cmdline_fixed_string_t tx;
6669         cmdline_fixed_string_t tx_lfc_mode;
6670         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6671         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6672         cmdline_fixed_string_t autoneg_str;
6673         cmdline_fixed_string_t autoneg;
6674         cmdline_fixed_string_t hw_str;
6675         uint32_t high_water;
6676         cmdline_fixed_string_t lw_str;
6677         uint32_t low_water;
6678         cmdline_fixed_string_t pt_str;
6679         uint16_t pause_time;
6680         cmdline_fixed_string_t xon_str;
6681         uint16_t send_xon;
6682         portid_t port_id;
6683 };
6684
6685 cmdline_parse_token_string_t cmd_lfc_set_set =
6686         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6687                                 set, "set");
6688 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6689         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6690                                 flow_ctrl, "flow_ctrl");
6691 cmdline_parse_token_string_t cmd_lfc_set_rx =
6692         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6693                                 rx, "rx");
6694 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6695         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6696                                 rx_lfc_mode, "on#off");
6697 cmdline_parse_token_string_t cmd_lfc_set_tx =
6698         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6699                                 tx, "tx");
6700 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6701         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6702                                 tx_lfc_mode, "on#off");
6703 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6704         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6705                                 hw_str, "high_water");
6706 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6707         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6708                                 high_water, UINT32);
6709 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6710         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6711                                 lw_str, "low_water");
6712 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6713         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6714                                 low_water, UINT32);
6715 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6716         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6717                                 pt_str, "pause_time");
6718 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6719         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6720                                 pause_time, UINT16);
6721 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6722         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6723                                 xon_str, "send_xon");
6724 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6725         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6726                                 send_xon, UINT16);
6727 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6728         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6729                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6730 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6731         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6732                                 mac_ctrl_frame_fwd_mode, "on#off");
6733 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6734         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6735                                 autoneg_str, "autoneg");
6736 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6737         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6738                                 autoneg, "on#off");
6739 cmdline_parse_token_num_t cmd_lfc_set_portid =
6740         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6741                                 port_id, UINT16);
6742
6743 /* forward declaration */
6744 static void
6745 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6746                               void *data);
6747
6748 cmdline_parse_inst_t cmd_link_flow_control_set = {
6749         .f = cmd_link_flow_ctrl_set_parsed,
6750         .data = NULL,
6751         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6752                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6753                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6754         .tokens = {
6755                 (void *)&cmd_lfc_set_set,
6756                 (void *)&cmd_lfc_set_flow_ctrl,
6757                 (void *)&cmd_lfc_set_rx,
6758                 (void *)&cmd_lfc_set_rx_mode,
6759                 (void *)&cmd_lfc_set_tx,
6760                 (void *)&cmd_lfc_set_tx_mode,
6761                 (void *)&cmd_lfc_set_high_water,
6762                 (void *)&cmd_lfc_set_low_water,
6763                 (void *)&cmd_lfc_set_pause_time,
6764                 (void *)&cmd_lfc_set_send_xon,
6765                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6766                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6767                 (void *)&cmd_lfc_set_autoneg_str,
6768                 (void *)&cmd_lfc_set_autoneg,
6769                 (void *)&cmd_lfc_set_portid,
6770                 NULL,
6771         },
6772 };
6773
6774 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6775         .f = cmd_link_flow_ctrl_set_parsed,
6776         .data = (void *)&cmd_link_flow_control_set_rx,
6777         .help_str = "set flow_ctrl rx on|off <port_id>: "
6778                 "Change rx flow control parameter",
6779         .tokens = {
6780                 (void *)&cmd_lfc_set_set,
6781                 (void *)&cmd_lfc_set_flow_ctrl,
6782                 (void *)&cmd_lfc_set_rx,
6783                 (void *)&cmd_lfc_set_rx_mode,
6784                 (void *)&cmd_lfc_set_portid,
6785                 NULL,
6786         },
6787 };
6788
6789 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6790         .f = cmd_link_flow_ctrl_set_parsed,
6791         .data = (void *)&cmd_link_flow_control_set_tx,
6792         .help_str = "set flow_ctrl tx on|off <port_id>: "
6793                 "Change tx flow control parameter",
6794         .tokens = {
6795                 (void *)&cmd_lfc_set_set,
6796                 (void *)&cmd_lfc_set_flow_ctrl,
6797                 (void *)&cmd_lfc_set_tx,
6798                 (void *)&cmd_lfc_set_tx_mode,
6799                 (void *)&cmd_lfc_set_portid,
6800                 NULL,
6801         },
6802 };
6803
6804 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6805         .f = cmd_link_flow_ctrl_set_parsed,
6806         .data = (void *)&cmd_link_flow_control_set_hw,
6807         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6808                 "Change high water flow control parameter",
6809         .tokens = {
6810                 (void *)&cmd_lfc_set_set,
6811                 (void *)&cmd_lfc_set_flow_ctrl,
6812                 (void *)&cmd_lfc_set_high_water_str,
6813                 (void *)&cmd_lfc_set_high_water,
6814                 (void *)&cmd_lfc_set_portid,
6815                 NULL,
6816         },
6817 };
6818
6819 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6820         .f = cmd_link_flow_ctrl_set_parsed,
6821         .data = (void *)&cmd_link_flow_control_set_lw,
6822         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6823                 "Change low water flow control parameter",
6824         .tokens = {
6825                 (void *)&cmd_lfc_set_set,
6826                 (void *)&cmd_lfc_set_flow_ctrl,
6827                 (void *)&cmd_lfc_set_low_water_str,
6828                 (void *)&cmd_lfc_set_low_water,
6829                 (void *)&cmd_lfc_set_portid,
6830                 NULL,
6831         },
6832 };
6833
6834 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6835         .f = cmd_link_flow_ctrl_set_parsed,
6836         .data = (void *)&cmd_link_flow_control_set_pt,
6837         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6838                 "Change pause time flow control parameter",
6839         .tokens = {
6840                 (void *)&cmd_lfc_set_set,
6841                 (void *)&cmd_lfc_set_flow_ctrl,
6842                 (void *)&cmd_lfc_set_pause_time_str,
6843                 (void *)&cmd_lfc_set_pause_time,
6844                 (void *)&cmd_lfc_set_portid,
6845                 NULL,
6846         },
6847 };
6848
6849 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6850         .f = cmd_link_flow_ctrl_set_parsed,
6851         .data = (void *)&cmd_link_flow_control_set_xon,
6852         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6853                 "Change send_xon flow control parameter",
6854         .tokens = {
6855                 (void *)&cmd_lfc_set_set,
6856                 (void *)&cmd_lfc_set_flow_ctrl,
6857                 (void *)&cmd_lfc_set_send_xon_str,
6858                 (void *)&cmd_lfc_set_send_xon,
6859                 (void *)&cmd_lfc_set_portid,
6860                 NULL,
6861         },
6862 };
6863
6864 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6865         .f = cmd_link_flow_ctrl_set_parsed,
6866         .data = (void *)&cmd_link_flow_control_set_macfwd,
6867         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6868                 "Change mac ctrl fwd flow control parameter",
6869         .tokens = {
6870                 (void *)&cmd_lfc_set_set,
6871                 (void *)&cmd_lfc_set_flow_ctrl,
6872                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6873                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6874                 (void *)&cmd_lfc_set_portid,
6875                 NULL,
6876         },
6877 };
6878
6879 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6880         .f = cmd_link_flow_ctrl_set_parsed,
6881         .data = (void *)&cmd_link_flow_control_set_autoneg,
6882         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6883                 "Change autoneg flow control parameter",
6884         .tokens = {
6885                 (void *)&cmd_lfc_set_set,
6886                 (void *)&cmd_lfc_set_flow_ctrl,
6887                 (void *)&cmd_lfc_set_autoneg_str,
6888                 (void *)&cmd_lfc_set_autoneg,
6889                 (void *)&cmd_lfc_set_portid,
6890                 NULL,
6891         },
6892 };
6893
6894 static void
6895 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6896                               __attribute__((unused)) struct cmdline *cl,
6897                               void *data)
6898 {
6899         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6900         cmdline_parse_inst_t *cmd = data;
6901         struct rte_eth_fc_conf fc_conf;
6902         int rx_fc_en = 0;
6903         int tx_fc_en = 0;
6904         int ret;
6905
6906         /*
6907          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6908          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6909          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6910          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6911          */
6912         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6913                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6914         };
6915
6916         /* Partial command line, retrieve current configuration */
6917         if (cmd) {
6918                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6919                 if (ret != 0) {
6920                         printf("cannot get current flow ctrl parameters, return"
6921                                "code = %d\n", ret);
6922                         return;
6923                 }
6924
6925                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6926                     (fc_conf.mode == RTE_FC_FULL))
6927                         rx_fc_en = 1;
6928                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6929                     (fc_conf.mode == RTE_FC_FULL))
6930                         tx_fc_en = 1;
6931         }
6932
6933         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6934                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6935
6936         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6937                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6938
6939         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6940
6941         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6942                 fc_conf.high_water = res->high_water;
6943
6944         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6945                 fc_conf.low_water = res->low_water;
6946
6947         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6948                 fc_conf.pause_time = res->pause_time;
6949
6950         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6951                 fc_conf.send_xon = res->send_xon;
6952
6953         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6954                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6955                         fc_conf.mac_ctrl_frame_fwd = 1;
6956                 else
6957                         fc_conf.mac_ctrl_frame_fwd = 0;
6958         }
6959
6960         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6961                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6962
6963         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6964         if (ret != 0)
6965                 printf("bad flow contrl parameter, return code = %d \n", ret);
6966 }
6967
6968 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6969 struct cmd_priority_flow_ctrl_set_result {
6970         cmdline_fixed_string_t set;
6971         cmdline_fixed_string_t pfc_ctrl;
6972         cmdline_fixed_string_t rx;
6973         cmdline_fixed_string_t rx_pfc_mode;
6974         cmdline_fixed_string_t tx;
6975         cmdline_fixed_string_t tx_pfc_mode;
6976         uint32_t high_water;
6977         uint32_t low_water;
6978         uint16_t pause_time;
6979         uint8_t  priority;
6980         portid_t port_id;
6981 };
6982
6983 static void
6984 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6985                        __attribute__((unused)) struct cmdline *cl,
6986                        __attribute__((unused)) void *data)
6987 {
6988         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6989         struct rte_eth_pfc_conf pfc_conf;
6990         int rx_fc_enable, tx_fc_enable;
6991         int ret;
6992
6993         /*
6994          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6995          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6996          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6997          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6998          */
6999         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7000                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7001         };
7002
7003         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7004         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7005         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7006         pfc_conf.fc.high_water = res->high_water;
7007         pfc_conf.fc.low_water  = res->low_water;
7008         pfc_conf.fc.pause_time = res->pause_time;
7009         pfc_conf.priority      = res->priority;
7010
7011         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7012         if (ret != 0)
7013                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7014 }
7015
7016 cmdline_parse_token_string_t cmd_pfc_set_set =
7017         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7018                                 set, "set");
7019 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7020         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7021                                 pfc_ctrl, "pfc_ctrl");
7022 cmdline_parse_token_string_t cmd_pfc_set_rx =
7023         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7024                                 rx, "rx");
7025 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7026         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7027                                 rx_pfc_mode, "on#off");
7028 cmdline_parse_token_string_t cmd_pfc_set_tx =
7029         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7030                                 tx, "tx");
7031 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7032         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7033                                 tx_pfc_mode, "on#off");
7034 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7035         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7036                                 high_water, UINT32);
7037 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7038         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7039                                 low_water, UINT32);
7040 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7041         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7042                                 pause_time, UINT16);
7043 cmdline_parse_token_num_t cmd_pfc_set_priority =
7044         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7045                                 priority, UINT8);
7046 cmdline_parse_token_num_t cmd_pfc_set_portid =
7047         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7048                                 port_id, UINT16);
7049
7050 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7051         .f = cmd_priority_flow_ctrl_set_parsed,
7052         .data = NULL,
7053         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7054                 "<pause_time> <priority> <port_id>: "
7055                 "Configure the Ethernet priority flow control",
7056         .tokens = {
7057                 (void *)&cmd_pfc_set_set,
7058                 (void *)&cmd_pfc_set_flow_ctrl,
7059                 (void *)&cmd_pfc_set_rx,
7060                 (void *)&cmd_pfc_set_rx_mode,
7061                 (void *)&cmd_pfc_set_tx,
7062                 (void *)&cmd_pfc_set_tx_mode,
7063                 (void *)&cmd_pfc_set_high_water,
7064                 (void *)&cmd_pfc_set_low_water,
7065                 (void *)&cmd_pfc_set_pause_time,
7066                 (void *)&cmd_pfc_set_priority,
7067                 (void *)&cmd_pfc_set_portid,
7068                 NULL,
7069         },
7070 };
7071
7072 /* *** RESET CONFIGURATION *** */
7073 struct cmd_reset_result {
7074         cmdline_fixed_string_t reset;
7075         cmdline_fixed_string_t def;
7076 };
7077
7078 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7079                              struct cmdline *cl,
7080                              __attribute__((unused)) void *data)
7081 {
7082         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7083         set_def_fwd_config();
7084 }
7085
7086 cmdline_parse_token_string_t cmd_reset_set =
7087         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7088 cmdline_parse_token_string_t cmd_reset_def =
7089         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7090                                  "default");
7091
7092 cmdline_parse_inst_t cmd_reset = {
7093         .f = cmd_reset_parsed,
7094         .data = NULL,
7095         .help_str = "set default: Reset default forwarding configuration",
7096         .tokens = {
7097                 (void *)&cmd_reset_set,
7098                 (void *)&cmd_reset_def,
7099                 NULL,
7100         },
7101 };
7102
7103 /* *** START FORWARDING *** */
7104 struct cmd_start_result {
7105         cmdline_fixed_string_t start;
7106 };
7107
7108 cmdline_parse_token_string_t cmd_start_start =
7109         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7110
7111 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7112                              __attribute__((unused)) struct cmdline *cl,
7113                              __attribute__((unused)) void *data)
7114 {
7115         start_packet_forwarding(0);
7116 }
7117
7118 cmdline_parse_inst_t cmd_start = {
7119         .f = cmd_start_parsed,
7120         .data = NULL,
7121         .help_str = "start: Start packet forwarding",
7122         .tokens = {
7123                 (void *)&cmd_start_start,
7124                 NULL,
7125         },
7126 };
7127
7128 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7129 struct cmd_start_tx_first_result {
7130         cmdline_fixed_string_t start;
7131         cmdline_fixed_string_t tx_first;
7132 };
7133
7134 static void
7135 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7136                           __attribute__((unused)) struct cmdline *cl,
7137                           __attribute__((unused)) void *data)
7138 {
7139         start_packet_forwarding(1);
7140 }
7141
7142 cmdline_parse_token_string_t cmd_start_tx_first_start =
7143         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7144                                  "start");
7145 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7146         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7147                                  tx_first, "tx_first");
7148
7149 cmdline_parse_inst_t cmd_start_tx_first = {
7150         .f = cmd_start_tx_first_parsed,
7151         .data = NULL,
7152         .help_str = "start tx_first: Start packet forwarding, "
7153                 "after sending 1 burst of packets",
7154         .tokens = {
7155                 (void *)&cmd_start_tx_first_start,
7156                 (void *)&cmd_start_tx_first_tx_first,
7157                 NULL,
7158         },
7159 };
7160
7161 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7162 struct cmd_start_tx_first_n_result {
7163         cmdline_fixed_string_t start;
7164         cmdline_fixed_string_t tx_first;
7165         uint32_t tx_num;
7166 };
7167
7168 static void
7169 cmd_start_tx_first_n_parsed(void *parsed_result,
7170                           __attribute__((unused)) struct cmdline *cl,
7171                           __attribute__((unused)) void *data)
7172 {
7173         struct cmd_start_tx_first_n_result *res = parsed_result;
7174
7175         start_packet_forwarding(res->tx_num);
7176 }
7177
7178 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7179         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7180                         start, "start");
7181 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7182         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7183                         tx_first, "tx_first");
7184 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7185         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7186                         tx_num, UINT32);
7187
7188 cmdline_parse_inst_t cmd_start_tx_first_n = {
7189         .f = cmd_start_tx_first_n_parsed,
7190         .data = NULL,
7191         .help_str = "start tx_first <num>: "
7192                 "packet forwarding, after sending <num> bursts of packets",
7193         .tokens = {
7194                 (void *)&cmd_start_tx_first_n_start,
7195                 (void *)&cmd_start_tx_first_n_tx_first,
7196                 (void *)&cmd_start_tx_first_n_tx_num,
7197                 NULL,
7198         },
7199 };
7200
7201 /* *** SET LINK UP *** */
7202 struct cmd_set_link_up_result {
7203         cmdline_fixed_string_t set;
7204         cmdline_fixed_string_t link_up;
7205         cmdline_fixed_string_t port;
7206         portid_t port_id;
7207 };
7208
7209 cmdline_parse_token_string_t cmd_set_link_up_set =
7210         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7211 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7212         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7213                                 "link-up");
7214 cmdline_parse_token_string_t cmd_set_link_up_port =
7215         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7216 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7218
7219 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7220                              __attribute__((unused)) struct cmdline *cl,
7221                              __attribute__((unused)) void *data)
7222 {
7223         struct cmd_set_link_up_result *res = parsed_result;
7224         dev_set_link_up(res->port_id);
7225 }
7226
7227 cmdline_parse_inst_t cmd_set_link_up = {
7228         .f = cmd_set_link_up_parsed,
7229         .data = NULL,
7230         .help_str = "set link-up port <port id>",
7231         .tokens = {
7232                 (void *)&cmd_set_link_up_set,
7233                 (void *)&cmd_set_link_up_link_up,
7234                 (void *)&cmd_set_link_up_port,
7235                 (void *)&cmd_set_link_up_port_id,
7236                 NULL,
7237         },
7238 };
7239
7240 /* *** SET LINK DOWN *** */
7241 struct cmd_set_link_down_result {
7242         cmdline_fixed_string_t set;
7243         cmdline_fixed_string_t link_down;
7244         cmdline_fixed_string_t port;
7245         portid_t port_id;
7246 };
7247
7248 cmdline_parse_token_string_t cmd_set_link_down_set =
7249         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7250 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7251         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7252                                 "link-down");
7253 cmdline_parse_token_string_t cmd_set_link_down_port =
7254         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7255 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7256         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7257
7258 static void cmd_set_link_down_parsed(
7259                                 __attribute__((unused)) void *parsed_result,
7260                                 __attribute__((unused)) struct cmdline *cl,
7261                                 __attribute__((unused)) void *data)
7262 {
7263         struct cmd_set_link_down_result *res = parsed_result;
7264         dev_set_link_down(res->port_id);
7265 }
7266
7267 cmdline_parse_inst_t cmd_set_link_down = {
7268         .f = cmd_set_link_down_parsed,
7269         .data = NULL,
7270         .help_str = "set link-down port <port id>",
7271         .tokens = {
7272                 (void *)&cmd_set_link_down_set,
7273                 (void *)&cmd_set_link_down_link_down,
7274                 (void *)&cmd_set_link_down_port,
7275                 (void *)&cmd_set_link_down_port_id,
7276                 NULL,
7277         },
7278 };
7279
7280 /* *** SHOW CFG *** */
7281 struct cmd_showcfg_result {
7282         cmdline_fixed_string_t show;
7283         cmdline_fixed_string_t cfg;
7284         cmdline_fixed_string_t what;
7285 };
7286
7287 static void cmd_showcfg_parsed(void *parsed_result,
7288                                __attribute__((unused)) struct cmdline *cl,
7289                                __attribute__((unused)) void *data)
7290 {
7291         struct cmd_showcfg_result *res = parsed_result;
7292         if (!strcmp(res->what, "rxtx"))
7293                 rxtx_config_display();
7294         else if (!strcmp(res->what, "cores"))
7295                 fwd_lcores_config_display();
7296         else if (!strcmp(res->what, "fwd"))
7297                 pkt_fwd_config_display(&cur_fwd_config);
7298         else if (!strcmp(res->what, "txpkts"))
7299                 show_tx_pkt_segments();
7300 }
7301
7302 cmdline_parse_token_string_t cmd_showcfg_show =
7303         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7304 cmdline_parse_token_string_t cmd_showcfg_port =
7305         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7306 cmdline_parse_token_string_t cmd_showcfg_what =
7307         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7308                                  "rxtx#cores#fwd#txpkts");
7309
7310 cmdline_parse_inst_t cmd_showcfg = {
7311         .f = cmd_showcfg_parsed,
7312         .data = NULL,
7313         .help_str = "show config rxtx|cores|fwd|txpkts",
7314         .tokens = {
7315                 (void *)&cmd_showcfg_show,
7316                 (void *)&cmd_showcfg_port,
7317                 (void *)&cmd_showcfg_what,
7318                 NULL,
7319         },
7320 };
7321
7322 /* *** SHOW ALL PORT INFO *** */
7323 struct cmd_showportall_result {
7324         cmdline_fixed_string_t show;
7325         cmdline_fixed_string_t port;
7326         cmdline_fixed_string_t what;
7327         cmdline_fixed_string_t all;
7328 };
7329
7330 static void cmd_showportall_parsed(void *parsed_result,
7331                                 __attribute__((unused)) struct cmdline *cl,
7332                                 __attribute__((unused)) void *data)
7333 {
7334         portid_t i;
7335
7336         struct cmd_showportall_result *res = parsed_result;
7337         if (!strcmp(res->show, "clear")) {
7338                 if (!strcmp(res->what, "stats"))
7339                         RTE_ETH_FOREACH_DEV(i)
7340                                 nic_stats_clear(i);
7341                 else if (!strcmp(res->what, "xstats"))
7342                         RTE_ETH_FOREACH_DEV(i)
7343                                 nic_xstats_clear(i);
7344         } else if (!strcmp(res->what, "info"))
7345                 RTE_ETH_FOREACH_DEV(i)
7346                         port_infos_display(i);
7347         else if (!strcmp(res->what, "summary")) {
7348                 port_summary_header_display();
7349                 RTE_ETH_FOREACH_DEV(i)
7350                         port_summary_display(i);
7351         }
7352         else if (!strcmp(res->what, "stats"))
7353                 RTE_ETH_FOREACH_DEV(i)
7354                         nic_stats_display(i);
7355         else if (!strcmp(res->what, "xstats"))
7356                 RTE_ETH_FOREACH_DEV(i)
7357                         nic_xstats_display(i);
7358         else if (!strcmp(res->what, "fdir"))
7359                 RTE_ETH_FOREACH_DEV(i)
7360                         fdir_get_infos(i);
7361         else if (!strcmp(res->what, "stat_qmap"))
7362                 RTE_ETH_FOREACH_DEV(i)
7363                         nic_stats_mapping_display(i);
7364         else if (!strcmp(res->what, "dcb_tc"))
7365                 RTE_ETH_FOREACH_DEV(i)
7366                         port_dcb_info_display(i);
7367         else if (!strcmp(res->what, "cap"))
7368                 RTE_ETH_FOREACH_DEV(i)
7369                         port_offload_cap_display(i);
7370 }
7371
7372 cmdline_parse_token_string_t cmd_showportall_show =
7373         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7374                                  "show#clear");
7375 cmdline_parse_token_string_t cmd_showportall_port =
7376         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7377 cmdline_parse_token_string_t cmd_showportall_what =
7378         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7379                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7380 cmdline_parse_token_string_t cmd_showportall_all =
7381         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7382 cmdline_parse_inst_t cmd_showportall = {
7383         .f = cmd_showportall_parsed,
7384         .data = NULL,
7385         .help_str = "show|clear port "
7386                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7387         .tokens = {
7388                 (void *)&cmd_showportall_show,
7389                 (void *)&cmd_showportall_port,
7390                 (void *)&cmd_showportall_what,
7391                 (void *)&cmd_showportall_all,
7392                 NULL,
7393         },
7394 };
7395
7396 /* *** SHOW PORT INFO *** */
7397 struct cmd_showport_result {
7398         cmdline_fixed_string_t show;
7399         cmdline_fixed_string_t port;
7400         cmdline_fixed_string_t what;
7401         uint16_t portnum;
7402 };
7403
7404 static void cmd_showport_parsed(void *parsed_result,
7405                                 __attribute__((unused)) struct cmdline *cl,
7406                                 __attribute__((unused)) void *data)
7407 {
7408         struct cmd_showport_result *res = parsed_result;
7409         if (!strcmp(res->show, "clear")) {
7410                 if (!strcmp(res->what, "stats"))
7411                         nic_stats_clear(res->portnum);
7412                 else if (!strcmp(res->what, "xstats"))
7413                         nic_xstats_clear(res->portnum);
7414         } else if (!strcmp(res->what, "info"))
7415                 port_infos_display(res->portnum);
7416         else if (!strcmp(res->what, "summary")) {
7417                 port_summary_header_display();
7418                 port_summary_display(res->portnum);
7419         }
7420         else if (!strcmp(res->what, "stats"))
7421                 nic_stats_display(res->portnum);
7422         else if (!strcmp(res->what, "xstats"))
7423                 nic_xstats_display(res->portnum);
7424         else if (!strcmp(res->what, "fdir"))
7425                  fdir_get_infos(res->portnum);
7426         else if (!strcmp(res->what, "stat_qmap"))
7427                 nic_stats_mapping_display(res->portnum);
7428         else if (!strcmp(res->what, "dcb_tc"))
7429                 port_dcb_info_display(res->portnum);
7430         else if (!strcmp(res->what, "cap"))
7431                 port_offload_cap_display(res->portnum);
7432 }
7433
7434 cmdline_parse_token_string_t cmd_showport_show =
7435         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7436                                  "show#clear");
7437 cmdline_parse_token_string_t cmd_showport_port =
7438         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7439 cmdline_parse_token_string_t cmd_showport_what =
7440         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7441                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7442 cmdline_parse_token_num_t cmd_showport_portnum =
7443         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7444
7445 cmdline_parse_inst_t cmd_showport = {
7446         .f = cmd_showport_parsed,
7447         .data = NULL,
7448         .help_str = "show|clear port "
7449                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7450                 "<port_id>",
7451         .tokens = {
7452                 (void *)&cmd_showport_show,
7453                 (void *)&cmd_showport_port,
7454                 (void *)&cmd_showport_what,
7455                 (void *)&cmd_showport_portnum,
7456                 NULL,
7457         },
7458 };
7459
7460 /* *** SHOW QUEUE INFO *** */
7461 struct cmd_showqueue_result {
7462         cmdline_fixed_string_t show;
7463         cmdline_fixed_string_t type;
7464         cmdline_fixed_string_t what;
7465         uint16_t portnum;
7466         uint16_t queuenum;
7467 };
7468
7469 static void
7470 cmd_showqueue_parsed(void *parsed_result,
7471         __attribute__((unused)) struct cmdline *cl,
7472         __attribute__((unused)) void *data)
7473 {
7474         struct cmd_showqueue_result *res = parsed_result;
7475
7476         if (!strcmp(res->type, "rxq"))
7477                 rx_queue_infos_display(res->portnum, res->queuenum);
7478         else if (!strcmp(res->type, "txq"))
7479                 tx_queue_infos_display(res->portnum, res->queuenum);
7480 }
7481
7482 cmdline_parse_token_string_t cmd_showqueue_show =
7483         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7484 cmdline_parse_token_string_t cmd_showqueue_type =
7485         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7486 cmdline_parse_token_string_t cmd_showqueue_what =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7488 cmdline_parse_token_num_t cmd_showqueue_portnum =
7489         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7490 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7491         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7492
7493 cmdline_parse_inst_t cmd_showqueue = {
7494         .f = cmd_showqueue_parsed,
7495         .data = NULL,
7496         .help_str = "show rxq|txq info <port_id> <queue_id>",
7497         .tokens = {
7498                 (void *)&cmd_showqueue_show,
7499                 (void *)&cmd_showqueue_type,
7500                 (void *)&cmd_showqueue_what,
7501                 (void *)&cmd_showqueue_portnum,
7502                 (void *)&cmd_showqueue_queuenum,
7503                 NULL,
7504         },
7505 };
7506
7507 /* show/clear fwd engine statistics */
7508 struct fwd_result {
7509         cmdline_fixed_string_t action;
7510         cmdline_fixed_string_t fwd;
7511         cmdline_fixed_string_t stats;
7512         cmdline_fixed_string_t all;
7513 };
7514
7515 cmdline_parse_token_string_t cmd_fwd_action =
7516         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7517 cmdline_parse_token_string_t cmd_fwd_fwd =
7518         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7519 cmdline_parse_token_string_t cmd_fwd_stats =
7520         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7521 cmdline_parse_token_string_t cmd_fwd_all =
7522         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7523
7524 static void
7525 cmd_showfwdall_parsed(void *parsed_result,
7526                       __rte_unused struct cmdline *cl,
7527                       __rte_unused void *data)
7528 {
7529         struct fwd_result *res = parsed_result;
7530
7531         if (!strcmp(res->action, "show"))
7532                 fwd_stats_display();
7533         else
7534                 fwd_stats_reset();
7535 }
7536
7537 static cmdline_parse_inst_t cmd_showfwdall = {
7538         .f = cmd_showfwdall_parsed,
7539         .data = NULL,
7540         .help_str = "show|clear fwd stats all",
7541         .tokens = {
7542                 (void *)&cmd_fwd_action,
7543                 (void *)&cmd_fwd_fwd,
7544                 (void *)&cmd_fwd_stats,
7545                 (void *)&cmd_fwd_all,
7546                 NULL,
7547         },
7548 };
7549
7550 /* *** READ PORT REGISTER *** */
7551 struct cmd_read_reg_result {
7552         cmdline_fixed_string_t read;
7553         cmdline_fixed_string_t reg;
7554         portid_t port_id;
7555         uint32_t reg_off;
7556 };
7557
7558 static void
7559 cmd_read_reg_parsed(void *parsed_result,
7560                     __attribute__((unused)) struct cmdline *cl,
7561                     __attribute__((unused)) void *data)
7562 {
7563         struct cmd_read_reg_result *res = parsed_result;
7564         port_reg_display(res->port_id, res->reg_off);
7565 }
7566
7567 cmdline_parse_token_string_t cmd_read_reg_read =
7568         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7569 cmdline_parse_token_string_t cmd_read_reg_reg =
7570         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7571 cmdline_parse_token_num_t cmd_read_reg_port_id =
7572         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7573 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7574         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7575
7576 cmdline_parse_inst_t cmd_read_reg = {
7577         .f = cmd_read_reg_parsed,
7578         .data = NULL,
7579         .help_str = "read reg <port_id> <reg_off>",
7580         .tokens = {
7581                 (void *)&cmd_read_reg_read,
7582                 (void *)&cmd_read_reg_reg,
7583                 (void *)&cmd_read_reg_port_id,
7584                 (void *)&cmd_read_reg_reg_off,
7585                 NULL,
7586         },
7587 };
7588
7589 /* *** READ PORT REGISTER BIT FIELD *** */
7590 struct cmd_read_reg_bit_field_result {
7591         cmdline_fixed_string_t read;
7592         cmdline_fixed_string_t regfield;
7593         portid_t port_id;
7594         uint32_t reg_off;
7595         uint8_t bit1_pos;
7596         uint8_t bit2_pos;
7597 };
7598
7599 static void
7600 cmd_read_reg_bit_field_parsed(void *parsed_result,
7601                               __attribute__((unused)) struct cmdline *cl,
7602                               __attribute__((unused)) void *data)
7603 {
7604         struct cmd_read_reg_bit_field_result *res = parsed_result;
7605         port_reg_bit_field_display(res->port_id, res->reg_off,
7606                                    res->bit1_pos, res->bit2_pos);
7607 }
7608
7609 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7610         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7611                                  "read");
7612 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7613         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7614                                  regfield, "regfield");
7615 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7616         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7617                               UINT16);
7618 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7619         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7620                               UINT32);
7621 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7622         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7623                               UINT8);
7624 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7625         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7626                               UINT8);
7627
7628 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7629         .f = cmd_read_reg_bit_field_parsed,
7630         .data = NULL,
7631         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7632         "Read register bit field between bit_x and bit_y included",
7633         .tokens = {
7634                 (void *)&cmd_read_reg_bit_field_read,
7635                 (void *)&cmd_read_reg_bit_field_regfield,
7636                 (void *)&cmd_read_reg_bit_field_port_id,
7637                 (void *)&cmd_read_reg_bit_field_reg_off,
7638                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7639                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7640                 NULL,
7641         },
7642 };
7643
7644 /* *** READ PORT REGISTER BIT *** */
7645 struct cmd_read_reg_bit_result {
7646         cmdline_fixed_string_t read;
7647         cmdline_fixed_string_t regbit;
7648         portid_t port_id;
7649         uint32_t reg_off;
7650         uint8_t bit_pos;
7651 };
7652
7653 static void
7654 cmd_read_reg_bit_parsed(void *parsed_result,
7655                         __attribute__((unused)) struct cmdline *cl,
7656                         __attribute__((unused)) void *data)
7657 {
7658         struct cmd_read_reg_bit_result *res = parsed_result;
7659         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7660 }
7661
7662 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7663         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7664 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7665         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7666                                  regbit, "regbit");
7667 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7668         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7669 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7670         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7671 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7672         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7673
7674 cmdline_parse_inst_t cmd_read_reg_bit = {
7675         .f = cmd_read_reg_bit_parsed,
7676         .data = NULL,
7677         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7678         .tokens = {
7679                 (void *)&cmd_read_reg_bit_read,
7680                 (void *)&cmd_read_reg_bit_regbit,
7681                 (void *)&cmd_read_reg_bit_port_id,
7682                 (void *)&cmd_read_reg_bit_reg_off,
7683                 (void *)&cmd_read_reg_bit_bit_pos,
7684                 NULL,
7685         },
7686 };
7687
7688 /* *** WRITE PORT REGISTER *** */
7689 struct cmd_write_reg_result {
7690         cmdline_fixed_string_t write;
7691         cmdline_fixed_string_t reg;
7692         portid_t port_id;
7693         uint32_t reg_off;
7694         uint32_t value;
7695 };
7696
7697 static void
7698 cmd_write_reg_parsed(void *parsed_result,
7699                      __attribute__((unused)) struct cmdline *cl,
7700                      __attribute__((unused)) void *data)
7701 {
7702         struct cmd_write_reg_result *res = parsed_result;
7703         port_reg_set(res->port_id, res->reg_off, res->value);
7704 }
7705
7706 cmdline_parse_token_string_t cmd_write_reg_write =
7707         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7708 cmdline_parse_token_string_t cmd_write_reg_reg =
7709         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7710 cmdline_parse_token_num_t cmd_write_reg_port_id =
7711         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7712 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7713         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7714 cmdline_parse_token_num_t cmd_write_reg_value =
7715         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7716
7717 cmdline_parse_inst_t cmd_write_reg = {
7718         .f = cmd_write_reg_parsed,
7719         .data = NULL,
7720         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7721         .tokens = {
7722                 (void *)&cmd_write_reg_write,
7723                 (void *)&cmd_write_reg_reg,
7724                 (void *)&cmd_write_reg_port_id,
7725                 (void *)&cmd_write_reg_reg_off,
7726                 (void *)&cmd_write_reg_value,
7727                 NULL,
7728         },
7729 };
7730
7731 /* *** WRITE PORT REGISTER BIT FIELD *** */
7732 struct cmd_write_reg_bit_field_result {
7733         cmdline_fixed_string_t write;
7734         cmdline_fixed_string_t regfield;
7735         portid_t port_id;
7736         uint32_t reg_off;
7737         uint8_t bit1_pos;
7738         uint8_t bit2_pos;
7739         uint32_t value;
7740 };
7741
7742 static void
7743 cmd_write_reg_bit_field_parsed(void *parsed_result,
7744                                __attribute__((unused)) struct cmdline *cl,
7745                                __attribute__((unused)) void *data)
7746 {
7747         struct cmd_write_reg_bit_field_result *res = parsed_result;
7748         port_reg_bit_field_set(res->port_id, res->reg_off,
7749                           res->bit1_pos, res->bit2_pos, res->value);
7750 }
7751
7752 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7753         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7754                                  "write");
7755 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7756         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7757                                  regfield, "regfield");
7758 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7759         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7760                               UINT16);
7761 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7762         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7763                               UINT32);
7764 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7765         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7766                               UINT8);
7767 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7768         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7769                               UINT8);
7770 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7771         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7772                               UINT32);
7773
7774 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7775         .f = cmd_write_reg_bit_field_parsed,
7776         .data = NULL,
7777         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7778                 "<reg_value>: "
7779                 "Set register bit field between bit_x and bit_y included",
7780         .tokens = {
7781                 (void *)&cmd_write_reg_bit_field_write,
7782                 (void *)&cmd_write_reg_bit_field_regfield,
7783                 (void *)&cmd_write_reg_bit_field_port_id,
7784                 (void *)&cmd_write_reg_bit_field_reg_off,
7785                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7786                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7787                 (void *)&cmd_write_reg_bit_field_value,
7788                 NULL,
7789         },
7790 };
7791
7792 /* *** WRITE PORT REGISTER BIT *** */
7793 struct cmd_write_reg_bit_result {
7794         cmdline_fixed_string_t write;
7795         cmdline_fixed_string_t regbit;
7796         portid_t port_id;
7797         uint32_t reg_off;
7798         uint8_t bit_pos;
7799         uint8_t value;
7800 };
7801
7802 static void
7803 cmd_write_reg_bit_parsed(void *parsed_result,
7804                          __attribute__((unused)) struct cmdline *cl,
7805                          __attribute__((unused)) void *data)
7806 {
7807         struct cmd_write_reg_bit_result *res = parsed_result;
7808         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7809 }
7810
7811 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7812         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7813                                  "write");
7814 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7815         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7816                                  regbit, "regbit");
7817 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7818         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7819 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7820         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7821 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7822         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7823 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7824         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7825
7826 cmdline_parse_inst_t cmd_write_reg_bit = {
7827         .f = cmd_write_reg_bit_parsed,
7828         .data = NULL,
7829         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7830                 "0 <= bit_x <= 31",
7831         .tokens = {
7832                 (void *)&cmd_write_reg_bit_write,
7833                 (void *)&cmd_write_reg_bit_regbit,
7834                 (void *)&cmd_write_reg_bit_port_id,
7835                 (void *)&cmd_write_reg_bit_reg_off,
7836                 (void *)&cmd_write_reg_bit_bit_pos,
7837                 (void *)&cmd_write_reg_bit_value,
7838                 NULL,
7839         },
7840 };
7841
7842 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7843 struct cmd_read_rxd_txd_result {
7844         cmdline_fixed_string_t read;
7845         cmdline_fixed_string_t rxd_txd;
7846         portid_t port_id;
7847         uint16_t queue_id;
7848         uint16_t desc_id;
7849 };
7850
7851 static void
7852 cmd_read_rxd_txd_parsed(void *parsed_result,
7853                         __attribute__((unused)) struct cmdline *cl,
7854                         __attribute__((unused)) void *data)
7855 {
7856         struct cmd_read_rxd_txd_result *res = parsed_result;
7857
7858         if (!strcmp(res->rxd_txd, "rxd"))
7859                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7860         else if (!strcmp(res->rxd_txd, "txd"))
7861                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7862 }
7863
7864 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7865         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7866 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7867         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7868                                  "rxd#txd");
7869 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7870         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7871 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7872         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7873 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7874         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7875
7876 cmdline_parse_inst_t cmd_read_rxd_txd = {
7877         .f = cmd_read_rxd_txd_parsed,
7878         .data = NULL,
7879         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7880         .tokens = {
7881                 (void *)&cmd_read_rxd_txd_read,
7882                 (void *)&cmd_read_rxd_txd_rxd_txd,
7883                 (void *)&cmd_read_rxd_txd_port_id,
7884                 (void *)&cmd_read_rxd_txd_queue_id,
7885                 (void *)&cmd_read_rxd_txd_desc_id,
7886                 NULL,
7887         },
7888 };
7889
7890 /* *** QUIT *** */
7891 struct cmd_quit_result {
7892         cmdline_fixed_string_t quit;
7893 };
7894
7895 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7896                             struct cmdline *cl,
7897                             __attribute__((unused)) void *data)
7898 {
7899         cmdline_quit(cl);
7900 }
7901
7902 cmdline_parse_token_string_t cmd_quit_quit =
7903         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7904
7905 cmdline_parse_inst_t cmd_quit = {
7906         .f = cmd_quit_parsed,
7907         .data = NULL,
7908         .help_str = "quit: Exit application",
7909         .tokens = {
7910                 (void *)&cmd_quit_quit,
7911                 NULL,
7912         },
7913 };
7914
7915 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7916 struct cmd_mac_addr_result {
7917         cmdline_fixed_string_t mac_addr_cmd;
7918         cmdline_fixed_string_t what;
7919         uint16_t port_num;
7920         struct rte_ether_addr address;
7921 };
7922
7923 static void cmd_mac_addr_parsed(void *parsed_result,
7924                 __attribute__((unused)) struct cmdline *cl,
7925                 __attribute__((unused)) void *data)
7926 {
7927         struct cmd_mac_addr_result *res = parsed_result;
7928         int ret;
7929
7930         if (strcmp(res->what, "add") == 0)
7931                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7932         else if (strcmp(res->what, "set") == 0)
7933                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7934                                                        &res->address);
7935         else
7936                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7937
7938         /* check the return value and print it if is < 0 */
7939         if(ret < 0)
7940                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7941
7942 }
7943
7944 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7945         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7946                                 "mac_addr");
7947 cmdline_parse_token_string_t cmd_mac_addr_what =
7948         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7949                                 "add#remove#set");
7950 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7951                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7952                                         UINT16);
7953 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7954                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7955
7956 cmdline_parse_inst_t cmd_mac_addr = {
7957         .f = cmd_mac_addr_parsed,
7958         .data = (void *)0,
7959         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7960                         "Add/Remove/Set MAC address on port_id",
7961         .tokens = {
7962                 (void *)&cmd_mac_addr_cmd,
7963                 (void *)&cmd_mac_addr_what,
7964                 (void *)&cmd_mac_addr_portnum,
7965                 (void *)&cmd_mac_addr_addr,
7966                 NULL,
7967         },
7968 };
7969
7970 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7971 struct cmd_eth_peer_result {
7972         cmdline_fixed_string_t set;
7973         cmdline_fixed_string_t eth_peer;
7974         portid_t port_id;
7975         cmdline_fixed_string_t peer_addr;
7976 };
7977
7978 static void cmd_set_eth_peer_parsed(void *parsed_result,
7979                         __attribute__((unused)) struct cmdline *cl,
7980                         __attribute__((unused)) void *data)
7981 {
7982                 struct cmd_eth_peer_result *res = parsed_result;
7983
7984                 if (test_done == 0) {
7985                         printf("Please stop forwarding first\n");
7986                         return;
7987                 }
7988                 if (!strcmp(res->eth_peer, "eth-peer")) {
7989                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7990                         fwd_config_setup();
7991                 }
7992 }
7993 cmdline_parse_token_string_t cmd_eth_peer_set =
7994         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7995 cmdline_parse_token_string_t cmd_eth_peer =
7996         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7997 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7998         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7999 cmdline_parse_token_string_t cmd_eth_peer_addr =
8000         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8001
8002 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8003         .f = cmd_set_eth_peer_parsed,
8004         .data = NULL,
8005         .help_str = "set eth-peer <port_id> <peer_mac>",
8006         .tokens = {
8007                 (void *)&cmd_eth_peer_set,
8008                 (void *)&cmd_eth_peer,
8009                 (void *)&cmd_eth_peer_port_id,
8010                 (void *)&cmd_eth_peer_addr,
8011                 NULL,
8012         },
8013 };
8014
8015 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8016 struct cmd_set_qmap_result {
8017         cmdline_fixed_string_t set;
8018         cmdline_fixed_string_t qmap;
8019         cmdline_fixed_string_t what;
8020         portid_t port_id;
8021         uint16_t queue_id;
8022         uint8_t map_value;
8023 };
8024
8025 static void
8026 cmd_set_qmap_parsed(void *parsed_result,
8027                        __attribute__((unused)) struct cmdline *cl,
8028                        __attribute__((unused)) void *data)
8029 {
8030         struct cmd_set_qmap_result *res = parsed_result;
8031         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8032
8033         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8034 }
8035
8036 cmdline_parse_token_string_t cmd_setqmap_set =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8038                                  set, "set");
8039 cmdline_parse_token_string_t cmd_setqmap_qmap =
8040         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8041                                  qmap, "stat_qmap");
8042 cmdline_parse_token_string_t cmd_setqmap_what =
8043         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8044                                  what, "tx#rx");
8045 cmdline_parse_token_num_t cmd_setqmap_portid =
8046         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8047                               port_id, UINT16);
8048 cmdline_parse_token_num_t cmd_setqmap_queueid =
8049         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8050                               queue_id, UINT16);
8051 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8052         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8053                               map_value, UINT8);
8054
8055 cmdline_parse_inst_t cmd_set_qmap = {
8056         .f = cmd_set_qmap_parsed,
8057         .data = NULL,
8058         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8059                 "Set statistics mapping value on tx|rx queue_id of port_id",
8060         .tokens = {
8061                 (void *)&cmd_setqmap_set,
8062                 (void *)&cmd_setqmap_qmap,
8063                 (void *)&cmd_setqmap_what,
8064                 (void *)&cmd_setqmap_portid,
8065                 (void *)&cmd_setqmap_queueid,
8066                 (void *)&cmd_setqmap_mapvalue,
8067                 NULL,
8068         },
8069 };
8070
8071 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8072 struct cmd_set_xstats_hide_zero_result {
8073         cmdline_fixed_string_t keyword;
8074         cmdline_fixed_string_t name;
8075         cmdline_fixed_string_t on_off;
8076 };
8077
8078 static void
8079 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8080                         __attribute__((unused)) struct cmdline *cl,
8081                         __attribute__((unused)) void *data)
8082 {
8083         struct cmd_set_xstats_hide_zero_result *res;
8084         uint16_t on_off = 0;
8085
8086         res = parsed_result;
8087         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8088         set_xstats_hide_zero(on_off);
8089 }
8090
8091 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8092         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8093                                  keyword, "set");
8094 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8095         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8096                                  name, "xstats-hide-zero");
8097 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8098         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8099                                  on_off, "on#off");
8100
8101 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8102         .f = cmd_set_xstats_hide_zero_parsed,
8103         .data = NULL,
8104         .help_str = "set xstats-hide-zero on|off",
8105         .tokens = {
8106                 (void *)&cmd_set_xstats_hide_zero_keyword,
8107                 (void *)&cmd_set_xstats_hide_zero_name,
8108                 (void *)&cmd_set_xstats_hide_zero_on_off,
8109                 NULL,
8110         },
8111 };
8112
8113 /* *** CONFIGURE UNICAST HASH TABLE *** */
8114 struct cmd_set_uc_hash_table {
8115         cmdline_fixed_string_t set;
8116         cmdline_fixed_string_t port;
8117         portid_t port_id;
8118         cmdline_fixed_string_t what;
8119         struct rte_ether_addr address;
8120         cmdline_fixed_string_t mode;
8121 };
8122
8123 static void
8124 cmd_set_uc_hash_parsed(void *parsed_result,
8125                        __attribute__((unused)) struct cmdline *cl,
8126                        __attribute__((unused)) void *data)
8127 {
8128         int ret=0;
8129         struct cmd_set_uc_hash_table *res = parsed_result;
8130
8131         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8132
8133         if (strcmp(res->what, "uta") == 0)
8134                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8135                                                 &res->address,(uint8_t)is_on);
8136         if (ret < 0)
8137                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8138
8139 }
8140
8141 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8142         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8143                                  set, "set");
8144 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8145         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8146                                  port, "port");
8147 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8148         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8149                               port_id, UINT16);
8150 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8151         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8152                                  what, "uta");
8153 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8154         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8155                                 address);
8156 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8157         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8158                                  mode, "on#off");
8159
8160 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8161         .f = cmd_set_uc_hash_parsed,
8162         .data = NULL,
8163         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8164         .tokens = {
8165                 (void *)&cmd_set_uc_hash_set,
8166                 (void *)&cmd_set_uc_hash_port,
8167                 (void *)&cmd_set_uc_hash_portid,
8168                 (void *)&cmd_set_uc_hash_what,
8169                 (void *)&cmd_set_uc_hash_mac,
8170                 (void *)&cmd_set_uc_hash_mode,
8171                 NULL,
8172         },
8173 };
8174
8175 struct cmd_set_uc_all_hash_table {
8176         cmdline_fixed_string_t set;
8177         cmdline_fixed_string_t port;
8178         portid_t port_id;
8179         cmdline_fixed_string_t what;
8180         cmdline_fixed_string_t value;
8181         cmdline_fixed_string_t mode;
8182 };
8183
8184 static void
8185 cmd_set_uc_all_hash_parsed(void *parsed_result,
8186                        __attribute__((unused)) struct cmdline *cl,
8187                        __attribute__((unused)) void *data)
8188 {
8189         int ret=0;
8190         struct cmd_set_uc_all_hash_table *res = parsed_result;
8191
8192         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8193
8194         if ((strcmp(res->what, "uta") == 0) &&
8195                 (strcmp(res->value, "all") == 0))
8196                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8197         if (ret < 0)
8198                 printf("bad unicast hash table parameter,"
8199                         "return code = %d \n", ret);
8200 }
8201
8202 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8203         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8204                                  set, "set");
8205 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8206         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8207                                  port, "port");
8208 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8209         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8210                               port_id, UINT16);
8211 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8213                                  what, "uta");
8214 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8216                                 value,"all");
8217 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8219                                  mode, "on#off");
8220
8221 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8222         .f = cmd_set_uc_all_hash_parsed,
8223         .data = NULL,
8224         .help_str = "set port <port_id> uta all on|off",
8225         .tokens = {
8226                 (void *)&cmd_set_uc_all_hash_set,
8227                 (void *)&cmd_set_uc_all_hash_port,
8228                 (void *)&cmd_set_uc_all_hash_portid,
8229                 (void *)&cmd_set_uc_all_hash_what,
8230                 (void *)&cmd_set_uc_all_hash_value,
8231                 (void *)&cmd_set_uc_all_hash_mode,
8232                 NULL,
8233         },
8234 };
8235
8236 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8237 struct cmd_set_vf_macvlan_filter {
8238         cmdline_fixed_string_t set;
8239         cmdline_fixed_string_t port;
8240         portid_t port_id;
8241         cmdline_fixed_string_t vf;
8242         uint8_t vf_id;
8243         struct rte_ether_addr address;
8244         cmdline_fixed_string_t filter_type;
8245         cmdline_fixed_string_t mode;
8246 };
8247
8248 static void
8249 cmd_set_vf_macvlan_parsed(void *parsed_result,
8250                        __attribute__((unused)) struct cmdline *cl,
8251                        __attribute__((unused)) void *data)
8252 {
8253         int is_on, ret = 0;
8254         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8255         struct rte_eth_mac_filter filter;
8256
8257         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8258
8259         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8260
8261         /* set VF MAC filter */
8262         filter.is_vf = 1;
8263
8264         /* set VF ID */
8265         filter.dst_id = res->vf_id;
8266
8267         if (!strcmp(res->filter_type, "exact-mac"))
8268                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8269         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8270                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8271         else if (!strcmp(res->filter_type, "hashmac"))
8272                 filter.filter_type = RTE_MAC_HASH_MATCH;
8273         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8274                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8275
8276         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8277
8278         if (is_on)
8279                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8280                                         RTE_ETH_FILTER_MACVLAN,
8281                                         RTE_ETH_FILTER_ADD,
8282                                          &filter);
8283         else
8284                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8285                                         RTE_ETH_FILTER_MACVLAN,
8286                                         RTE_ETH_FILTER_DELETE,
8287                                         &filter);
8288
8289         if (ret < 0)
8290                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8291
8292 }
8293
8294 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8295         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8296                                  set, "set");
8297 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8298         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8299                                  port, "port");
8300 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8301         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8302                               port_id, UINT16);
8303 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8305                                  vf, "vf");
8306 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8307         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8308                                 vf_id, UINT8);
8309 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8310         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8311                                 address);
8312 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8313         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8314                                 filter_type, "exact-mac#exact-mac-vlan"
8315                                 "#hashmac#hashmac-vlan");
8316 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8317         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8318                                  mode, "on#off");
8319
8320 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8321         .f = cmd_set_vf_macvlan_parsed,
8322         .data = NULL,
8323         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8324                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8325                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8326                 "hash match rule: hash match of MAC and exact match of VLAN",
8327         .tokens = {
8328                 (void *)&cmd_set_vf_macvlan_set,
8329                 (void *)&cmd_set_vf_macvlan_port,
8330                 (void *)&cmd_set_vf_macvlan_portid,
8331                 (void *)&cmd_set_vf_macvlan_vf,
8332                 (void *)&cmd_set_vf_macvlan_vf_id,
8333                 (void *)&cmd_set_vf_macvlan_mac,
8334                 (void *)&cmd_set_vf_macvlan_filter_type,
8335                 (void *)&cmd_set_vf_macvlan_mode,
8336                 NULL,
8337         },
8338 };
8339
8340 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8341 struct cmd_set_vf_traffic {
8342         cmdline_fixed_string_t set;
8343         cmdline_fixed_string_t port;
8344         portid_t port_id;
8345         cmdline_fixed_string_t vf;
8346         uint8_t vf_id;
8347         cmdline_fixed_string_t what;
8348         cmdline_fixed_string_t mode;
8349 };
8350
8351 static void
8352 cmd_set_vf_traffic_parsed(void *parsed_result,
8353                        __attribute__((unused)) struct cmdline *cl,
8354                        __attribute__((unused)) void *data)
8355 {
8356         struct cmd_set_vf_traffic *res = parsed_result;
8357         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8358         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8359
8360         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8361 }
8362
8363 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8364         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8365                                  set, "set");
8366 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8367         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8368                                  port, "port");
8369 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8370         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8371                               port_id, UINT16);
8372 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8373         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8374                                  vf, "vf");
8375 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8376         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8377                               vf_id, UINT8);
8378 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8380                                  what, "tx#rx");
8381 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8382         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8383                                  mode, "on#off");
8384
8385 cmdline_parse_inst_t cmd_set_vf_traffic = {
8386         .f = cmd_set_vf_traffic_parsed,
8387         .data = NULL,
8388         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8389         .tokens = {
8390                 (void *)&cmd_setvf_traffic_set,
8391                 (void *)&cmd_setvf_traffic_port,
8392                 (void *)&cmd_setvf_traffic_portid,
8393                 (void *)&cmd_setvf_traffic_vf,
8394                 (void *)&cmd_setvf_traffic_vfid,
8395                 (void *)&cmd_setvf_traffic_what,
8396                 (void *)&cmd_setvf_traffic_mode,
8397                 NULL,
8398         },
8399 };
8400
8401 /* *** CONFIGURE VF RECEIVE MODE *** */
8402 struct cmd_set_vf_rxmode {
8403         cmdline_fixed_string_t set;
8404         cmdline_fixed_string_t port;
8405         portid_t port_id;
8406         cmdline_fixed_string_t vf;
8407         uint8_t vf_id;
8408         cmdline_fixed_string_t what;
8409         cmdline_fixed_string_t mode;
8410         cmdline_fixed_string_t on;
8411 };
8412
8413 static void
8414 cmd_set_vf_rxmode_parsed(void *parsed_result,
8415                        __attribute__((unused)) struct cmdline *cl,
8416                        __attribute__((unused)) void *data)
8417 {
8418         int ret = -ENOTSUP;
8419         uint16_t rx_mode = 0;
8420         struct cmd_set_vf_rxmode *res = parsed_result;
8421
8422         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8423         if (!strcmp(res->what,"rxmode")) {
8424                 if (!strcmp(res->mode, "AUPE"))
8425                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8426                 else if (!strcmp(res->mode, "ROPE"))
8427                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8428                 else if (!strcmp(res->mode, "BAM"))
8429                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8430                 else if (!strncmp(res->mode, "MPE",3))
8431                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8432         }
8433
8434         RTE_SET_USED(is_on);
8435
8436 #ifdef RTE_LIBRTE_IXGBE_PMD
8437         if (ret == -ENOTSUP)
8438                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8439                                                   rx_mode, (uint8_t)is_on);
8440 #endif
8441 #ifdef RTE_LIBRTE_BNXT_PMD
8442         if (ret == -ENOTSUP)
8443                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8444                                                  rx_mode, (uint8_t)is_on);
8445 #endif
8446         if (ret < 0)
8447                 printf("bad VF receive mode parameter, return code = %d \n",
8448                 ret);
8449 }
8450
8451 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8452         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8453                                  set, "set");
8454 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8455         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8456                                  port, "port");
8457 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8458         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8459                               port_id, UINT16);
8460 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8461         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8462                                  vf, "vf");
8463 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8464         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8465                               vf_id, UINT8);
8466 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8467         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8468                                  what, "rxmode");
8469 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8470         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8471                                  mode, "AUPE#ROPE#BAM#MPE");
8472 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8474                                  on, "on#off");
8475
8476 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8477         .f = cmd_set_vf_rxmode_parsed,
8478         .data = NULL,
8479         .help_str = "set port <port_id> vf <vf_id> rxmode "
8480                 "AUPE|ROPE|BAM|MPE on|off",
8481         .tokens = {
8482                 (void *)&cmd_set_vf_rxmode_set,
8483                 (void *)&cmd_set_vf_rxmode_port,
8484                 (void *)&cmd_set_vf_rxmode_portid,
8485                 (void *)&cmd_set_vf_rxmode_vf,
8486                 (void *)&cmd_set_vf_rxmode_vfid,
8487                 (void *)&cmd_set_vf_rxmode_what,
8488                 (void *)&cmd_set_vf_rxmode_mode,
8489                 (void *)&cmd_set_vf_rxmode_on,
8490                 NULL,
8491         },
8492 };
8493
8494 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8495 struct cmd_vf_mac_addr_result {
8496         cmdline_fixed_string_t mac_addr_cmd;
8497         cmdline_fixed_string_t what;
8498         cmdline_fixed_string_t port;
8499         uint16_t port_num;
8500         cmdline_fixed_string_t vf;
8501         uint8_t vf_num;
8502         struct rte_ether_addr address;
8503 };
8504
8505 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8506                 __attribute__((unused)) struct cmdline *cl,
8507                 __attribute__((unused)) void *data)
8508 {
8509         struct cmd_vf_mac_addr_result *res = parsed_result;
8510         int ret = -ENOTSUP;
8511
8512         if (strcmp(res->what, "add") != 0)
8513                 return;
8514
8515 #ifdef RTE_LIBRTE_I40E_PMD
8516         if (ret == -ENOTSUP)
8517                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8518                                                    &res->address);
8519 #endif
8520 #ifdef RTE_LIBRTE_BNXT_PMD
8521         if (ret == -ENOTSUP)
8522                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8523                                                 res->vf_num);
8524 #endif
8525
8526         if(ret < 0)
8527                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8528
8529 }
8530
8531 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8532         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8533                                 mac_addr_cmd,"mac_addr");
8534 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8535         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8536                                 what,"add");
8537 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8538         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8539                                 port,"port");
8540 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8541         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8542                                 port_num, UINT16);
8543 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8544         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8545                                 vf,"vf");
8546 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8547         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8548                                 vf_num, UINT8);
8549 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8550         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8551                                 address);
8552
8553 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8554         .f = cmd_vf_mac_addr_parsed,
8555         .data = (void *)0,
8556         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8557                 "Add MAC address filtering for a VF on port_id",
8558         .tokens = {
8559                 (void *)&cmd_vf_mac_addr_cmd,
8560                 (void *)&cmd_vf_mac_addr_what,
8561                 (void *)&cmd_vf_mac_addr_port,
8562                 (void *)&cmd_vf_mac_addr_portnum,
8563                 (void *)&cmd_vf_mac_addr_vf,
8564                 (void *)&cmd_vf_mac_addr_vfnum,
8565                 (void *)&cmd_vf_mac_addr_addr,
8566                 NULL,
8567         },
8568 };
8569
8570 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8571 struct cmd_vf_rx_vlan_filter {
8572         cmdline_fixed_string_t rx_vlan;
8573         cmdline_fixed_string_t what;
8574         uint16_t vlan_id;
8575         cmdline_fixed_string_t port;
8576         portid_t port_id;
8577         cmdline_fixed_string_t vf;
8578         uint64_t vf_mask;
8579 };
8580
8581 static void
8582 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8583                           __attribute__((unused)) struct cmdline *cl,
8584                           __attribute__((unused)) void *data)
8585 {
8586         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8587         int ret = -ENOTSUP;
8588
8589         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8590
8591 #ifdef RTE_LIBRTE_IXGBE_PMD
8592         if (ret == -ENOTSUP)
8593                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8594                                 res->vlan_id, res->vf_mask, is_add);
8595 #endif
8596 #ifdef RTE_LIBRTE_I40E_PMD
8597         if (ret == -ENOTSUP)
8598                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8599                                 res->vlan_id, res->vf_mask, is_add);
8600 #endif
8601 #ifdef RTE_LIBRTE_BNXT_PMD
8602         if (ret == -ENOTSUP)
8603                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8604                                 res->vlan_id, res->vf_mask, is_add);
8605 #endif
8606
8607         switch (ret) {
8608         case 0:
8609                 break;
8610         case -EINVAL:
8611                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8612                                 res->vlan_id, res->vf_mask);
8613                 break;
8614         case -ENODEV:
8615                 printf("invalid port_id %d\n", res->port_id);
8616                 break;
8617         case -ENOTSUP:
8618                 printf("function not implemented or supported\n");
8619                 break;
8620         default:
8621                 printf("programming error: (%s)\n", strerror(-ret));
8622         }
8623 }
8624
8625 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8626         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8627                                  rx_vlan, "rx_vlan");
8628 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8629         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8630                                  what, "add#rm");
8631 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8632         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8633                               vlan_id, UINT16);
8634 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8635         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8636                                  port, "port");
8637 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8638         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8639                               port_id, UINT16);
8640 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8641         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8642                                  vf, "vf");
8643 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8644         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8645                               vf_mask, UINT64);
8646
8647 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8648         .f = cmd_vf_rx_vlan_filter_parsed,
8649         .data = NULL,
8650         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8651                 "(vf_mask = hexadecimal VF mask)",
8652         .tokens = {
8653                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8654                 (void *)&cmd_vf_rx_vlan_filter_what,
8655                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8656                 (void *)&cmd_vf_rx_vlan_filter_port,
8657                 (void *)&cmd_vf_rx_vlan_filter_portid,
8658                 (void *)&cmd_vf_rx_vlan_filter_vf,
8659                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8660                 NULL,
8661         },
8662 };
8663
8664 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8665 struct cmd_queue_rate_limit_result {
8666         cmdline_fixed_string_t set;
8667         cmdline_fixed_string_t port;
8668         uint16_t port_num;
8669         cmdline_fixed_string_t queue;
8670         uint8_t queue_num;
8671         cmdline_fixed_string_t rate;
8672         uint16_t rate_num;
8673 };
8674
8675 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8676                 __attribute__((unused)) struct cmdline *cl,
8677                 __attribute__((unused)) void *data)
8678 {
8679         struct cmd_queue_rate_limit_result *res = parsed_result;
8680         int ret = 0;
8681
8682         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8683                 && (strcmp(res->queue, "queue") == 0)
8684                 && (strcmp(res->rate, "rate") == 0))
8685                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8686                                         res->rate_num);
8687         if (ret < 0)
8688                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8689
8690 }
8691
8692 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8693         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8694                                 set, "set");
8695 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8696         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8697                                 port, "port");
8698 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8699         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8700                                 port_num, UINT16);
8701 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8702         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8703                                 queue, "queue");
8704 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8705         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8706                                 queue_num, UINT8);
8707 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8708         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8709                                 rate, "rate");
8710 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8711         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8712                                 rate_num, UINT16);
8713
8714 cmdline_parse_inst_t cmd_queue_rate_limit = {
8715         .f = cmd_queue_rate_limit_parsed,
8716         .data = (void *)0,
8717         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8718                 "Set rate limit for a queue on port_id",
8719         .tokens = {
8720                 (void *)&cmd_queue_rate_limit_set,
8721                 (void *)&cmd_queue_rate_limit_port,
8722                 (void *)&cmd_queue_rate_limit_portnum,
8723                 (void *)&cmd_queue_rate_limit_queue,
8724                 (void *)&cmd_queue_rate_limit_queuenum,
8725                 (void *)&cmd_queue_rate_limit_rate,
8726                 (void *)&cmd_queue_rate_limit_ratenum,
8727                 NULL,
8728         },
8729 };
8730
8731 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8732 struct cmd_vf_rate_limit_result {
8733         cmdline_fixed_string_t set;
8734         cmdline_fixed_string_t port;
8735         uint16_t port_num;
8736         cmdline_fixed_string_t vf;
8737         uint8_t vf_num;
8738         cmdline_fixed_string_t rate;
8739         uint16_t rate_num;
8740         cmdline_fixed_string_t q_msk;
8741         uint64_t q_msk_val;
8742 };
8743
8744 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8745                 __attribute__((unused)) struct cmdline *cl,
8746                 __attribute__((unused)) void *data)
8747 {
8748         struct cmd_vf_rate_limit_result *res = parsed_result;
8749         int ret = 0;
8750
8751         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8752                 && (strcmp(res->vf, "vf") == 0)
8753                 && (strcmp(res->rate, "rate") == 0)
8754                 && (strcmp(res->q_msk, "queue_mask") == 0))
8755                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8756                                         res->rate_num, res->q_msk_val);
8757         if (ret < 0)
8758                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8759
8760 }
8761
8762 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8763         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8764                                 set, "set");
8765 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8766         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8767                                 port, "port");
8768 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8769         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8770                                 port_num, UINT16);
8771 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8773                                 vf, "vf");
8774 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8775         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8776                                 vf_num, UINT8);
8777 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8779                                 rate, "rate");
8780 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8782                                 rate_num, UINT16);
8783 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8784         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8785                                 q_msk, "queue_mask");
8786 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8787         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8788                                 q_msk_val, UINT64);
8789
8790 cmdline_parse_inst_t cmd_vf_rate_limit = {
8791         .f = cmd_vf_rate_limit_parsed,
8792         .data = (void *)0,
8793         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8794                 "queue_mask <queue_mask_value>: "
8795                 "Set rate limit for queues of VF on port_id",
8796         .tokens = {
8797                 (void *)&cmd_vf_rate_limit_set,
8798                 (void *)&cmd_vf_rate_limit_port,
8799                 (void *)&cmd_vf_rate_limit_portnum,
8800                 (void *)&cmd_vf_rate_limit_vf,
8801                 (void *)&cmd_vf_rate_limit_vfnum,
8802                 (void *)&cmd_vf_rate_limit_rate,
8803                 (void *)&cmd_vf_rate_limit_ratenum,
8804                 (void *)&cmd_vf_rate_limit_q_msk,
8805                 (void *)&cmd_vf_rate_limit_q_msk_val,
8806                 NULL,
8807         },
8808 };
8809
8810 /* *** ADD TUNNEL FILTER OF A PORT *** */
8811 struct cmd_tunnel_filter_result {
8812         cmdline_fixed_string_t cmd;
8813         cmdline_fixed_string_t what;
8814         portid_t port_id;
8815         struct rte_ether_addr outer_mac;
8816         struct rte_ether_addr inner_mac;
8817         cmdline_ipaddr_t ip_value;
8818         uint16_t inner_vlan;
8819         cmdline_fixed_string_t tunnel_type;
8820         cmdline_fixed_string_t filter_type;
8821         uint32_t tenant_id;
8822         uint16_t queue_num;
8823 };
8824
8825 static void
8826 cmd_tunnel_filter_parsed(void *parsed_result,
8827                           __attribute__((unused)) struct cmdline *cl,
8828                           __attribute__((unused)) void *data)
8829 {
8830         struct cmd_tunnel_filter_result *res = parsed_result;
8831         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8832         int ret = 0;
8833
8834         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8835
8836         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8837         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8838         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8839
8840         if (res->ip_value.family == AF_INET) {
8841                 tunnel_filter_conf.ip_addr.ipv4_addr =
8842                         res->ip_value.addr.ipv4.s_addr;
8843                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8844         } else {
8845                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8846                         &(res->ip_value.addr.ipv6),
8847                         sizeof(struct in6_addr));
8848                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8849         }
8850
8851         if (!strcmp(res->filter_type, "imac-ivlan"))
8852                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8853         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8854                 tunnel_filter_conf.filter_type =
8855                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8856         else if (!strcmp(res->filter_type, "imac-tenid"))
8857                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8858         else if (!strcmp(res->filter_type, "imac"))
8859                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8860         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8861                 tunnel_filter_conf.filter_type =
8862                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8863         else if (!strcmp(res->filter_type, "oip"))
8864                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8865         else if (!strcmp(res->filter_type, "iip"))
8866                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8867         else {
8868                 printf("The filter type is not supported");
8869                 return;
8870         }
8871
8872         if (!strcmp(res->tunnel_type, "vxlan"))
8873                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8874         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8875                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8876         else if (!strcmp(res->tunnel_type, "nvgre"))
8877                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8878         else if (!strcmp(res->tunnel_type, "ipingre"))
8879                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8880         else {
8881                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8882                 return;
8883         }
8884
8885         tunnel_filter_conf.tenant_id = res->tenant_id;
8886         tunnel_filter_conf.queue_id = res->queue_num;
8887         if (!strcmp(res->what, "add"))
8888                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8889                                         RTE_ETH_FILTER_TUNNEL,
8890                                         RTE_ETH_FILTER_ADD,
8891                                         &tunnel_filter_conf);
8892         else
8893                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8894                                         RTE_ETH_FILTER_TUNNEL,
8895                                         RTE_ETH_FILTER_DELETE,
8896                                         &tunnel_filter_conf);
8897         if (ret < 0)
8898                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8899                                 strerror(-ret));
8900
8901 }
8902 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8903         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8904         cmd, "tunnel_filter");
8905 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8906         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8907         what, "add#rm");
8908 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8909         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8910         port_id, UINT16);
8911 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8912         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8913         outer_mac);
8914 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8915         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8916         inner_mac);
8917 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8918         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8919         inner_vlan, UINT16);
8920 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8921         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8922         ip_value);
8923 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8924         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8925         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8926
8927 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8928         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8929         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8930                 "imac#omac-imac-tenid");
8931 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8932         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8933         tenant_id, UINT32);
8934 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8935         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8936         queue_num, UINT16);
8937
8938 cmdline_parse_inst_t cmd_tunnel_filter = {
8939         .f = cmd_tunnel_filter_parsed,
8940         .data = (void *)0,
8941         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8942                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8943                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8944                 "<queue_id>: Add/Rm tunnel filter of a port",
8945         .tokens = {
8946                 (void *)&cmd_tunnel_filter_cmd,
8947                 (void *)&cmd_tunnel_filter_what,
8948                 (void *)&cmd_tunnel_filter_port_id,
8949                 (void *)&cmd_tunnel_filter_outer_mac,
8950                 (void *)&cmd_tunnel_filter_inner_mac,
8951                 (void *)&cmd_tunnel_filter_ip_value,
8952                 (void *)&cmd_tunnel_filter_innner_vlan,
8953                 (void *)&cmd_tunnel_filter_tunnel_type,
8954                 (void *)&cmd_tunnel_filter_filter_type,
8955                 (void *)&cmd_tunnel_filter_tenant_id,
8956                 (void *)&cmd_tunnel_filter_queue_num,
8957                 NULL,
8958         },
8959 };
8960
8961 /* *** CONFIGURE TUNNEL UDP PORT *** */
8962 struct cmd_tunnel_udp_config {
8963         cmdline_fixed_string_t cmd;
8964         cmdline_fixed_string_t what;
8965         uint16_t udp_port;
8966         portid_t port_id;
8967 };
8968
8969 static void
8970 cmd_tunnel_udp_config_parsed(void *parsed_result,
8971                           __attribute__((unused)) struct cmdline *cl,
8972                           __attribute__((unused)) void *data)
8973 {
8974         struct cmd_tunnel_udp_config *res = parsed_result;
8975         struct rte_eth_udp_tunnel tunnel_udp;
8976         int ret;
8977
8978         tunnel_udp.udp_port = res->udp_port;
8979
8980         if (!strcmp(res->cmd, "rx_vxlan_port"))
8981                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8982
8983         if (!strcmp(res->what, "add"))
8984                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8985                                                       &tunnel_udp);
8986         else
8987                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8988                                                          &tunnel_udp);
8989
8990         if (ret < 0)
8991                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8992 }
8993
8994 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8995         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8996                                 cmd, "rx_vxlan_port");
8997 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8998         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8999                                 what, "add#rm");
9000 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9001         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9002                                 udp_port, UINT16);
9003 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9004         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9005                                 port_id, UINT16);
9006
9007 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9008         .f = cmd_tunnel_udp_config_parsed,
9009         .data = (void *)0,
9010         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9011                 "Add/Remove a tunneling UDP port filter",
9012         .tokens = {
9013                 (void *)&cmd_tunnel_udp_config_cmd,
9014                 (void *)&cmd_tunnel_udp_config_what,
9015                 (void *)&cmd_tunnel_udp_config_udp_port,
9016                 (void *)&cmd_tunnel_udp_config_port_id,
9017                 NULL,
9018         },
9019 };
9020
9021 struct cmd_config_tunnel_udp_port {
9022         cmdline_fixed_string_t port;
9023         cmdline_fixed_string_t config;
9024         portid_t port_id;
9025         cmdline_fixed_string_t udp_tunnel_port;
9026         cmdline_fixed_string_t action;
9027         cmdline_fixed_string_t tunnel_type;
9028         uint16_t udp_port;
9029 };
9030
9031 static void
9032 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9033                                __attribute__((unused)) struct cmdline *cl,
9034                                __attribute__((unused)) void *data)
9035 {
9036         struct cmd_config_tunnel_udp_port *res = parsed_result;
9037         struct rte_eth_udp_tunnel tunnel_udp;
9038         int ret = 0;
9039
9040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9041                 return;
9042
9043         tunnel_udp.udp_port = res->udp_port;
9044
9045         if (!strcmp(res->tunnel_type, "vxlan")) {
9046                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9047         } else if (!strcmp(res->tunnel_type, "geneve")) {
9048                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9049         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9050                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9051         } else {
9052                 printf("Invalid tunnel type\n");
9053                 return;
9054         }
9055
9056         if (!strcmp(res->action, "add"))
9057                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9058                                                       &tunnel_udp);
9059         else
9060                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9061                                                          &tunnel_udp);
9062
9063         if (ret < 0)
9064                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9065 }
9066
9067 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9068         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9069                                  "port");
9070 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9071         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9072                                  "config");
9073 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9074         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9075                               UINT16);
9076 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9077         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9078                                  udp_tunnel_port,
9079                                  "udp_tunnel_port");
9080 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9081         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9082                                  "add#rm");
9083 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9084         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9085                                  "vxlan#geneve#vxlan-gpe");
9086 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9087         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9088                               UINT16);
9089
9090 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9091         .f = cmd_cfg_tunnel_udp_port_parsed,
9092         .data = NULL,
9093         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9094         .tokens = {
9095                 (void *)&cmd_config_tunnel_udp_port_port,
9096                 (void *)&cmd_config_tunnel_udp_port_config,
9097                 (void *)&cmd_config_tunnel_udp_port_port_id,
9098                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9099                 (void *)&cmd_config_tunnel_udp_port_action,
9100                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9101                 (void *)&cmd_config_tunnel_udp_port_value,
9102                 NULL,
9103         },
9104 };
9105
9106 /* *** GLOBAL CONFIG *** */
9107 struct cmd_global_config_result {
9108         cmdline_fixed_string_t cmd;
9109         portid_t port_id;
9110         cmdline_fixed_string_t cfg_type;
9111         uint8_t len;
9112 };
9113
9114 static void
9115 cmd_global_config_parsed(void *parsed_result,
9116                          __attribute__((unused)) struct cmdline *cl,
9117                          __attribute__((unused)) void *data)
9118 {
9119         struct cmd_global_config_result *res = parsed_result;
9120         struct rte_eth_global_cfg conf;
9121         int ret;
9122
9123         memset(&conf, 0, sizeof(conf));
9124         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9125         conf.cfg.gre_key_len = res->len;
9126         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9127                                       RTE_ETH_FILTER_SET, &conf);
9128         if (ret != 0)
9129                 printf("Global config error\n");
9130 }
9131
9132 cmdline_parse_token_string_t cmd_global_config_cmd =
9133         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9134                 "global_config");
9135 cmdline_parse_token_num_t cmd_global_config_port_id =
9136         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9137                                UINT16);
9138 cmdline_parse_token_string_t cmd_global_config_type =
9139         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9140                 cfg_type, "gre-key-len");
9141 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9142         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9143                 len, UINT8);
9144
9145 cmdline_parse_inst_t cmd_global_config = {
9146         .f = cmd_global_config_parsed,
9147         .data = (void *)NULL,
9148         .help_str = "global_config <port_id> gre-key-len <key_len>",
9149         .tokens = {
9150                 (void *)&cmd_global_config_cmd,
9151                 (void *)&cmd_global_config_port_id,
9152                 (void *)&cmd_global_config_type,
9153                 (void *)&cmd_global_config_gre_key_len,
9154                 NULL,
9155         },
9156 };
9157
9158 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9159 struct cmd_set_mirror_mask_result {
9160         cmdline_fixed_string_t set;
9161         cmdline_fixed_string_t port;
9162         portid_t port_id;
9163         cmdline_fixed_string_t mirror;
9164         uint8_t rule_id;
9165         cmdline_fixed_string_t what;
9166         cmdline_fixed_string_t value;
9167         cmdline_fixed_string_t dstpool;
9168         uint8_t dstpool_id;
9169         cmdline_fixed_string_t on;
9170 };
9171
9172 cmdline_parse_token_string_t cmd_mirror_mask_set =
9173         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9174                                 set, "set");
9175 cmdline_parse_token_string_t cmd_mirror_mask_port =
9176         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9177                                 port, "port");
9178 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9179         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9180                                 port_id, UINT16);
9181 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9182         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9183                                 mirror, "mirror-rule");
9184 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9185         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9186                                 rule_id, UINT8);
9187 cmdline_parse_token_string_t cmd_mirror_mask_what =
9188         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9189                                 what, "pool-mirror-up#pool-mirror-down"
9190                                       "#vlan-mirror");
9191 cmdline_parse_token_string_t cmd_mirror_mask_value =
9192         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9193                                 value, NULL);
9194 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9195         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9196                                 dstpool, "dst-pool");
9197 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9198         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9199                                 dstpool_id, UINT8);
9200 cmdline_parse_token_string_t cmd_mirror_mask_on =
9201         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9202                                 on, "on#off");
9203
9204 static void
9205 cmd_set_mirror_mask_parsed(void *parsed_result,
9206                        __attribute__((unused)) struct cmdline *cl,
9207                        __attribute__((unused)) void *data)
9208 {
9209         int ret,nb_item,i;
9210         struct cmd_set_mirror_mask_result *res = parsed_result;
9211         struct rte_eth_mirror_conf mr_conf;
9212
9213         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9214
9215         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9216
9217         mr_conf.dst_pool = res->dstpool_id;
9218
9219         if (!strcmp(res->what, "pool-mirror-up")) {
9220                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9221                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9222         } else if (!strcmp(res->what, "pool-mirror-down")) {
9223                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9224                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9225         } else if (!strcmp(res->what, "vlan-mirror")) {
9226                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9227                 nb_item = parse_item_list(res->value, "vlan",
9228                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9229                 if (nb_item <= 0)
9230                         return;
9231
9232                 for (i = 0; i < nb_item; i++) {
9233                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9234                                 printf("Invalid vlan_id: must be < 4096\n");
9235                                 return;
9236                         }
9237
9238                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9239                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9240                 }
9241         }
9242
9243         if (!strcmp(res->on, "on"))
9244                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9245                                                 res->rule_id, 1);
9246         else
9247                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9248                                                 res->rule_id, 0);
9249         if (ret < 0)
9250                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9251 }
9252
9253 cmdline_parse_inst_t cmd_set_mirror_mask = {
9254                 .f = cmd_set_mirror_mask_parsed,
9255                 .data = NULL,
9256                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9257                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9258                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9259                 .tokens = {
9260                         (void *)&cmd_mirror_mask_set,
9261                         (void *)&cmd_mirror_mask_port,
9262                         (void *)&cmd_mirror_mask_portid,
9263                         (void *)&cmd_mirror_mask_mirror,
9264                         (void *)&cmd_mirror_mask_ruleid,
9265                         (void *)&cmd_mirror_mask_what,
9266                         (void *)&cmd_mirror_mask_value,
9267                         (void *)&cmd_mirror_mask_dstpool,
9268                         (void *)&cmd_mirror_mask_poolid,
9269                         (void *)&cmd_mirror_mask_on,
9270                         NULL,
9271                 },
9272 };
9273
9274 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9275 struct cmd_set_mirror_link_result {
9276         cmdline_fixed_string_t set;
9277         cmdline_fixed_string_t port;
9278         portid_t port_id;
9279         cmdline_fixed_string_t mirror;
9280         uint8_t rule_id;
9281         cmdline_fixed_string_t what;
9282         cmdline_fixed_string_t dstpool;
9283         uint8_t dstpool_id;
9284         cmdline_fixed_string_t on;
9285 };
9286
9287 cmdline_parse_token_string_t cmd_mirror_link_set =
9288         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9289                                  set, "set");
9290 cmdline_parse_token_string_t cmd_mirror_link_port =
9291         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9292                                 port, "port");
9293 cmdline_parse_token_num_t cmd_mirror_link_portid =
9294         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9295                                 port_id, UINT16);
9296 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9297         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9298                                 mirror, "mirror-rule");
9299 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9300         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9301                             rule_id, UINT8);
9302 cmdline_parse_token_string_t cmd_mirror_link_what =
9303         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9304                                 what, "uplink-mirror#downlink-mirror");
9305 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9306         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9307                                 dstpool, "dst-pool");
9308 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9309         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9310                                 dstpool_id, UINT8);
9311 cmdline_parse_token_string_t cmd_mirror_link_on =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9313                                 on, "on#off");
9314
9315 static void
9316 cmd_set_mirror_link_parsed(void *parsed_result,
9317                        __attribute__((unused)) struct cmdline *cl,
9318                        __attribute__((unused)) void *data)
9319 {
9320         int ret;
9321         struct cmd_set_mirror_link_result *res = parsed_result;
9322         struct rte_eth_mirror_conf mr_conf;
9323
9324         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9325         if (!strcmp(res->what, "uplink-mirror"))
9326                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9327         else
9328                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9329
9330         mr_conf.dst_pool = res->dstpool_id;
9331
9332         if (!strcmp(res->on, "on"))
9333                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9334                                                 res->rule_id, 1);
9335         else
9336                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9337                                                 res->rule_id, 0);
9338
9339         /* check the return value and print it if is < 0 */
9340         if (ret < 0)
9341                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9342
9343 }
9344
9345 cmdline_parse_inst_t cmd_set_mirror_link = {
9346                 .f = cmd_set_mirror_link_parsed,
9347                 .data = NULL,
9348                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9349                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9350                 .tokens = {
9351                         (void *)&cmd_mirror_link_set,
9352                         (void *)&cmd_mirror_link_port,
9353                         (void *)&cmd_mirror_link_portid,
9354                         (void *)&cmd_mirror_link_mirror,
9355                         (void *)&cmd_mirror_link_ruleid,
9356                         (void *)&cmd_mirror_link_what,
9357                         (void *)&cmd_mirror_link_dstpool,
9358                         (void *)&cmd_mirror_link_poolid,
9359                         (void *)&cmd_mirror_link_on,
9360                         NULL,
9361                 },
9362 };
9363
9364 /* *** RESET VM MIRROR RULE *** */
9365 struct cmd_rm_mirror_rule_result {
9366         cmdline_fixed_string_t reset;
9367         cmdline_fixed_string_t port;
9368         portid_t port_id;
9369         cmdline_fixed_string_t mirror;
9370         uint8_t rule_id;
9371 };
9372
9373 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9374         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9375                                  reset, "reset");
9376 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9377         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9378                                 port, "port");
9379 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9380         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9381                                 port_id, UINT16);
9382 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9383         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9384                                 mirror, "mirror-rule");
9385 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9386         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9387                                 rule_id, UINT8);
9388
9389 static void
9390 cmd_reset_mirror_rule_parsed(void *parsed_result,
9391                        __attribute__((unused)) struct cmdline *cl,
9392                        __attribute__((unused)) void *data)
9393 {
9394         int ret;
9395         struct cmd_set_mirror_link_result *res = parsed_result;
9396         /* check rule_id */
9397         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9398         if(ret < 0)
9399                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9400 }
9401
9402 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9403                 .f = cmd_reset_mirror_rule_parsed,
9404                 .data = NULL,
9405                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9406                 .tokens = {
9407                         (void *)&cmd_rm_mirror_rule_reset,
9408                         (void *)&cmd_rm_mirror_rule_port,
9409                         (void *)&cmd_rm_mirror_rule_portid,
9410                         (void *)&cmd_rm_mirror_rule_mirror,
9411                         (void *)&cmd_rm_mirror_rule_ruleid,
9412                         NULL,
9413                 },
9414 };
9415
9416 /* ******************************************************************************** */
9417
9418 struct cmd_dump_result {
9419         cmdline_fixed_string_t dump;
9420 };
9421
9422 static void
9423 dump_struct_sizes(void)
9424 {
9425 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9426         DUMP_SIZE(struct rte_mbuf);
9427         DUMP_SIZE(struct rte_mempool);
9428         DUMP_SIZE(struct rte_ring);
9429 #undef DUMP_SIZE
9430 }
9431
9432 static void cmd_dump_parsed(void *parsed_result,
9433                             __attribute__((unused)) struct cmdline *cl,
9434                             __attribute__((unused)) void *data)
9435 {
9436         struct cmd_dump_result *res = parsed_result;
9437
9438         if (!strcmp(res->dump, "dump_physmem"))
9439                 rte_dump_physmem_layout(stdout);
9440         else if (!strcmp(res->dump, "dump_memzone"))
9441                 rte_memzone_dump(stdout);
9442         else if (!strcmp(res->dump, "dump_struct_sizes"))
9443                 dump_struct_sizes();
9444         else if (!strcmp(res->dump, "dump_ring"))
9445                 rte_ring_list_dump(stdout);
9446         else if (!strcmp(res->dump, "dump_mempool"))
9447                 rte_mempool_list_dump(stdout);
9448         else if (!strcmp(res->dump, "dump_devargs"))
9449                 rte_devargs_dump(stdout);
9450         else if (!strcmp(res->dump, "dump_log_types"))
9451                 rte_log_dump(stdout);
9452 }
9453
9454 cmdline_parse_token_string_t cmd_dump_dump =
9455         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9456                 "dump_physmem#"
9457                 "dump_memzone#"
9458                 "dump_struct_sizes#"
9459                 "dump_ring#"
9460                 "dump_mempool#"
9461                 "dump_devargs#"
9462                 "dump_log_types");
9463
9464 cmdline_parse_inst_t cmd_dump = {
9465         .f = cmd_dump_parsed,  /* function to call */
9466         .data = NULL,      /* 2nd arg of func */
9467         .help_str = "Dump status",
9468         .tokens = {        /* token list, NULL terminated */
9469                 (void *)&cmd_dump_dump,
9470                 NULL,
9471         },
9472 };
9473
9474 /* ******************************************************************************** */
9475
9476 struct cmd_dump_one_result {
9477         cmdline_fixed_string_t dump;
9478         cmdline_fixed_string_t name;
9479 };
9480
9481 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9482                                 __attribute__((unused)) void *data)
9483 {
9484         struct cmd_dump_one_result *res = parsed_result;
9485
9486         if (!strcmp(res->dump, "dump_ring")) {
9487                 struct rte_ring *r;
9488                 r = rte_ring_lookup(res->name);
9489                 if (r == NULL) {
9490                         cmdline_printf(cl, "Cannot find ring\n");
9491                         return;
9492                 }
9493                 rte_ring_dump(stdout, r);
9494         } else if (!strcmp(res->dump, "dump_mempool")) {
9495                 struct rte_mempool *mp;
9496                 mp = rte_mempool_lookup(res->name);
9497                 if (mp == NULL) {
9498                         cmdline_printf(cl, "Cannot find mempool\n");
9499                         return;
9500                 }
9501                 rte_mempool_dump(stdout, mp);
9502         }
9503 }
9504
9505 cmdline_parse_token_string_t cmd_dump_one_dump =
9506         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9507                                  "dump_ring#dump_mempool");
9508
9509 cmdline_parse_token_string_t cmd_dump_one_name =
9510         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9511
9512 cmdline_parse_inst_t cmd_dump_one = {
9513         .f = cmd_dump_one_parsed,  /* function to call */
9514         .data = NULL,      /* 2nd arg of func */
9515         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9516         .tokens = {        /* token list, NULL terminated */
9517                 (void *)&cmd_dump_one_dump,
9518                 (void *)&cmd_dump_one_name,
9519                 NULL,
9520         },
9521 };
9522
9523 /* *** Add/Del syn filter *** */
9524 struct cmd_syn_filter_result {
9525         cmdline_fixed_string_t filter;
9526         portid_t port_id;
9527         cmdline_fixed_string_t ops;
9528         cmdline_fixed_string_t priority;
9529         cmdline_fixed_string_t high;
9530         cmdline_fixed_string_t queue;
9531         uint16_t queue_id;
9532 };
9533
9534 static void
9535 cmd_syn_filter_parsed(void *parsed_result,
9536                         __attribute__((unused)) struct cmdline *cl,
9537                         __attribute__((unused)) void *data)
9538 {
9539         struct cmd_syn_filter_result *res = parsed_result;
9540         struct rte_eth_syn_filter syn_filter;
9541         int ret = 0;
9542
9543         ret = rte_eth_dev_filter_supported(res->port_id,
9544                                         RTE_ETH_FILTER_SYN);
9545         if (ret < 0) {
9546                 printf("syn filter is not supported on port %u.\n",
9547                                 res->port_id);
9548                 return;
9549         }
9550
9551         memset(&syn_filter, 0, sizeof(syn_filter));
9552
9553         if (!strcmp(res->ops, "add")) {
9554                 if (!strcmp(res->high, "high"))
9555                         syn_filter.hig_pri = 1;
9556                 else
9557                         syn_filter.hig_pri = 0;
9558
9559                 syn_filter.queue = res->queue_id;
9560                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9561                                                 RTE_ETH_FILTER_SYN,
9562                                                 RTE_ETH_FILTER_ADD,
9563                                                 &syn_filter);
9564         } else
9565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9566                                                 RTE_ETH_FILTER_SYN,
9567                                                 RTE_ETH_FILTER_DELETE,
9568                                                 &syn_filter);
9569
9570         if (ret < 0)
9571                 printf("syn filter programming error: (%s)\n",
9572                                 strerror(-ret));
9573 }
9574
9575 cmdline_parse_token_string_t cmd_syn_filter_filter =
9576         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9577         filter, "syn_filter");
9578 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9579         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9580         port_id, UINT16);
9581 cmdline_parse_token_string_t cmd_syn_filter_ops =
9582         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9583         ops, "add#del");
9584 cmdline_parse_token_string_t cmd_syn_filter_priority =
9585         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9586                                 priority, "priority");
9587 cmdline_parse_token_string_t cmd_syn_filter_high =
9588         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9589                                 high, "high#low");
9590 cmdline_parse_token_string_t cmd_syn_filter_queue =
9591         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9592                                 queue, "queue");
9593 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9594         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9595                                 queue_id, UINT16);
9596
9597 cmdline_parse_inst_t cmd_syn_filter = {
9598         .f = cmd_syn_filter_parsed,
9599         .data = NULL,
9600         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9601                 "<queue_id>: Add/Delete syn filter",
9602         .tokens = {
9603                 (void *)&cmd_syn_filter_filter,
9604                 (void *)&cmd_syn_filter_port_id,
9605                 (void *)&cmd_syn_filter_ops,
9606                 (void *)&cmd_syn_filter_priority,
9607                 (void *)&cmd_syn_filter_high,
9608                 (void *)&cmd_syn_filter_queue,
9609                 (void *)&cmd_syn_filter_queue_id,
9610                 NULL,
9611         },
9612 };
9613
9614 /* *** queue region set *** */
9615 struct cmd_queue_region_result {
9616         cmdline_fixed_string_t set;
9617         cmdline_fixed_string_t port;
9618         portid_t port_id;
9619         cmdline_fixed_string_t cmd;
9620         cmdline_fixed_string_t region;
9621         uint8_t  region_id;
9622         cmdline_fixed_string_t queue_start_index;
9623         uint8_t  queue_id;
9624         cmdline_fixed_string_t queue_num;
9625         uint8_t  queue_num_value;
9626 };
9627
9628 static void
9629 cmd_queue_region_parsed(void *parsed_result,
9630                         __attribute__((unused)) struct cmdline *cl,
9631                         __attribute__((unused)) void *data)
9632 {
9633         struct cmd_queue_region_result *res = parsed_result;
9634         int ret = -ENOTSUP;
9635 #ifdef RTE_LIBRTE_I40E_PMD
9636         struct rte_pmd_i40e_queue_region_conf region_conf;
9637         enum rte_pmd_i40e_queue_region_op op_type;
9638 #endif
9639
9640         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9641                 return;
9642
9643 #ifdef RTE_LIBRTE_I40E_PMD
9644         memset(&region_conf, 0, sizeof(region_conf));
9645         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9646         region_conf.region_id = res->region_id;
9647         region_conf.queue_num = res->queue_num_value;
9648         region_conf.queue_start_index = res->queue_id;
9649
9650         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9651                                 op_type, &region_conf);
9652 #endif
9653
9654         switch (ret) {
9655         case 0:
9656                 break;
9657         case -ENOTSUP:
9658                 printf("function not implemented or supported\n");
9659                 break;
9660         default:
9661                 printf("queue region config error: (%s)\n", strerror(-ret));
9662         }
9663 }
9664
9665 cmdline_parse_token_string_t cmd_queue_region_set =
9666 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9667                 set, "set");
9668 cmdline_parse_token_string_t cmd_queue_region_port =
9669         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9670 cmdline_parse_token_num_t cmd_queue_region_port_id =
9671         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9672                                 port_id, UINT16);
9673 cmdline_parse_token_string_t cmd_queue_region_cmd =
9674         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9675                                  cmd, "queue-region");
9676 cmdline_parse_token_string_t cmd_queue_region_id =
9677         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9678                                 region, "region_id");
9679 cmdline_parse_token_num_t cmd_queue_region_index =
9680         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9681                                 region_id, UINT8);
9682 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9683         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9684                                 queue_start_index, "queue_start_index");
9685 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9686         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9687                                 queue_id, UINT8);
9688 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9689         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9690                                 queue_num, "queue_num");
9691 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9692         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9693                                 queue_num_value, UINT8);
9694
9695 cmdline_parse_inst_t cmd_queue_region = {
9696         .f = cmd_queue_region_parsed,
9697         .data = NULL,
9698         .help_str = "set port <port_id> queue-region region_id <value> "
9699                 "queue_start_index <value> queue_num <value>: Set a queue region",
9700         .tokens = {
9701                 (void *)&cmd_queue_region_set,
9702                 (void *)&cmd_queue_region_port,
9703                 (void *)&cmd_queue_region_port_id,
9704                 (void *)&cmd_queue_region_cmd,
9705                 (void *)&cmd_queue_region_id,
9706                 (void *)&cmd_queue_region_index,
9707                 (void *)&cmd_queue_region_queue_start_index,
9708                 (void *)&cmd_queue_region_queue_id,
9709                 (void *)&cmd_queue_region_queue_num,
9710                 (void *)&cmd_queue_region_queue_num_value,
9711                 NULL,
9712         },
9713 };
9714
9715 /* *** queue region and flowtype set *** */
9716 struct cmd_region_flowtype_result {
9717         cmdline_fixed_string_t set;
9718         cmdline_fixed_string_t port;
9719         portid_t port_id;
9720         cmdline_fixed_string_t cmd;
9721         cmdline_fixed_string_t region;
9722         uint8_t  region_id;
9723         cmdline_fixed_string_t flowtype;
9724         uint8_t  flowtype_id;
9725 };
9726
9727 static void
9728 cmd_region_flowtype_parsed(void *parsed_result,
9729                         __attribute__((unused)) struct cmdline *cl,
9730                         __attribute__((unused)) void *data)
9731 {
9732         struct cmd_region_flowtype_result *res = parsed_result;
9733         int ret = -ENOTSUP;
9734 #ifdef RTE_LIBRTE_I40E_PMD
9735         struct rte_pmd_i40e_queue_region_conf region_conf;
9736         enum rte_pmd_i40e_queue_region_op op_type;
9737 #endif
9738
9739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9740                 return;
9741
9742 #ifdef RTE_LIBRTE_I40E_PMD
9743         memset(&region_conf, 0, sizeof(region_conf));
9744
9745         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9746         region_conf.region_id = res->region_id;
9747         region_conf.hw_flowtype = res->flowtype_id;
9748
9749         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9750                         op_type, &region_conf);
9751 #endif
9752
9753         switch (ret) {
9754         case 0:
9755                 break;
9756         case -ENOTSUP:
9757                 printf("function not implemented or supported\n");
9758                 break;
9759         default:
9760                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9761         }
9762 }
9763
9764 cmdline_parse_token_string_t cmd_region_flowtype_set =
9765 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9766                                 set, "set");
9767 cmdline_parse_token_string_t cmd_region_flowtype_port =
9768         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9769                                 port, "port");
9770 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9771         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9772                                 port_id, UINT16);
9773 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9774         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9775                                 cmd, "queue-region");
9776 cmdline_parse_token_string_t cmd_region_flowtype_index =
9777         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9778                                 region, "region_id");
9779 cmdline_parse_token_num_t cmd_region_flowtype_id =
9780         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9781                                 region_id, UINT8);
9782 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9783         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9784                                 flowtype, "flowtype");
9785 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9786         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9787                                 flowtype_id, UINT8);
9788 cmdline_parse_inst_t cmd_region_flowtype = {
9789         .f = cmd_region_flowtype_parsed,
9790         .data = NULL,
9791         .help_str = "set port <port_id> queue-region region_id <value> "
9792                 "flowtype <value>: Set a flowtype region index",
9793         .tokens = {
9794                 (void *)&cmd_region_flowtype_set,
9795                 (void *)&cmd_region_flowtype_port,
9796                 (void *)&cmd_region_flowtype_port_index,
9797                 (void *)&cmd_region_flowtype_cmd,
9798                 (void *)&cmd_region_flowtype_index,
9799                 (void *)&cmd_region_flowtype_id,
9800                 (void *)&cmd_region_flowtype_flow_index,
9801                 (void *)&cmd_region_flowtype_flow_id,
9802                 NULL,
9803         },
9804 };
9805
9806 /* *** User Priority (UP) to queue region (region_id) set *** */
9807 struct cmd_user_priority_region_result {
9808         cmdline_fixed_string_t set;
9809         cmdline_fixed_string_t port;
9810         portid_t port_id;
9811         cmdline_fixed_string_t cmd;
9812         cmdline_fixed_string_t user_priority;
9813         uint8_t  user_priority_id;
9814         cmdline_fixed_string_t region;
9815         uint8_t  region_id;
9816 };
9817
9818 static void
9819 cmd_user_priority_region_parsed(void *parsed_result,
9820                         __attribute__((unused)) struct cmdline *cl,
9821                         __attribute__((unused)) void *data)
9822 {
9823         struct cmd_user_priority_region_result *res = parsed_result;
9824         int ret = -ENOTSUP;
9825 #ifdef RTE_LIBRTE_I40E_PMD
9826         struct rte_pmd_i40e_queue_region_conf region_conf;
9827         enum rte_pmd_i40e_queue_region_op op_type;
9828 #endif
9829
9830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9831                 return;
9832
9833 #ifdef RTE_LIBRTE_I40E_PMD
9834         memset(&region_conf, 0, sizeof(region_conf));
9835         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9836         region_conf.user_priority = res->user_priority_id;
9837         region_conf.region_id = res->region_id;
9838
9839         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9840                                 op_type, &region_conf);
9841 #endif
9842
9843         switch (ret) {
9844         case 0:
9845                 break;
9846         case -ENOTSUP:
9847                 printf("function not implemented or supported\n");
9848                 break;
9849         default:
9850                 printf("user_priority region config error: (%s)\n",
9851                                 strerror(-ret));
9852         }
9853 }
9854
9855 cmdline_parse_token_string_t cmd_user_priority_region_set =
9856         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9857                                 set, "set");
9858 cmdline_parse_token_string_t cmd_user_priority_region_port =
9859         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9860                                 port, "port");
9861 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9862         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9863                                 port_id, UINT16);
9864 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9865         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9866                                 cmd, "queue-region");
9867 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9868         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9869                                 user_priority, "UP");
9870 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9871         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9872                                 user_priority_id, UINT8);
9873 cmdline_parse_token_string_t cmd_user_priority_region_region =
9874         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9875                                 region, "region_id");
9876 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9877         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9878                                 region_id, UINT8);
9879
9880 cmdline_parse_inst_t cmd_user_priority_region = {
9881         .f = cmd_user_priority_region_parsed,
9882         .data = NULL,
9883         .help_str = "set port <port_id> queue-region UP <value> "
9884                 "region_id <value>: Set the mapping of User Priority (UP) "
9885                 "to queue region (region_id) ",
9886         .tokens = {
9887                 (void *)&cmd_user_priority_region_set,
9888                 (void *)&cmd_user_priority_region_port,
9889                 (void *)&cmd_user_priority_region_port_index,
9890                 (void *)&cmd_user_priority_region_cmd,
9891                 (void *)&cmd_user_priority_region_UP,
9892                 (void *)&cmd_user_priority_region_UP_id,
9893                 (void *)&cmd_user_priority_region_region,
9894                 (void *)&cmd_user_priority_region_region_id,
9895                 NULL,
9896         },
9897 };
9898
9899 /* *** flush all queue region related configuration *** */
9900 struct cmd_flush_queue_region_result {
9901         cmdline_fixed_string_t set;
9902         cmdline_fixed_string_t port;
9903         portid_t port_id;
9904         cmdline_fixed_string_t cmd;
9905         cmdline_fixed_string_t flush;
9906         cmdline_fixed_string_t what;
9907 };
9908
9909 static void
9910 cmd_flush_queue_region_parsed(void *parsed_result,
9911                         __attribute__((unused)) struct cmdline *cl,
9912                         __attribute__((unused)) void *data)
9913 {
9914         struct cmd_flush_queue_region_result *res = parsed_result;
9915         int ret = -ENOTSUP;
9916 #ifdef RTE_LIBRTE_I40E_PMD
9917         struct rte_pmd_i40e_queue_region_conf region_conf;
9918         enum rte_pmd_i40e_queue_region_op op_type;
9919 #endif
9920
9921         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9922                 return;
9923
9924 #ifdef RTE_LIBRTE_I40E_PMD
9925         memset(&region_conf, 0, sizeof(region_conf));
9926
9927         if (strcmp(res->what, "on") == 0)
9928                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9929         else
9930                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9931
9932         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9933                                 op_type, &region_conf);
9934 #endif
9935
9936         switch (ret) {
9937         case 0:
9938                 break;
9939         case -ENOTSUP:
9940                 printf("function not implemented or supported\n");
9941                 break;
9942         default:
9943                 printf("queue region config flush error: (%s)\n",
9944                                 strerror(-ret));
9945         }
9946 }
9947
9948 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9949         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9950                                 set, "set");
9951 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9952         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9953                                 port, "port");
9954 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9955         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9956                                 port_id, UINT16);
9957 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9958         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9959                                 cmd, "queue-region");
9960 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9961         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9962                                 flush, "flush");
9963 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9964         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9965                                 what, "on#off");
9966
9967 cmdline_parse_inst_t cmd_flush_queue_region = {
9968         .f = cmd_flush_queue_region_parsed,
9969         .data = NULL,
9970         .help_str = "set port <port_id> queue-region flush on|off"
9971                 ": flush all queue region related configuration",
9972         .tokens = {
9973                 (void *)&cmd_flush_queue_region_set,
9974                 (void *)&cmd_flush_queue_region_port,
9975                 (void *)&cmd_flush_queue_region_port_index,
9976                 (void *)&cmd_flush_queue_region_cmd,
9977                 (void *)&cmd_flush_queue_region_flush,
9978                 (void *)&cmd_flush_queue_region_what,
9979                 NULL,
9980         },
9981 };
9982
9983 /* *** get all queue region related configuration info *** */
9984 struct cmd_show_queue_region_info {
9985         cmdline_fixed_string_t show;
9986         cmdline_fixed_string_t port;
9987         portid_t port_id;
9988         cmdline_fixed_string_t cmd;
9989 };
9990
9991 static void
9992 cmd_show_queue_region_info_parsed(void *parsed_result,
9993                         __attribute__((unused)) struct cmdline *cl,
9994                         __attribute__((unused)) void *data)
9995 {
9996         struct cmd_show_queue_region_info *res = parsed_result;
9997         int ret = -ENOTSUP;
9998 #ifdef RTE_LIBRTE_I40E_PMD
9999         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10000         enum rte_pmd_i40e_queue_region_op op_type;
10001 #endif
10002
10003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10004                 return;
10005
10006 #ifdef RTE_LIBRTE_I40E_PMD
10007         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10008
10009         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10010
10011         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10012                                         op_type, &rte_pmd_regions);
10013
10014         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10015 #endif
10016
10017         switch (ret) {
10018         case 0:
10019                 break;
10020         case -ENOTSUP:
10021                 printf("function not implemented or supported\n");
10022                 break;
10023         default:
10024                 printf("queue region config info show error: (%s)\n",
10025                                 strerror(-ret));
10026         }
10027 }
10028
10029 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10030 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10031                                 show, "show");
10032 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10033         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10034                                 port, "port");
10035 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10036         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10037                                 port_id, UINT16);
10038 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10039         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10040                                 cmd, "queue-region");
10041
10042 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10043         .f = cmd_show_queue_region_info_parsed,
10044         .data = NULL,
10045         .help_str = "show port <port_id> queue-region"
10046                 ": show all queue region related configuration info",
10047         .tokens = {
10048                 (void *)&cmd_show_queue_region_info_get,
10049                 (void *)&cmd_show_queue_region_info_port,
10050                 (void *)&cmd_show_queue_region_info_port_index,
10051                 (void *)&cmd_show_queue_region_info_cmd,
10052                 NULL,
10053         },
10054 };
10055
10056 /* *** ADD/REMOVE A 2tuple FILTER *** */
10057 struct cmd_2tuple_filter_result {
10058         cmdline_fixed_string_t filter;
10059         portid_t port_id;
10060         cmdline_fixed_string_t ops;
10061         cmdline_fixed_string_t dst_port;
10062         uint16_t dst_port_value;
10063         cmdline_fixed_string_t protocol;
10064         uint8_t protocol_value;
10065         cmdline_fixed_string_t mask;
10066         uint8_t  mask_value;
10067         cmdline_fixed_string_t tcp_flags;
10068         uint8_t tcp_flags_value;
10069         cmdline_fixed_string_t priority;
10070         uint8_t  priority_value;
10071         cmdline_fixed_string_t queue;
10072         uint16_t  queue_id;
10073 };
10074
10075 static void
10076 cmd_2tuple_filter_parsed(void *parsed_result,
10077                         __attribute__((unused)) struct cmdline *cl,
10078                         __attribute__((unused)) void *data)
10079 {
10080         struct rte_eth_ntuple_filter filter;
10081         struct cmd_2tuple_filter_result *res = parsed_result;
10082         int ret = 0;
10083
10084         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10085         if (ret < 0) {
10086                 printf("ntuple filter is not supported on port %u.\n",
10087                         res->port_id);
10088                 return;
10089         }
10090
10091         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10092
10093         filter.flags = RTE_2TUPLE_FLAGS;
10094         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10095         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10096         filter.proto = res->protocol_value;
10097         filter.priority = res->priority_value;
10098         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10099                 printf("nonzero tcp_flags is only meaningful"
10100                         " when protocol is TCP.\n");
10101                 return;
10102         }
10103         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10104                 printf("invalid TCP flags.\n");
10105                 return;
10106         }
10107
10108         if (res->tcp_flags_value != 0) {
10109                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10110                 filter.tcp_flags = res->tcp_flags_value;
10111         }
10112
10113         /* need convert to big endian. */
10114         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10115         filter.queue = res->queue_id;
10116
10117         if (!strcmp(res->ops, "add"))
10118                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10119                                 RTE_ETH_FILTER_NTUPLE,
10120                                 RTE_ETH_FILTER_ADD,
10121                                 &filter);
10122         else
10123                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10124                                 RTE_ETH_FILTER_NTUPLE,
10125                                 RTE_ETH_FILTER_DELETE,
10126                                 &filter);
10127         if (ret < 0)
10128                 printf("2tuple filter programming error: (%s)\n",
10129                         strerror(-ret));
10130
10131 }
10132
10133 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10134         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10135                                  filter, "2tuple_filter");
10136 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10137         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10138                                 port_id, UINT16);
10139 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10140         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10141                                  ops, "add#del");
10142 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10143         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10144                                 dst_port, "dst_port");
10145 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10146         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10147                                 dst_port_value, UINT16);
10148 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10149         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10150                                 protocol, "protocol");
10151 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10152         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10153                                 protocol_value, UINT8);
10154 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10155         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10156                                 mask, "mask");
10157 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10158         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10159                                 mask_value, INT8);
10160 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10161         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10162                                 tcp_flags, "tcp_flags");
10163 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10165                                 tcp_flags_value, UINT8);
10166 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10167         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10168                                 priority, "priority");
10169 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10170         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10171                                 priority_value, UINT8);
10172 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10174                                 queue, "queue");
10175 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10177                                 queue_id, UINT16);
10178
10179 cmdline_parse_inst_t cmd_2tuple_filter = {
10180         .f = cmd_2tuple_filter_parsed,
10181         .data = NULL,
10182         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10183                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10184                 "<queue_id>: Add a 2tuple filter",
10185         .tokens = {
10186                 (void *)&cmd_2tuple_filter_filter,
10187                 (void *)&cmd_2tuple_filter_port_id,
10188                 (void *)&cmd_2tuple_filter_ops,
10189                 (void *)&cmd_2tuple_filter_dst_port,
10190                 (void *)&cmd_2tuple_filter_dst_port_value,
10191                 (void *)&cmd_2tuple_filter_protocol,
10192                 (void *)&cmd_2tuple_filter_protocol_value,
10193                 (void *)&cmd_2tuple_filter_mask,
10194                 (void *)&cmd_2tuple_filter_mask_value,
10195                 (void *)&cmd_2tuple_filter_tcp_flags,
10196                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10197                 (void *)&cmd_2tuple_filter_priority,
10198                 (void *)&cmd_2tuple_filter_priority_value,
10199                 (void *)&cmd_2tuple_filter_queue,
10200                 (void *)&cmd_2tuple_filter_queue_id,
10201                 NULL,
10202         },
10203 };
10204
10205 /* *** ADD/REMOVE A 5tuple FILTER *** */
10206 struct cmd_5tuple_filter_result {
10207         cmdline_fixed_string_t filter;
10208         portid_t port_id;
10209         cmdline_fixed_string_t ops;
10210         cmdline_fixed_string_t dst_ip;
10211         cmdline_ipaddr_t dst_ip_value;
10212         cmdline_fixed_string_t src_ip;
10213         cmdline_ipaddr_t src_ip_value;
10214         cmdline_fixed_string_t dst_port;
10215         uint16_t dst_port_value;
10216         cmdline_fixed_string_t src_port;
10217         uint16_t src_port_value;
10218         cmdline_fixed_string_t protocol;
10219         uint8_t protocol_value;
10220         cmdline_fixed_string_t mask;
10221         uint8_t  mask_value;
10222         cmdline_fixed_string_t tcp_flags;
10223         uint8_t tcp_flags_value;
10224         cmdline_fixed_string_t priority;
10225         uint8_t  priority_value;
10226         cmdline_fixed_string_t queue;
10227         uint16_t  queue_id;
10228 };
10229
10230 static void
10231 cmd_5tuple_filter_parsed(void *parsed_result,
10232                         __attribute__((unused)) struct cmdline *cl,
10233                         __attribute__((unused)) void *data)
10234 {
10235         struct rte_eth_ntuple_filter filter;
10236         struct cmd_5tuple_filter_result *res = parsed_result;
10237         int ret = 0;
10238
10239         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10240         if (ret < 0) {
10241                 printf("ntuple filter is not supported on port %u.\n",
10242                         res->port_id);
10243                 return;
10244         }
10245
10246         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10247
10248         filter.flags = RTE_5TUPLE_FLAGS;
10249         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10250         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10251         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10252         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10253         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10254         filter.proto = res->protocol_value;
10255         filter.priority = res->priority_value;
10256         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10257                 printf("nonzero tcp_flags is only meaningful"
10258                         " when protocol is TCP.\n");
10259                 return;
10260         }
10261         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10262                 printf("invalid TCP flags.\n");
10263                 return;
10264         }
10265
10266         if (res->tcp_flags_value != 0) {
10267                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10268                 filter.tcp_flags = res->tcp_flags_value;
10269         }
10270
10271         if (res->dst_ip_value.family == AF_INET)
10272                 /* no need to convert, already big endian. */
10273                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10274         else {
10275                 if (filter.dst_ip_mask == 0) {
10276                         printf("can not support ipv6 involved compare.\n");
10277                         return;
10278                 }
10279                 filter.dst_ip = 0;
10280         }
10281
10282         if (res->src_ip_value.family == AF_INET)
10283                 /* no need to convert, already big endian. */
10284                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10285         else {
10286                 if (filter.src_ip_mask == 0) {
10287                         printf("can not support ipv6 involved compare.\n");
10288                         return;
10289                 }
10290                 filter.src_ip = 0;
10291         }
10292         /* need convert to big endian. */
10293         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10294         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10295         filter.queue = res->queue_id;
10296
10297         if (!strcmp(res->ops, "add"))
10298                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10299                                 RTE_ETH_FILTER_NTUPLE,
10300                                 RTE_ETH_FILTER_ADD,
10301                                 &filter);
10302         else
10303                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10304                                 RTE_ETH_FILTER_NTUPLE,
10305                                 RTE_ETH_FILTER_DELETE,
10306                                 &filter);
10307         if (ret < 0)
10308                 printf("5tuple filter programming error: (%s)\n",
10309                         strerror(-ret));
10310 }
10311
10312 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10313         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10314                                  filter, "5tuple_filter");
10315 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10316         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10317                                 port_id, UINT16);
10318 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10319         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10320                                  ops, "add#del");
10321 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10322         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10323                                 dst_ip, "dst_ip");
10324 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10325         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10326                                 dst_ip_value);
10327 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10328         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10329                                 src_ip, "src_ip");
10330 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10331         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10332                                 src_ip_value);
10333 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10334         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10335                                 dst_port, "dst_port");
10336 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10337         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10338                                 dst_port_value, UINT16);
10339 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10340         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10341                                 src_port, "src_port");
10342 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10343         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10344                                 src_port_value, UINT16);
10345 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10346         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10347                                 protocol, "protocol");
10348 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10349         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10350                                 protocol_value, UINT8);
10351 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10353                                 mask, "mask");
10354 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10355         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10356                                 mask_value, INT8);
10357 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10359                                 tcp_flags, "tcp_flags");
10360 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10362                                 tcp_flags_value, UINT8);
10363 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10364         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10365                                 priority, "priority");
10366 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10368                                 priority_value, UINT8);
10369 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10370         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10371                                 queue, "queue");
10372 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10373         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10374                                 queue_id, UINT16);
10375
10376 cmdline_parse_inst_t cmd_5tuple_filter = {
10377         .f = cmd_5tuple_filter_parsed,
10378         .data = NULL,
10379         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10380                 "src_ip <value> dst_port <value> src_port <value> "
10381                 "protocol <value>  mask <value> tcp_flags <value> "
10382                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10383         .tokens = {
10384                 (void *)&cmd_5tuple_filter_filter,
10385                 (void *)&cmd_5tuple_filter_port_id,
10386                 (void *)&cmd_5tuple_filter_ops,
10387                 (void *)&cmd_5tuple_filter_dst_ip,
10388                 (void *)&cmd_5tuple_filter_dst_ip_value,
10389                 (void *)&cmd_5tuple_filter_src_ip,
10390                 (void *)&cmd_5tuple_filter_src_ip_value,
10391                 (void *)&cmd_5tuple_filter_dst_port,
10392                 (void *)&cmd_5tuple_filter_dst_port_value,
10393                 (void *)&cmd_5tuple_filter_src_port,
10394                 (void *)&cmd_5tuple_filter_src_port_value,
10395                 (void *)&cmd_5tuple_filter_protocol,
10396                 (void *)&cmd_5tuple_filter_protocol_value,
10397                 (void *)&cmd_5tuple_filter_mask,
10398                 (void *)&cmd_5tuple_filter_mask_value,
10399                 (void *)&cmd_5tuple_filter_tcp_flags,
10400                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10401                 (void *)&cmd_5tuple_filter_priority,
10402                 (void *)&cmd_5tuple_filter_priority_value,
10403                 (void *)&cmd_5tuple_filter_queue,
10404                 (void *)&cmd_5tuple_filter_queue_id,
10405                 NULL,
10406         },
10407 };
10408
10409 /* *** ADD/REMOVE A flex FILTER *** */
10410 struct cmd_flex_filter_result {
10411         cmdline_fixed_string_t filter;
10412         cmdline_fixed_string_t ops;
10413         portid_t port_id;
10414         cmdline_fixed_string_t len;
10415         uint8_t len_value;
10416         cmdline_fixed_string_t bytes;
10417         cmdline_fixed_string_t bytes_value;
10418         cmdline_fixed_string_t mask;
10419         cmdline_fixed_string_t mask_value;
10420         cmdline_fixed_string_t priority;
10421         uint8_t priority_value;
10422         cmdline_fixed_string_t queue;
10423         uint16_t queue_id;
10424 };
10425
10426 static int xdigit2val(unsigned char c)
10427 {
10428         int val;
10429         if (isdigit(c))
10430                 val = c - '0';
10431         else if (isupper(c))
10432                 val = c - 'A' + 10;
10433         else
10434                 val = c - 'a' + 10;
10435         return val;
10436 }
10437
10438 static void
10439 cmd_flex_filter_parsed(void *parsed_result,
10440                           __attribute__((unused)) struct cmdline *cl,
10441                           __attribute__((unused)) void *data)
10442 {
10443         int ret = 0;
10444         struct rte_eth_flex_filter filter;
10445         struct cmd_flex_filter_result *res = parsed_result;
10446         char *bytes_ptr, *mask_ptr;
10447         uint16_t len, i, j = 0;
10448         char c;
10449         int val;
10450         uint8_t byte = 0;
10451
10452         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10453                 printf("the len exceed the max length 128\n");
10454                 return;
10455         }
10456         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10457         filter.len = res->len_value;
10458         filter.priority = res->priority_value;
10459         filter.queue = res->queue_id;
10460         bytes_ptr = res->bytes_value;
10461         mask_ptr = res->mask_value;
10462
10463          /* translate bytes string to array. */
10464         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10465                 (bytes_ptr[1] == 'X')))
10466                 bytes_ptr += 2;
10467         len = strnlen(bytes_ptr, res->len_value * 2);
10468         if (len == 0 || (len % 8 != 0)) {
10469                 printf("please check len and bytes input\n");
10470                 return;
10471         }
10472         for (i = 0; i < len; i++) {
10473                 c = bytes_ptr[i];
10474                 if (isxdigit(c) == 0) {
10475                         /* invalid characters. */
10476                         printf("invalid input\n");
10477                         return;
10478                 }
10479                 val = xdigit2val(c);
10480                 if (i % 2) {
10481                         byte |= val;
10482                         filter.bytes[j] = byte;
10483                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10484                         j++;
10485                         byte = 0;
10486                 } else
10487                         byte |= val << 4;
10488         }
10489         printf("\n");
10490          /* translate mask string to uint8_t array. */
10491         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10492                 (mask_ptr[1] == 'X')))
10493                 mask_ptr += 2;
10494         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10495         if (len == 0) {
10496                 printf("invalid input\n");
10497                 return;
10498         }
10499         j = 0;
10500         byte = 0;
10501         for (i = 0; i < len; i++) {
10502                 c = mask_ptr[i];
10503                 if (isxdigit(c) == 0) {
10504                         /* invalid characters. */
10505                         printf("invalid input\n");
10506                         return;
10507                 }
10508                 val = xdigit2val(c);
10509                 if (i % 2) {
10510                         byte |= val;
10511                         filter.mask[j] = byte;
10512                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10513                         j++;
10514                         byte = 0;
10515                 } else
10516                         byte |= val << 4;
10517         }
10518         printf("\n");
10519
10520         if (!strcmp(res->ops, "add"))
10521                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10522                                 RTE_ETH_FILTER_FLEXIBLE,
10523                                 RTE_ETH_FILTER_ADD,
10524                                 &filter);
10525         else
10526                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10527                                 RTE_ETH_FILTER_FLEXIBLE,
10528                                 RTE_ETH_FILTER_DELETE,
10529                                 &filter);
10530
10531         if (ret < 0)
10532                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10533 }
10534
10535 cmdline_parse_token_string_t cmd_flex_filter_filter =
10536         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10537                                 filter, "flex_filter");
10538 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10539         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10540                                 port_id, UINT16);
10541 cmdline_parse_token_string_t cmd_flex_filter_ops =
10542         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10543                                 ops, "add#del");
10544 cmdline_parse_token_string_t cmd_flex_filter_len =
10545         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10546                                 len, "len");
10547 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10548         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10549                                 len_value, UINT8);
10550 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10551         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10552                                 bytes, "bytes");
10553 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10554         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10555                                 bytes_value, NULL);
10556 cmdline_parse_token_string_t cmd_flex_filter_mask =
10557         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10558                                 mask, "mask");
10559 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10561                                 mask_value, NULL);
10562 cmdline_parse_token_string_t cmd_flex_filter_priority =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10564                                 priority, "priority");
10565 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10566         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10567                                 priority_value, UINT8);
10568 cmdline_parse_token_string_t cmd_flex_filter_queue =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10570                                 queue, "queue");
10571 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10572         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10573                                 queue_id, UINT16);
10574 cmdline_parse_inst_t cmd_flex_filter = {
10575         .f = cmd_flex_filter_parsed,
10576         .data = NULL,
10577         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10578                 "<value> mask <value> priority <value> queue <queue_id>: "
10579                 "Add/Del a flex filter",
10580         .tokens = {
10581                 (void *)&cmd_flex_filter_filter,
10582                 (void *)&cmd_flex_filter_port_id,
10583                 (void *)&cmd_flex_filter_ops,
10584                 (void *)&cmd_flex_filter_len,
10585                 (void *)&cmd_flex_filter_len_value,
10586                 (void *)&cmd_flex_filter_bytes,
10587                 (void *)&cmd_flex_filter_bytes_value,
10588                 (void *)&cmd_flex_filter_mask,
10589                 (void *)&cmd_flex_filter_mask_value,
10590                 (void *)&cmd_flex_filter_priority,
10591                 (void *)&cmd_flex_filter_priority_value,
10592                 (void *)&cmd_flex_filter_queue,
10593                 (void *)&cmd_flex_filter_queue_id,
10594                 NULL,
10595         },
10596 };
10597
10598 /* *** Filters Control *** */
10599
10600 /* *** deal with ethertype filter *** */
10601 struct cmd_ethertype_filter_result {
10602         cmdline_fixed_string_t filter;
10603         portid_t port_id;
10604         cmdline_fixed_string_t ops;
10605         cmdline_fixed_string_t mac;
10606         struct rte_ether_addr mac_addr;
10607         cmdline_fixed_string_t ethertype;
10608         uint16_t ethertype_value;
10609         cmdline_fixed_string_t drop;
10610         cmdline_fixed_string_t queue;
10611         uint16_t  queue_id;
10612 };
10613
10614 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10615         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10616                                  filter, "ethertype_filter");
10617 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10618         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10619                               port_id, UINT16);
10620 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10621         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10622                                  ops, "add#del");
10623 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10624         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10625                                  mac, "mac_addr#mac_ignr");
10626 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10627         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10628                                      mac_addr);
10629 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10630         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10631                                  ethertype, "ethertype");
10632 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10633         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10634                               ethertype_value, UINT16);
10635 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10636         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10637                                  drop, "drop#fwd");
10638 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10639         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10640                                  queue, "queue");
10641 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10642         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10643                               queue_id, UINT16);
10644
10645 static void
10646 cmd_ethertype_filter_parsed(void *parsed_result,
10647                           __attribute__((unused)) struct cmdline *cl,
10648                           __attribute__((unused)) void *data)
10649 {
10650         struct cmd_ethertype_filter_result *res = parsed_result;
10651         struct rte_eth_ethertype_filter filter;
10652         int ret = 0;
10653
10654         ret = rte_eth_dev_filter_supported(res->port_id,
10655                         RTE_ETH_FILTER_ETHERTYPE);
10656         if (ret < 0) {
10657                 printf("ethertype filter is not supported on port %u.\n",
10658                         res->port_id);
10659                 return;
10660         }
10661
10662         memset(&filter, 0, sizeof(filter));
10663         if (!strcmp(res->mac, "mac_addr")) {
10664                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10665                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10666                         sizeof(struct rte_ether_addr));
10667         }
10668         if (!strcmp(res->drop, "drop"))
10669                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10670         filter.ether_type = res->ethertype_value;
10671         filter.queue = res->queue_id;
10672
10673         if (!strcmp(res->ops, "add"))
10674                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10675                                 RTE_ETH_FILTER_ETHERTYPE,
10676                                 RTE_ETH_FILTER_ADD,
10677                                 &filter);
10678         else
10679                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10680                                 RTE_ETH_FILTER_ETHERTYPE,
10681                                 RTE_ETH_FILTER_DELETE,
10682                                 &filter);
10683         if (ret < 0)
10684                 printf("ethertype filter programming error: (%s)\n",
10685                         strerror(-ret));
10686 }
10687
10688 cmdline_parse_inst_t cmd_ethertype_filter = {
10689         .f = cmd_ethertype_filter_parsed,
10690         .data = NULL,
10691         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10692                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10693                 "Add or delete an ethertype filter entry",
10694         .tokens = {
10695                 (void *)&cmd_ethertype_filter_filter,
10696                 (void *)&cmd_ethertype_filter_port_id,
10697                 (void *)&cmd_ethertype_filter_ops,
10698                 (void *)&cmd_ethertype_filter_mac,
10699                 (void *)&cmd_ethertype_filter_mac_addr,
10700                 (void *)&cmd_ethertype_filter_ethertype,
10701                 (void *)&cmd_ethertype_filter_ethertype_value,
10702                 (void *)&cmd_ethertype_filter_drop,
10703                 (void *)&cmd_ethertype_filter_queue,
10704                 (void *)&cmd_ethertype_filter_queue_id,
10705                 NULL,
10706         },
10707 };
10708
10709 /* *** deal with flow director filter *** */
10710 struct cmd_flow_director_result {
10711         cmdline_fixed_string_t flow_director_filter;
10712         portid_t port_id;
10713         cmdline_fixed_string_t mode;
10714         cmdline_fixed_string_t mode_value;
10715         cmdline_fixed_string_t ops;
10716         cmdline_fixed_string_t flow;
10717         cmdline_fixed_string_t flow_type;
10718         cmdline_fixed_string_t ether;
10719         uint16_t ether_type;
10720         cmdline_fixed_string_t src;
10721         cmdline_ipaddr_t ip_src;
10722         uint16_t port_src;
10723         cmdline_fixed_string_t dst;
10724         cmdline_ipaddr_t ip_dst;
10725         uint16_t port_dst;
10726         cmdline_fixed_string_t verify_tag;
10727         uint32_t verify_tag_value;
10728         cmdline_fixed_string_t tos;
10729         uint8_t tos_value;
10730         cmdline_fixed_string_t proto;
10731         uint8_t proto_value;
10732         cmdline_fixed_string_t ttl;
10733         uint8_t ttl_value;
10734         cmdline_fixed_string_t vlan;
10735         uint16_t vlan_value;
10736         cmdline_fixed_string_t flexbytes;
10737         cmdline_fixed_string_t flexbytes_value;
10738         cmdline_fixed_string_t pf_vf;
10739         cmdline_fixed_string_t drop;
10740         cmdline_fixed_string_t queue;
10741         uint16_t  queue_id;
10742         cmdline_fixed_string_t fd_id;
10743         uint32_t  fd_id_value;
10744         cmdline_fixed_string_t mac;
10745         struct rte_ether_addr mac_addr;
10746         cmdline_fixed_string_t tunnel;
10747         cmdline_fixed_string_t tunnel_type;
10748         cmdline_fixed_string_t tunnel_id;
10749         uint32_t tunnel_id_value;
10750         cmdline_fixed_string_t packet;
10751         char filepath[];
10752 };
10753
10754 static inline int
10755 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10756 {
10757         char s[256];
10758         const char *p, *p0 = q_arg;
10759         char *end;
10760         unsigned long int_fld;
10761         char *str_fld[max_num];
10762         int i;
10763         unsigned size;
10764         int ret = -1;
10765
10766         p = strchr(p0, '(');
10767         if (p == NULL)
10768                 return -1;
10769         ++p;
10770         p0 = strchr(p, ')');
10771         if (p0 == NULL)
10772                 return -1;
10773
10774         size = p0 - p;
10775         if (size >= sizeof(s))
10776                 return -1;
10777
10778         snprintf(s, sizeof(s), "%.*s", size, p);
10779         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10780         if (ret < 0 || ret > max_num)
10781                 return -1;
10782         for (i = 0; i < ret; i++) {
10783                 errno = 0;
10784                 int_fld = strtoul(str_fld[i], &end, 0);
10785                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10786                         return -1;
10787                 flexbytes[i] = (uint8_t)int_fld;
10788         }
10789         return ret;
10790 }
10791
10792 static uint16_t
10793 str2flowtype(char *string)
10794 {
10795         uint8_t i = 0;
10796         static const struct {
10797                 char str[32];
10798                 uint16_t type;
10799         } flowtype_str[] = {
10800                 {"raw", RTE_ETH_FLOW_RAW},
10801                 {"ipv4", RTE_ETH_FLOW_IPV4},
10802                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10803                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10804                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10805                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10806                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10807                 {"ipv6", RTE_ETH_FLOW_IPV6},
10808                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10809                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10810                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10811                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10812                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10813                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10814         };
10815
10816         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10817                 if (!strcmp(flowtype_str[i].str, string))
10818                         return flowtype_str[i].type;
10819         }
10820
10821         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10822                 return (uint16_t)atoi(string);
10823
10824         return RTE_ETH_FLOW_UNKNOWN;
10825 }
10826
10827 static enum rte_eth_fdir_tunnel_type
10828 str2fdir_tunneltype(char *string)
10829 {
10830         uint8_t i = 0;
10831
10832         static const struct {
10833                 char str[32];
10834                 enum rte_eth_fdir_tunnel_type type;
10835         } tunneltype_str[] = {
10836                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10837                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10838         };
10839
10840         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10841                 if (!strcmp(tunneltype_str[i].str, string))
10842                         return tunneltype_str[i].type;
10843         }
10844         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10845 }
10846
10847 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10848 do { \
10849         if ((ip_addr).family == AF_INET) \
10850                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10851         else { \
10852                 printf("invalid parameter.\n"); \
10853                 return; \
10854         } \
10855 } while (0)
10856
10857 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10858 do { \
10859         if ((ip_addr).family == AF_INET6) \
10860                 rte_memcpy(&(ip), \
10861                                  &((ip_addr).addr.ipv6), \
10862                                  sizeof(struct in6_addr)); \
10863         else { \
10864                 printf("invalid parameter.\n"); \
10865                 return; \
10866         } \
10867 } while (0)
10868
10869 static void
10870 cmd_flow_director_filter_parsed(void *parsed_result,
10871                           __attribute__((unused)) struct cmdline *cl,
10872                           __attribute__((unused)) void *data)
10873 {
10874         struct cmd_flow_director_result *res = parsed_result;
10875         struct rte_eth_fdir_filter entry;
10876         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10877         char *end;
10878         unsigned long vf_id;
10879         int ret = 0;
10880
10881         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10882         if (ret < 0) {
10883                 printf("flow director is not supported on port %u.\n",
10884                         res->port_id);
10885                 return;
10886         }
10887         memset(flexbytes, 0, sizeof(flexbytes));
10888         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10889
10890         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10891                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10892                         printf("Please set mode to MAC-VLAN.\n");
10893                         return;
10894                 }
10895         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10896                 if (strcmp(res->mode_value, "Tunnel")) {
10897                         printf("Please set mode to Tunnel.\n");
10898                         return;
10899                 }
10900         } else {
10901                 if (!strcmp(res->mode_value, "raw")) {
10902 #ifdef RTE_LIBRTE_I40E_PMD
10903                         struct rte_pmd_i40e_flow_type_mapping
10904                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10905                         struct rte_pmd_i40e_pkt_template_conf conf;
10906                         uint16_t flow_type = str2flowtype(res->flow_type);
10907                         uint16_t i, port = res->port_id;
10908                         uint8_t add;
10909
10910                         memset(&conf, 0, sizeof(conf));
10911
10912                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10913                                 printf("Invalid flow type specified.\n");
10914                                 return;
10915                         }
10916                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10917                                                                  mapping);
10918                         if (ret)
10919                                 return;
10920                         if (mapping[flow_type].pctype == 0ULL) {
10921                                 printf("Invalid flow type specified.\n");
10922                                 return;
10923                         }
10924                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10925                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10926                                         conf.input.pctype = i;
10927                                         break;
10928                                 }
10929                         }
10930
10931                         conf.input.packet = open_file(res->filepath,
10932                                                 &conf.input.length);
10933                         if (!conf.input.packet)
10934                                 return;
10935                         if (!strcmp(res->drop, "drop"))
10936                                 conf.action.behavior =
10937                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10938                         else
10939                                 conf.action.behavior =
10940                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10941                         conf.action.report_status =
10942                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10943                         conf.action.rx_queue = res->queue_id;
10944                         conf.soft_id = res->fd_id_value;
10945                         add  = strcmp(res->ops, "del") ? 1 : 0;
10946                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10947                                                                         &conf,
10948                                                                         add);
10949                         if (ret < 0)
10950                                 printf("flow director config error: (%s)\n",
10951                                        strerror(-ret));
10952                         close_file(conf.input.packet);
10953 #endif
10954                         return;
10955                 } else if (strcmp(res->mode_value, "IP")) {
10956                         printf("Please set mode to IP or raw.\n");
10957                         return;
10958                 }
10959                 entry.input.flow_type = str2flowtype(res->flow_type);
10960         }
10961
10962         ret = parse_flexbytes(res->flexbytes_value,
10963                                         flexbytes,
10964                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10965         if (ret < 0) {
10966                 printf("error: Cannot parse flexbytes input.\n");
10967                 return;
10968         }
10969
10970         switch (entry.input.flow_type) {
10971         case RTE_ETH_FLOW_FRAG_IPV4:
10972         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10973                 entry.input.flow.ip4_flow.proto = res->proto_value;
10974                 /* fall-through */
10975         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10976         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10977                 IPV4_ADDR_TO_UINT(res->ip_dst,
10978                         entry.input.flow.ip4_flow.dst_ip);
10979                 IPV4_ADDR_TO_UINT(res->ip_src,
10980                         entry.input.flow.ip4_flow.src_ip);
10981                 entry.input.flow.ip4_flow.tos = res->tos_value;
10982                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10983                 /* need convert to big endian. */
10984                 entry.input.flow.udp4_flow.dst_port =
10985                                 rte_cpu_to_be_16(res->port_dst);
10986                 entry.input.flow.udp4_flow.src_port =
10987                                 rte_cpu_to_be_16(res->port_src);
10988                 break;
10989         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10990                 IPV4_ADDR_TO_UINT(res->ip_dst,
10991                         entry.input.flow.sctp4_flow.ip.dst_ip);
10992                 IPV4_ADDR_TO_UINT(res->ip_src,
10993                         entry.input.flow.sctp4_flow.ip.src_ip);
10994                 entry.input.flow.ip4_flow.tos = res->tos_value;
10995                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10996                 /* need convert to big endian. */
10997                 entry.input.flow.sctp4_flow.dst_port =
10998                                 rte_cpu_to_be_16(res->port_dst);
10999                 entry.input.flow.sctp4_flow.src_port =
11000                                 rte_cpu_to_be_16(res->port_src);
11001                 entry.input.flow.sctp4_flow.verify_tag =
11002                                 rte_cpu_to_be_32(res->verify_tag_value);
11003                 break;
11004         case RTE_ETH_FLOW_FRAG_IPV6:
11005         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11006                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11007                 /* fall-through */
11008         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11009         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11010                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11011                         entry.input.flow.ipv6_flow.dst_ip);
11012                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11013                         entry.input.flow.ipv6_flow.src_ip);
11014                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11015                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11016                 /* need convert to big endian. */
11017                 entry.input.flow.udp6_flow.dst_port =
11018                                 rte_cpu_to_be_16(res->port_dst);
11019                 entry.input.flow.udp6_flow.src_port =
11020                                 rte_cpu_to_be_16(res->port_src);
11021                 break;
11022         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11023                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11024                         entry.input.flow.sctp6_flow.ip.dst_ip);
11025                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11026                         entry.input.flow.sctp6_flow.ip.src_ip);
11027                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11028                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11029                 /* need convert to big endian. */
11030                 entry.input.flow.sctp6_flow.dst_port =
11031                                 rte_cpu_to_be_16(res->port_dst);
11032                 entry.input.flow.sctp6_flow.src_port =
11033                                 rte_cpu_to_be_16(res->port_src);
11034                 entry.input.flow.sctp6_flow.verify_tag =
11035                                 rte_cpu_to_be_32(res->verify_tag_value);
11036                 break;
11037         case RTE_ETH_FLOW_L2_PAYLOAD:
11038                 entry.input.flow.l2_flow.ether_type =
11039                         rte_cpu_to_be_16(res->ether_type);
11040                 break;
11041         default:
11042                 break;
11043         }
11044
11045         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11046                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11047                                  &res->mac_addr,
11048                                  sizeof(struct rte_ether_addr));
11049
11050         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11051                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11052                                  &res->mac_addr,
11053                                  sizeof(struct rte_ether_addr));
11054                 entry.input.flow.tunnel_flow.tunnel_type =
11055                         str2fdir_tunneltype(res->tunnel_type);
11056                 entry.input.flow.tunnel_flow.tunnel_id =
11057                         rte_cpu_to_be_32(res->tunnel_id_value);
11058         }
11059
11060         rte_memcpy(entry.input.flow_ext.flexbytes,
11061                    flexbytes,
11062                    RTE_ETH_FDIR_MAX_FLEXLEN);
11063
11064         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11065
11066         entry.action.flex_off = 0;  /*use 0 by default */
11067         if (!strcmp(res->drop, "drop"))
11068                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11069         else
11070                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11071
11072         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11073             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11074                 if (!strcmp(res->pf_vf, "pf"))
11075                         entry.input.flow_ext.is_vf = 0;
11076                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11077                         struct rte_eth_dev_info dev_info;
11078
11079                         memset(&dev_info, 0, sizeof(dev_info));
11080                         rte_eth_dev_info_get(res->port_id, &dev_info);
11081                         errno = 0;
11082                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11083                         if (errno != 0 || *end != '\0' ||
11084                             vf_id >= dev_info.max_vfs) {
11085                                 printf("invalid parameter %s.\n", res->pf_vf);
11086                                 return;
11087                         }
11088                         entry.input.flow_ext.is_vf = 1;
11089                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11090                 } else {
11091                         printf("invalid parameter %s.\n", res->pf_vf);
11092                         return;
11093                 }
11094         }
11095
11096         /* set to report FD ID by default */
11097         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11098         entry.action.rx_queue = res->queue_id;
11099         entry.soft_id = res->fd_id_value;
11100         if (!strcmp(res->ops, "add"))
11101                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11102                                              RTE_ETH_FILTER_ADD, &entry);
11103         else if (!strcmp(res->ops, "del"))
11104                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11105                                              RTE_ETH_FILTER_DELETE, &entry);
11106         else
11107                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11108                                              RTE_ETH_FILTER_UPDATE, &entry);
11109         if (ret < 0)
11110                 printf("flow director programming error: (%s)\n",
11111                         strerror(-ret));
11112 }
11113
11114 cmdline_parse_token_string_t cmd_flow_director_filter =
11115         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11116                                  flow_director_filter, "flow_director_filter");
11117 cmdline_parse_token_num_t cmd_flow_director_port_id =
11118         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11119                               port_id, UINT16);
11120 cmdline_parse_token_string_t cmd_flow_director_ops =
11121         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11122                                  ops, "add#del#update");
11123 cmdline_parse_token_string_t cmd_flow_director_flow =
11124         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11125                                  flow, "flow");
11126 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11128                 flow_type, NULL);
11129 cmdline_parse_token_string_t cmd_flow_director_ether =
11130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11131                                  ether, "ether");
11132 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11133         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11134                               ether_type, UINT16);
11135 cmdline_parse_token_string_t cmd_flow_director_src =
11136         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11137                                  src, "src");
11138 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11139         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11140                                  ip_src);
11141 cmdline_parse_token_num_t cmd_flow_director_port_src =
11142         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11143                               port_src, UINT16);
11144 cmdline_parse_token_string_t cmd_flow_director_dst =
11145         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11146                                  dst, "dst");
11147 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11148         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11149                                  ip_dst);
11150 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11151         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11152                               port_dst, UINT16);
11153 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11154         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11155                                   verify_tag, "verify_tag");
11156 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11157         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11158                               verify_tag_value, UINT32);
11159 cmdline_parse_token_string_t cmd_flow_director_tos =
11160         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11161                                  tos, "tos");
11162 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11163         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11164                               tos_value, UINT8);
11165 cmdline_parse_token_string_t cmd_flow_director_proto =
11166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11167                                  proto, "proto");
11168 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11169         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11170                               proto_value, UINT8);
11171 cmdline_parse_token_string_t cmd_flow_director_ttl =
11172         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11173                                  ttl, "ttl");
11174 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11175         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11176                               ttl_value, UINT8);
11177 cmdline_parse_token_string_t cmd_flow_director_vlan =
11178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11179                                  vlan, "vlan");
11180 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11181         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11182                               vlan_value, UINT16);
11183 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11184         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11185                                  flexbytes, "flexbytes");
11186 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11188                               flexbytes_value, NULL);
11189 cmdline_parse_token_string_t cmd_flow_director_drop =
11190         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11191                                  drop, "drop#fwd");
11192 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11194                               pf_vf, NULL);
11195 cmdline_parse_token_string_t cmd_flow_director_queue =
11196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11197                                  queue, "queue");
11198 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11199         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11200                               queue_id, UINT16);
11201 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11203                                  fd_id, "fd_id");
11204 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11205         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11206                               fd_id_value, UINT32);
11207
11208 cmdline_parse_token_string_t cmd_flow_director_mode =
11209         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11210                                  mode, "mode");
11211 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11212         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11213                                  mode_value, "IP");
11214 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11215         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11216                                  mode_value, "MAC-VLAN");
11217 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11218         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11219                                  mode_value, "Tunnel");
11220 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11221         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11222                                  mode_value, "raw");
11223 cmdline_parse_token_string_t cmd_flow_director_mac =
11224         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11225                                  mac, "mac");
11226 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11227         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11228                                     mac_addr);
11229 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11230         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11231                                  tunnel, "tunnel");
11232 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11233         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11234                                  tunnel_type, "NVGRE#VxLAN");
11235 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11236         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11237                                  tunnel_id, "tunnel-id");
11238 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11239         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11240                               tunnel_id_value, UINT32);
11241 cmdline_parse_token_string_t cmd_flow_director_packet =
11242         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11243                                  packet, "packet");
11244 cmdline_parse_token_string_t cmd_flow_director_filepath =
11245         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11246                                  filepath, NULL);
11247
11248 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11249         .f = cmd_flow_director_filter_parsed,
11250         .data = NULL,
11251         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11252                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11253                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11254                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11255                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11256                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11257                 "fd_id <fd_id_value>: "
11258                 "Add or delete an ip flow director entry on NIC",
11259         .tokens = {
11260                 (void *)&cmd_flow_director_filter,
11261                 (void *)&cmd_flow_director_port_id,
11262                 (void *)&cmd_flow_director_mode,
11263                 (void *)&cmd_flow_director_mode_ip,
11264                 (void *)&cmd_flow_director_ops,
11265                 (void *)&cmd_flow_director_flow,
11266                 (void *)&cmd_flow_director_flow_type,
11267                 (void *)&cmd_flow_director_src,
11268                 (void *)&cmd_flow_director_ip_src,
11269                 (void *)&cmd_flow_director_dst,
11270                 (void *)&cmd_flow_director_ip_dst,
11271                 (void *)&cmd_flow_director_tos,
11272                 (void *)&cmd_flow_director_tos_value,
11273                 (void *)&cmd_flow_director_proto,
11274                 (void *)&cmd_flow_director_proto_value,
11275                 (void *)&cmd_flow_director_ttl,
11276                 (void *)&cmd_flow_director_ttl_value,
11277                 (void *)&cmd_flow_director_vlan,
11278                 (void *)&cmd_flow_director_vlan_value,
11279                 (void *)&cmd_flow_director_flexbytes,
11280                 (void *)&cmd_flow_director_flexbytes_value,
11281                 (void *)&cmd_flow_director_drop,
11282                 (void *)&cmd_flow_director_pf_vf,
11283                 (void *)&cmd_flow_director_queue,
11284                 (void *)&cmd_flow_director_queue_id,
11285                 (void *)&cmd_flow_director_fd_id,
11286                 (void *)&cmd_flow_director_fd_id_value,
11287                 NULL,
11288         },
11289 };
11290
11291 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11292         .f = cmd_flow_director_filter_parsed,
11293         .data = NULL,
11294         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11295                 "director entry on NIC",
11296         .tokens = {
11297                 (void *)&cmd_flow_director_filter,
11298                 (void *)&cmd_flow_director_port_id,
11299                 (void *)&cmd_flow_director_mode,
11300                 (void *)&cmd_flow_director_mode_ip,
11301                 (void *)&cmd_flow_director_ops,
11302                 (void *)&cmd_flow_director_flow,
11303                 (void *)&cmd_flow_director_flow_type,
11304                 (void *)&cmd_flow_director_src,
11305                 (void *)&cmd_flow_director_ip_src,
11306                 (void *)&cmd_flow_director_port_src,
11307                 (void *)&cmd_flow_director_dst,
11308                 (void *)&cmd_flow_director_ip_dst,
11309                 (void *)&cmd_flow_director_port_dst,
11310                 (void *)&cmd_flow_director_tos,
11311                 (void *)&cmd_flow_director_tos_value,
11312                 (void *)&cmd_flow_director_ttl,
11313                 (void *)&cmd_flow_director_ttl_value,
11314                 (void *)&cmd_flow_director_vlan,
11315                 (void *)&cmd_flow_director_vlan_value,
11316                 (void *)&cmd_flow_director_flexbytes,
11317                 (void *)&cmd_flow_director_flexbytes_value,
11318                 (void *)&cmd_flow_director_drop,
11319                 (void *)&cmd_flow_director_pf_vf,
11320                 (void *)&cmd_flow_director_queue,
11321                 (void *)&cmd_flow_director_queue_id,
11322                 (void *)&cmd_flow_director_fd_id,
11323                 (void *)&cmd_flow_director_fd_id_value,
11324                 NULL,
11325         },
11326 };
11327
11328 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11329         .f = cmd_flow_director_filter_parsed,
11330         .data = NULL,
11331         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11332                 "director entry on NIC",
11333         .tokens = {
11334                 (void *)&cmd_flow_director_filter,
11335                 (void *)&cmd_flow_director_port_id,
11336                 (void *)&cmd_flow_director_mode,
11337                 (void *)&cmd_flow_director_mode_ip,
11338                 (void *)&cmd_flow_director_ops,
11339                 (void *)&cmd_flow_director_flow,
11340                 (void *)&cmd_flow_director_flow_type,
11341                 (void *)&cmd_flow_director_src,
11342                 (void *)&cmd_flow_director_ip_src,
11343                 (void *)&cmd_flow_director_port_src,
11344                 (void *)&cmd_flow_director_dst,
11345                 (void *)&cmd_flow_director_ip_dst,
11346                 (void *)&cmd_flow_director_port_dst,
11347                 (void *)&cmd_flow_director_verify_tag,
11348                 (void *)&cmd_flow_director_verify_tag_value,
11349                 (void *)&cmd_flow_director_tos,
11350                 (void *)&cmd_flow_director_tos_value,
11351                 (void *)&cmd_flow_director_ttl,
11352                 (void *)&cmd_flow_director_ttl_value,
11353                 (void *)&cmd_flow_director_vlan,
11354                 (void *)&cmd_flow_director_vlan_value,
11355                 (void *)&cmd_flow_director_flexbytes,
11356                 (void *)&cmd_flow_director_flexbytes_value,
11357                 (void *)&cmd_flow_director_drop,
11358                 (void *)&cmd_flow_director_pf_vf,
11359                 (void *)&cmd_flow_director_queue,
11360                 (void *)&cmd_flow_director_queue_id,
11361                 (void *)&cmd_flow_director_fd_id,
11362                 (void *)&cmd_flow_director_fd_id_value,
11363                 NULL,
11364         },
11365 };
11366
11367 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11368         .f = cmd_flow_director_filter_parsed,
11369         .data = NULL,
11370         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11371                 "director entry on NIC",
11372         .tokens = {
11373                 (void *)&cmd_flow_director_filter,
11374                 (void *)&cmd_flow_director_port_id,
11375                 (void *)&cmd_flow_director_mode,
11376                 (void *)&cmd_flow_director_mode_ip,
11377                 (void *)&cmd_flow_director_ops,
11378                 (void *)&cmd_flow_director_flow,
11379                 (void *)&cmd_flow_director_flow_type,
11380                 (void *)&cmd_flow_director_ether,
11381                 (void *)&cmd_flow_director_ether_type,
11382                 (void *)&cmd_flow_director_flexbytes,
11383                 (void *)&cmd_flow_director_flexbytes_value,
11384                 (void *)&cmd_flow_director_drop,
11385                 (void *)&cmd_flow_director_pf_vf,
11386                 (void *)&cmd_flow_director_queue,
11387                 (void *)&cmd_flow_director_queue_id,
11388                 (void *)&cmd_flow_director_fd_id,
11389                 (void *)&cmd_flow_director_fd_id_value,
11390                 NULL,
11391         },
11392 };
11393
11394 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11395         .f = cmd_flow_director_filter_parsed,
11396         .data = NULL,
11397         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11398                 "director entry on NIC",
11399         .tokens = {
11400                 (void *)&cmd_flow_director_filter,
11401                 (void *)&cmd_flow_director_port_id,
11402                 (void *)&cmd_flow_director_mode,
11403                 (void *)&cmd_flow_director_mode_mac_vlan,
11404                 (void *)&cmd_flow_director_ops,
11405                 (void *)&cmd_flow_director_mac,
11406                 (void *)&cmd_flow_director_mac_addr,
11407                 (void *)&cmd_flow_director_vlan,
11408                 (void *)&cmd_flow_director_vlan_value,
11409                 (void *)&cmd_flow_director_flexbytes,
11410                 (void *)&cmd_flow_director_flexbytes_value,
11411                 (void *)&cmd_flow_director_drop,
11412                 (void *)&cmd_flow_director_queue,
11413                 (void *)&cmd_flow_director_queue_id,
11414                 (void *)&cmd_flow_director_fd_id,
11415                 (void *)&cmd_flow_director_fd_id_value,
11416                 NULL,
11417         },
11418 };
11419
11420 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11421         .f = cmd_flow_director_filter_parsed,
11422         .data = NULL,
11423         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11424                 "director entry on NIC",
11425         .tokens = {
11426                 (void *)&cmd_flow_director_filter,
11427                 (void *)&cmd_flow_director_port_id,
11428                 (void *)&cmd_flow_director_mode,
11429                 (void *)&cmd_flow_director_mode_tunnel,
11430                 (void *)&cmd_flow_director_ops,
11431                 (void *)&cmd_flow_director_mac,
11432                 (void *)&cmd_flow_director_mac_addr,
11433                 (void *)&cmd_flow_director_vlan,
11434                 (void *)&cmd_flow_director_vlan_value,
11435                 (void *)&cmd_flow_director_tunnel,
11436                 (void *)&cmd_flow_director_tunnel_type,
11437                 (void *)&cmd_flow_director_tunnel_id,
11438                 (void *)&cmd_flow_director_tunnel_id_value,
11439                 (void *)&cmd_flow_director_flexbytes,
11440                 (void *)&cmd_flow_director_flexbytes_value,
11441                 (void *)&cmd_flow_director_drop,
11442                 (void *)&cmd_flow_director_queue,
11443                 (void *)&cmd_flow_director_queue_id,
11444                 (void *)&cmd_flow_director_fd_id,
11445                 (void *)&cmd_flow_director_fd_id_value,
11446                 NULL,
11447         },
11448 };
11449
11450 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11451         .f = cmd_flow_director_filter_parsed,
11452         .data = NULL,
11453         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11454                 "director entry on NIC",
11455         .tokens = {
11456                 (void *)&cmd_flow_director_filter,
11457                 (void *)&cmd_flow_director_port_id,
11458                 (void *)&cmd_flow_director_mode,
11459                 (void *)&cmd_flow_director_mode_raw,
11460                 (void *)&cmd_flow_director_ops,
11461                 (void *)&cmd_flow_director_flow,
11462                 (void *)&cmd_flow_director_flow_type,
11463                 (void *)&cmd_flow_director_drop,
11464                 (void *)&cmd_flow_director_queue,
11465                 (void *)&cmd_flow_director_queue_id,
11466                 (void *)&cmd_flow_director_fd_id,
11467                 (void *)&cmd_flow_director_fd_id_value,
11468                 (void *)&cmd_flow_director_packet,
11469                 (void *)&cmd_flow_director_filepath,
11470                 NULL,
11471         },
11472 };
11473
11474 struct cmd_flush_flow_director_result {
11475         cmdline_fixed_string_t flush_flow_director;
11476         portid_t port_id;
11477 };
11478
11479 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11480         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11481                                  flush_flow_director, "flush_flow_director");
11482 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11483         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11484                               port_id, UINT16);
11485
11486 static void
11487 cmd_flush_flow_director_parsed(void *parsed_result,
11488                           __attribute__((unused)) struct cmdline *cl,
11489                           __attribute__((unused)) void *data)
11490 {
11491         struct cmd_flow_director_result *res = parsed_result;
11492         int ret = 0;
11493
11494         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11495         if (ret < 0) {
11496                 printf("flow director is not supported on port %u.\n",
11497                         res->port_id);
11498                 return;
11499         }
11500
11501         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11502                         RTE_ETH_FILTER_FLUSH, NULL);
11503         if (ret < 0)
11504                 printf("flow director table flushing error: (%s)\n",
11505                         strerror(-ret));
11506 }
11507
11508 cmdline_parse_inst_t cmd_flush_flow_director = {
11509         .f = cmd_flush_flow_director_parsed,
11510         .data = NULL,
11511         .help_str = "flush_flow_director <port_id>: "
11512                 "Flush all flow director entries of a device on NIC",
11513         .tokens = {
11514                 (void *)&cmd_flush_flow_director_flush,
11515                 (void *)&cmd_flush_flow_director_port_id,
11516                 NULL,
11517         },
11518 };
11519
11520 /* *** deal with flow director mask *** */
11521 struct cmd_flow_director_mask_result {
11522         cmdline_fixed_string_t flow_director_mask;
11523         portid_t port_id;
11524         cmdline_fixed_string_t mode;
11525         cmdline_fixed_string_t mode_value;
11526         cmdline_fixed_string_t vlan;
11527         uint16_t vlan_mask;
11528         cmdline_fixed_string_t src_mask;
11529         cmdline_ipaddr_t ipv4_src;
11530         cmdline_ipaddr_t ipv6_src;
11531         uint16_t port_src;
11532         cmdline_fixed_string_t dst_mask;
11533         cmdline_ipaddr_t ipv4_dst;
11534         cmdline_ipaddr_t ipv6_dst;
11535         uint16_t port_dst;
11536         cmdline_fixed_string_t mac;
11537         uint8_t mac_addr_byte_mask;
11538         cmdline_fixed_string_t tunnel_id;
11539         uint32_t tunnel_id_mask;
11540         cmdline_fixed_string_t tunnel_type;
11541         uint8_t tunnel_type_mask;
11542 };
11543
11544 static void
11545 cmd_flow_director_mask_parsed(void *parsed_result,
11546                           __attribute__((unused)) struct cmdline *cl,
11547                           __attribute__((unused)) void *data)
11548 {
11549         struct cmd_flow_director_mask_result *res = parsed_result;
11550         struct rte_eth_fdir_masks *mask;
11551         struct rte_port *port;
11552
11553         port = &ports[res->port_id];
11554         /** Check if the port is not started **/
11555         if (port->port_status != RTE_PORT_STOPPED) {
11556                 printf("Please stop port %d first\n", res->port_id);
11557                 return;
11558         }
11559
11560         mask = &port->dev_conf.fdir_conf.mask;
11561
11562         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11563                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11564                         printf("Please set mode to MAC-VLAN.\n");
11565                         return;
11566                 }
11567
11568                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11569         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11570                 if (strcmp(res->mode_value, "Tunnel")) {
11571                         printf("Please set mode to Tunnel.\n");
11572                         return;
11573                 }
11574
11575                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11576                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11577                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11578                 mask->tunnel_type_mask = res->tunnel_type_mask;
11579         } else {
11580                 if (strcmp(res->mode_value, "IP")) {
11581                         printf("Please set mode to IP.\n");
11582                         return;
11583                 }
11584
11585                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11586                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11587                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11588                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11589                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11590                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11591                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11592         }
11593
11594         cmd_reconfig_device_queue(res->port_id, 1, 1);
11595 }
11596
11597 cmdline_parse_token_string_t cmd_flow_director_mask =
11598         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11599                                  flow_director_mask, "flow_director_mask");
11600 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11601         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11602                               port_id, UINT16);
11603 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11604         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11605                                  vlan, "vlan");
11606 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11607         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11608                               vlan_mask, UINT16);
11609 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11610         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11611                                  src_mask, "src_mask");
11612 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11613         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11614                                  ipv4_src);
11615 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11616         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11617                                  ipv6_src);
11618 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11619         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11620                               port_src, UINT16);
11621 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11622         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11623                                  dst_mask, "dst_mask");
11624 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11625         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11626                                  ipv4_dst);
11627 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11628         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11629                                  ipv6_dst);
11630 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11631         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11632                               port_dst, UINT16);
11633
11634 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11635         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11636                                  mode, "mode");
11637 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11638         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11639                                  mode_value, "IP");
11640 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11642                                  mode_value, "MAC-VLAN");
11643 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11644         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11645                                  mode_value, "Tunnel");
11646 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11647         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11648                                  mac, "mac");
11649 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11650         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11651                               mac_addr_byte_mask, UINT8);
11652 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11654                                  tunnel_type, "tunnel-type");
11655 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11656         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11657                               tunnel_type_mask, UINT8);
11658 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11659         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11660                                  tunnel_id, "tunnel-id");
11661 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11662         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11663                               tunnel_id_mask, UINT32);
11664
11665 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11666         .f = cmd_flow_director_mask_parsed,
11667         .data = NULL,
11668         .help_str = "flow_director_mask ... : "
11669                 "Set IP mode flow director's mask on NIC",
11670         .tokens = {
11671                 (void *)&cmd_flow_director_mask,
11672                 (void *)&cmd_flow_director_mask_port_id,
11673                 (void *)&cmd_flow_director_mask_mode,
11674                 (void *)&cmd_flow_director_mask_mode_ip,
11675                 (void *)&cmd_flow_director_mask_vlan,
11676                 (void *)&cmd_flow_director_mask_vlan_value,
11677                 (void *)&cmd_flow_director_mask_src,
11678                 (void *)&cmd_flow_director_mask_ipv4_src,
11679                 (void *)&cmd_flow_director_mask_ipv6_src,
11680                 (void *)&cmd_flow_director_mask_port_src,
11681                 (void *)&cmd_flow_director_mask_dst,
11682                 (void *)&cmd_flow_director_mask_ipv4_dst,
11683                 (void *)&cmd_flow_director_mask_ipv6_dst,
11684                 (void *)&cmd_flow_director_mask_port_dst,
11685                 NULL,
11686         },
11687 };
11688
11689 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11690         .f = cmd_flow_director_mask_parsed,
11691         .data = NULL,
11692         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11693                 "flow director's mask on NIC",
11694         .tokens = {
11695                 (void *)&cmd_flow_director_mask,
11696                 (void *)&cmd_flow_director_mask_port_id,
11697                 (void *)&cmd_flow_director_mask_mode,
11698                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11699                 (void *)&cmd_flow_director_mask_vlan,
11700                 (void *)&cmd_flow_director_mask_vlan_value,
11701                 NULL,
11702         },
11703 };
11704
11705 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11706         .f = cmd_flow_director_mask_parsed,
11707         .data = NULL,
11708         .help_str = "flow_director_mask ... : Set tunnel mode "
11709                 "flow director's mask on NIC",
11710         .tokens = {
11711                 (void *)&cmd_flow_director_mask,
11712                 (void *)&cmd_flow_director_mask_port_id,
11713                 (void *)&cmd_flow_director_mask_mode,
11714                 (void *)&cmd_flow_director_mask_mode_tunnel,
11715                 (void *)&cmd_flow_director_mask_vlan,
11716                 (void *)&cmd_flow_director_mask_vlan_value,
11717                 (void *)&cmd_flow_director_mask_mac,
11718                 (void *)&cmd_flow_director_mask_mac_value,
11719                 (void *)&cmd_flow_director_mask_tunnel_type,
11720                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11721                 (void *)&cmd_flow_director_mask_tunnel_id,
11722                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11723                 NULL,
11724         },
11725 };
11726
11727 /* *** deal with flow director mask on flexible payload *** */
11728 struct cmd_flow_director_flex_mask_result {
11729         cmdline_fixed_string_t flow_director_flexmask;
11730         portid_t port_id;
11731         cmdline_fixed_string_t flow;
11732         cmdline_fixed_string_t flow_type;
11733         cmdline_fixed_string_t mask;
11734 };
11735
11736 static void
11737 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11738                           __attribute__((unused)) struct cmdline *cl,
11739                           __attribute__((unused)) void *data)
11740 {
11741         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11742         struct rte_eth_fdir_info fdir_info;
11743         struct rte_eth_fdir_flex_mask flex_mask;
11744         struct rte_port *port;
11745         uint64_t flow_type_mask;
11746         uint16_t i;
11747         int ret;
11748
11749         port = &ports[res->port_id];
11750         /** Check if the port is not started **/
11751         if (port->port_status != RTE_PORT_STOPPED) {
11752                 printf("Please stop port %d first\n", res->port_id);
11753                 return;
11754         }
11755
11756         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11757         ret = parse_flexbytes(res->mask,
11758                         flex_mask.mask,
11759                         RTE_ETH_FDIR_MAX_FLEXLEN);
11760         if (ret < 0) {
11761                 printf("error: Cannot parse mask input.\n");
11762                 return;
11763         }
11764
11765         memset(&fdir_info, 0, sizeof(fdir_info));
11766         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11767                                 RTE_ETH_FILTER_INFO, &fdir_info);
11768         if (ret < 0) {
11769                 printf("Cannot get FDir filter info\n");
11770                 return;
11771         }
11772
11773         if (!strcmp(res->flow_type, "none")) {
11774                 /* means don't specify the flow type */
11775                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11776                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11777                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11778                                0, sizeof(struct rte_eth_fdir_flex_mask));
11779                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11780                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11781                                  &flex_mask,
11782                                  sizeof(struct rte_eth_fdir_flex_mask));
11783                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11784                 return;
11785         }
11786         flow_type_mask = fdir_info.flow_types_mask[0];
11787         if (!strcmp(res->flow_type, "all")) {
11788                 if (!flow_type_mask) {
11789                         printf("No flow type supported\n");
11790                         return;
11791                 }
11792                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11793                         if (flow_type_mask & (1ULL << i)) {
11794                                 flex_mask.flow_type = i;
11795                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11796                         }
11797                 }
11798                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11799                 return;
11800         }
11801         flex_mask.flow_type = str2flowtype(res->flow_type);
11802         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11803                 printf("Flow type %s not supported on port %d\n",
11804                                 res->flow_type, res->port_id);
11805                 return;
11806         }
11807         fdir_set_flex_mask(res->port_id, &flex_mask);
11808         cmd_reconfig_device_queue(res->port_id, 1, 1);
11809 }
11810
11811 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11812         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11813                                  flow_director_flexmask,
11814                                  "flow_director_flex_mask");
11815 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11816         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11817                               port_id, UINT16);
11818 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11819         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11820                                  flow, "flow");
11821 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11822         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11823                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11824                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11825 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11827                                  mask, NULL);
11828
11829 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11830         .f = cmd_flow_director_flex_mask_parsed,
11831         .data = NULL,
11832         .help_str = "flow_director_flex_mask ... : "
11833                 "Set flow director's flex mask on NIC",
11834         .tokens = {
11835                 (void *)&cmd_flow_director_flexmask,
11836                 (void *)&cmd_flow_director_flexmask_port_id,
11837                 (void *)&cmd_flow_director_flexmask_flow,
11838                 (void *)&cmd_flow_director_flexmask_flow_type,
11839                 (void *)&cmd_flow_director_flexmask_mask,
11840                 NULL,
11841         },
11842 };
11843
11844 /* *** deal with flow director flexible payload configuration *** */
11845 struct cmd_flow_director_flexpayload_result {
11846         cmdline_fixed_string_t flow_director_flexpayload;
11847         portid_t port_id;
11848         cmdline_fixed_string_t payload_layer;
11849         cmdline_fixed_string_t payload_cfg;
11850 };
11851
11852 static inline int
11853 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11854 {
11855         char s[256];
11856         const char *p, *p0 = q_arg;
11857         char *end;
11858         unsigned long int_fld;
11859         char *str_fld[max_num];
11860         int i;
11861         unsigned size;
11862         int ret = -1;
11863
11864         p = strchr(p0, '(');
11865         if (p == NULL)
11866                 return -1;
11867         ++p;
11868         p0 = strchr(p, ')');
11869         if (p0 == NULL)
11870                 return -1;
11871
11872         size = p0 - p;
11873         if (size >= sizeof(s))
11874                 return -1;
11875
11876         snprintf(s, sizeof(s), "%.*s", size, p);
11877         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11878         if (ret < 0 || ret > max_num)
11879                 return -1;
11880         for (i = 0; i < ret; i++) {
11881                 errno = 0;
11882                 int_fld = strtoul(str_fld[i], &end, 0);
11883                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11884                         return -1;
11885                 offsets[i] = (uint16_t)int_fld;
11886         }
11887         return ret;
11888 }
11889
11890 static void
11891 cmd_flow_director_flxpld_parsed(void *parsed_result,
11892                           __attribute__((unused)) struct cmdline *cl,
11893                           __attribute__((unused)) void *data)
11894 {
11895         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11896         struct rte_eth_flex_payload_cfg flex_cfg;
11897         struct rte_port *port;
11898         int ret = 0;
11899
11900         port = &ports[res->port_id];
11901         /** Check if the port is not started **/
11902         if (port->port_status != RTE_PORT_STOPPED) {
11903                 printf("Please stop port %d first\n", res->port_id);
11904                 return;
11905         }
11906
11907         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11908
11909         if (!strcmp(res->payload_layer, "raw"))
11910                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11911         else if (!strcmp(res->payload_layer, "l2"))
11912                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11913         else if (!strcmp(res->payload_layer, "l3"))
11914                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11915         else if (!strcmp(res->payload_layer, "l4"))
11916                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11917
11918         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11919                             RTE_ETH_FDIR_MAX_FLEXLEN);
11920         if (ret < 0) {
11921                 printf("error: Cannot parse flex payload input.\n");
11922                 return;
11923         }
11924
11925         fdir_set_flex_payload(res->port_id, &flex_cfg);
11926         cmd_reconfig_device_queue(res->port_id, 1, 1);
11927 }
11928
11929 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11930         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11931                                  flow_director_flexpayload,
11932                                  "flow_director_flex_payload");
11933 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11934         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11935                               port_id, UINT16);
11936 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11937         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11938                                  payload_layer, "raw#l2#l3#l4");
11939 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11940         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11941                                  payload_cfg, NULL);
11942
11943 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11944         .f = cmd_flow_director_flxpld_parsed,
11945         .data = NULL,
11946         .help_str = "flow_director_flexpayload ... : "
11947                 "Set flow director's flex payload on NIC",
11948         .tokens = {
11949                 (void *)&cmd_flow_director_flexpayload,
11950                 (void *)&cmd_flow_director_flexpayload_port_id,
11951                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11952                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11953                 NULL,
11954         },
11955 };
11956
11957 /* Generic flow interface command. */
11958 extern cmdline_parse_inst_t cmd_flow;
11959
11960 /* *** Classification Filters Control *** */
11961 /* *** Get symmetric hash enable per port *** */
11962 struct cmd_get_sym_hash_ena_per_port_result {
11963         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11964         portid_t port_id;
11965 };
11966
11967 static void
11968 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11969                                  __rte_unused struct cmdline *cl,
11970                                  __rte_unused void *data)
11971 {
11972         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11973         struct rte_eth_hash_filter_info info;
11974         int ret;
11975
11976         if (rte_eth_dev_filter_supported(res->port_id,
11977                                 RTE_ETH_FILTER_HASH) < 0) {
11978                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11979                                                         res->port_id);
11980                 return;
11981         }
11982
11983         memset(&info, 0, sizeof(info));
11984         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11985         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11986                                                 RTE_ETH_FILTER_GET, &info);
11987
11988         if (ret < 0) {
11989                 printf("Cannot get symmetric hash enable per port "
11990                                         "on port %u\n", res->port_id);
11991                 return;
11992         }
11993
11994         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11995                                 "enabled" : "disabled", res->port_id);
11996 }
11997
11998 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11999         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12000                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12001 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12002         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12003                 port_id, UINT16);
12004
12005 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12006         .f = cmd_get_sym_hash_per_port_parsed,
12007         .data = NULL,
12008         .help_str = "get_sym_hash_ena_per_port <port_id>",
12009         .tokens = {
12010                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12011                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12012                 NULL,
12013         },
12014 };
12015
12016 /* *** Set symmetric hash enable per port *** */
12017 struct cmd_set_sym_hash_ena_per_port_result {
12018         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12019         cmdline_fixed_string_t enable;
12020         portid_t port_id;
12021 };
12022
12023 static void
12024 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12025                                  __rte_unused struct cmdline *cl,
12026                                  __rte_unused void *data)
12027 {
12028         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12029         struct rte_eth_hash_filter_info info;
12030         int ret;
12031
12032         if (rte_eth_dev_filter_supported(res->port_id,
12033                                 RTE_ETH_FILTER_HASH) < 0) {
12034                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12035                                                         res->port_id);
12036                 return;
12037         }
12038
12039         memset(&info, 0, sizeof(info));
12040         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12041         if (!strcmp(res->enable, "enable"))
12042                 info.info.enable = 1;
12043         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12044                                         RTE_ETH_FILTER_SET, &info);
12045         if (ret < 0) {
12046                 printf("Cannot set symmetric hash enable per port on "
12047                                         "port %u\n", res->port_id);
12048                 return;
12049         }
12050         printf("Symmetric hash has been set to %s on port %u\n",
12051                                         res->enable, res->port_id);
12052 }
12053
12054 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12055         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12056                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12057 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12058         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12059                 port_id, UINT16);
12060 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12061         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12062                 enable, "enable#disable");
12063
12064 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12065         .f = cmd_set_sym_hash_per_port_parsed,
12066         .data = NULL,
12067         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12068         .tokens = {
12069                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12070                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12071                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12072                 NULL,
12073         },
12074 };
12075
12076 /* Get global config of hash function */
12077 struct cmd_get_hash_global_config_result {
12078         cmdline_fixed_string_t get_hash_global_config;
12079         portid_t port_id;
12080 };
12081
12082 static char *
12083 flowtype_to_str(uint16_t ftype)
12084 {
12085         uint16_t i;
12086         static struct {
12087                 char str[16];
12088                 uint16_t ftype;
12089         } ftype_table[] = {
12090                 {"ipv4", RTE_ETH_FLOW_IPV4},
12091                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12092                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12093                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12094                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12095                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12096                 {"ipv6", RTE_ETH_FLOW_IPV6},
12097                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12098                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12099                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12100                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12101                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12102                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12103                 {"port", RTE_ETH_FLOW_PORT},
12104                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12105                 {"geneve", RTE_ETH_FLOW_GENEVE},
12106                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12107                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12108         };
12109
12110         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12111                 if (ftype_table[i].ftype == ftype)
12112                         return ftype_table[i].str;
12113         }
12114
12115         return NULL;
12116 }
12117
12118 static void
12119 cmd_get_hash_global_config_parsed(void *parsed_result,
12120                                   __rte_unused struct cmdline *cl,
12121                                   __rte_unused void *data)
12122 {
12123         struct cmd_get_hash_global_config_result *res = parsed_result;
12124         struct rte_eth_hash_filter_info info;
12125         uint32_t idx, offset;
12126         uint16_t i;
12127         char *str;
12128         int ret;
12129
12130         if (rte_eth_dev_filter_supported(res->port_id,
12131                         RTE_ETH_FILTER_HASH) < 0) {
12132                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12133                                                         res->port_id);
12134                 return;
12135         }
12136
12137         memset(&info, 0, sizeof(info));
12138         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12139         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12140                                         RTE_ETH_FILTER_GET, &info);
12141         if (ret < 0) {
12142                 printf("Cannot get hash global configurations by port %d\n",
12143                                                         res->port_id);
12144                 return;
12145         }
12146
12147         switch (info.info.global_conf.hash_func) {
12148         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12149                 printf("Hash function is Toeplitz\n");
12150                 break;
12151         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12152                 printf("Hash function is Simple XOR\n");
12153                 break;
12154         default:
12155                 printf("Unknown hash function\n");
12156                 break;
12157         }
12158
12159         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12160                 idx = i / UINT64_BIT;
12161                 offset = i % UINT64_BIT;
12162                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12163                                                 (1ULL << offset)))
12164                         continue;
12165                 str = flowtype_to_str(i);
12166                 if (!str)
12167                         continue;
12168                 printf("Symmetric hash is %s globally for flow type %s "
12169                                                         "by port %d\n",
12170                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12171                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12172                                                         res->port_id);
12173         }
12174 }
12175
12176 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12177         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12178                 get_hash_global_config, "get_hash_global_config");
12179 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12180         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12181                 port_id, UINT16);
12182
12183 cmdline_parse_inst_t cmd_get_hash_global_config = {
12184         .f = cmd_get_hash_global_config_parsed,
12185         .data = NULL,
12186         .help_str = "get_hash_global_config <port_id>",
12187         .tokens = {
12188                 (void *)&cmd_get_hash_global_config_all,
12189                 (void *)&cmd_get_hash_global_config_port_id,
12190                 NULL,
12191         },
12192 };
12193
12194 /* Set global config of hash function */
12195 struct cmd_set_hash_global_config_result {
12196         cmdline_fixed_string_t set_hash_global_config;
12197         portid_t port_id;
12198         cmdline_fixed_string_t hash_func;
12199         cmdline_fixed_string_t flow_type;
12200         cmdline_fixed_string_t enable;
12201 };
12202
12203 static void
12204 cmd_set_hash_global_config_parsed(void *parsed_result,
12205                                   __rte_unused struct cmdline *cl,
12206                                   __rte_unused void *data)
12207 {
12208         struct cmd_set_hash_global_config_result *res = parsed_result;
12209         struct rte_eth_hash_filter_info info;
12210         uint32_t ftype, idx, offset;
12211         int ret;
12212
12213         if (rte_eth_dev_filter_supported(res->port_id,
12214                                 RTE_ETH_FILTER_HASH) < 0) {
12215                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12216                                                         res->port_id);
12217                 return;
12218         }
12219         memset(&info, 0, sizeof(info));
12220         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12221         if (!strcmp(res->hash_func, "toeplitz"))
12222                 info.info.global_conf.hash_func =
12223                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12224         else if (!strcmp(res->hash_func, "simple_xor"))
12225                 info.info.global_conf.hash_func =
12226                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12227         else if (!strcmp(res->hash_func, "default"))
12228                 info.info.global_conf.hash_func =
12229                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12230
12231         ftype = str2flowtype(res->flow_type);
12232         idx = ftype / UINT64_BIT;
12233         offset = ftype % UINT64_BIT;
12234         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12235         if (!strcmp(res->enable, "enable"))
12236                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12237                                                 (1ULL << offset);
12238         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12239                                         RTE_ETH_FILTER_SET, &info);
12240         if (ret < 0)
12241                 printf("Cannot set global hash configurations by port %d\n",
12242                                                         res->port_id);
12243         else
12244                 printf("Global hash configurations have been set "
12245                         "successfully by port %d\n", res->port_id);
12246 }
12247
12248 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12249         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12250                 set_hash_global_config, "set_hash_global_config");
12251 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12252         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12253                 port_id, UINT16);
12254 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12255         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12256                 hash_func, "toeplitz#simple_xor#default");
12257 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12258         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12259                 flow_type,
12260                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12261                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12262 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12263         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12264                 enable, "enable#disable");
12265
12266 cmdline_parse_inst_t cmd_set_hash_global_config = {
12267         .f = cmd_set_hash_global_config_parsed,
12268         .data = NULL,
12269         .help_str = "set_hash_global_config <port_id> "
12270                 "toeplitz|simple_xor|default "
12271                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12272                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12273                 "l2_payload enable|disable",
12274         .tokens = {
12275                 (void *)&cmd_set_hash_global_config_all,
12276                 (void *)&cmd_set_hash_global_config_port_id,
12277                 (void *)&cmd_set_hash_global_config_hash_func,
12278                 (void *)&cmd_set_hash_global_config_flow_type,
12279                 (void *)&cmd_set_hash_global_config_enable,
12280                 NULL,
12281         },
12282 };
12283
12284 /* Set hash input set */
12285 struct cmd_set_hash_input_set_result {
12286         cmdline_fixed_string_t set_hash_input_set;
12287         portid_t port_id;
12288         cmdline_fixed_string_t flow_type;
12289         cmdline_fixed_string_t inset_field;
12290         cmdline_fixed_string_t select;
12291 };
12292
12293 static enum rte_eth_input_set_field
12294 str2inset(char *string)
12295 {
12296         uint16_t i;
12297
12298         static const struct {
12299                 char str[32];
12300                 enum rte_eth_input_set_field inset;
12301         } inset_table[] = {
12302                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12303                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12304                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12305                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12306                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12307                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12308                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12309                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12310                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12311                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12312                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12313                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12314                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12315                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12316                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12317                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12318                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12319                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12320                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12321                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12322                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12323                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12324                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12325                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12326                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12327                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12328                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12329                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12330                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12331                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12332                 {"none", RTE_ETH_INPUT_SET_NONE},
12333         };
12334
12335         for (i = 0; i < RTE_DIM(inset_table); i++) {
12336                 if (!strcmp(string, inset_table[i].str))
12337                         return inset_table[i].inset;
12338         }
12339
12340         return RTE_ETH_INPUT_SET_UNKNOWN;
12341 }
12342
12343 static void
12344 cmd_set_hash_input_set_parsed(void *parsed_result,
12345                               __rte_unused struct cmdline *cl,
12346                               __rte_unused void *data)
12347 {
12348         struct cmd_set_hash_input_set_result *res = parsed_result;
12349         struct rte_eth_hash_filter_info info;
12350
12351         memset(&info, 0, sizeof(info));
12352         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12353         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12354         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12355         info.info.input_set_conf.inset_size = 1;
12356         if (!strcmp(res->select, "select"))
12357                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12358         else if (!strcmp(res->select, "add"))
12359                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12360         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12361                                 RTE_ETH_FILTER_SET, &info);
12362 }
12363
12364 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12365         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12366                 set_hash_input_set, "set_hash_input_set");
12367 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12368         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12369                 port_id, UINT16);
12370 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12371         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12372                 flow_type, NULL);
12373 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12374         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12375                 inset_field,
12376                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12377                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12378                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12379                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12380                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12381                 "fld-8th#none");
12382 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12383         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12384                 select, "select#add");
12385
12386 cmdline_parse_inst_t cmd_set_hash_input_set = {
12387         .f = cmd_set_hash_input_set_parsed,
12388         .data = NULL,
12389         .help_str = "set_hash_input_set <port_id> "
12390         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12391         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12392         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12393         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12394         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12395         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12396         "fld-7th|fld-8th|none select|add",
12397         .tokens = {
12398                 (void *)&cmd_set_hash_input_set_cmd,
12399                 (void *)&cmd_set_hash_input_set_port_id,
12400                 (void *)&cmd_set_hash_input_set_flow_type,
12401                 (void *)&cmd_set_hash_input_set_field,
12402                 (void *)&cmd_set_hash_input_set_select,
12403                 NULL,
12404         },
12405 };
12406
12407 /* Set flow director input set */
12408 struct cmd_set_fdir_input_set_result {
12409         cmdline_fixed_string_t set_fdir_input_set;
12410         portid_t port_id;
12411         cmdline_fixed_string_t flow_type;
12412         cmdline_fixed_string_t inset_field;
12413         cmdline_fixed_string_t select;
12414 };
12415
12416 static void
12417 cmd_set_fdir_input_set_parsed(void *parsed_result,
12418         __rte_unused struct cmdline *cl,
12419         __rte_unused void *data)
12420 {
12421         struct cmd_set_fdir_input_set_result *res = parsed_result;
12422         struct rte_eth_fdir_filter_info info;
12423
12424         memset(&info, 0, sizeof(info));
12425         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12426         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12427         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12428         info.info.input_set_conf.inset_size = 1;
12429         if (!strcmp(res->select, "select"))
12430                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12431         else if (!strcmp(res->select, "add"))
12432                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12433         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12434                 RTE_ETH_FILTER_SET, &info);
12435 }
12436
12437 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12438         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12439         set_fdir_input_set, "set_fdir_input_set");
12440 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12441         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12442         port_id, UINT16);
12443 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12444         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12445         flow_type,
12446         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12447         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12448 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12449         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12450         inset_field,
12451         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12452         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12453         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12454         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12455         "sctp-veri-tag#none");
12456 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12457         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12458         select, "select#add");
12459
12460 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12461         .f = cmd_set_fdir_input_set_parsed,
12462         .data = NULL,
12463         .help_str = "set_fdir_input_set <port_id> "
12464         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12465         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12466         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12467         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12468         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12469         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12470         "sctp-veri-tag|none select|add",
12471         .tokens = {
12472                 (void *)&cmd_set_fdir_input_set_cmd,
12473                 (void *)&cmd_set_fdir_input_set_port_id,
12474                 (void *)&cmd_set_fdir_input_set_flow_type,
12475                 (void *)&cmd_set_fdir_input_set_field,
12476                 (void *)&cmd_set_fdir_input_set_select,
12477                 NULL,
12478         },
12479 };
12480
12481 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12482 struct cmd_mcast_addr_result {
12483         cmdline_fixed_string_t mcast_addr_cmd;
12484         cmdline_fixed_string_t what;
12485         uint16_t port_num;
12486         struct rte_ether_addr mc_addr;
12487 };
12488
12489 static void cmd_mcast_addr_parsed(void *parsed_result,
12490                 __attribute__((unused)) struct cmdline *cl,
12491                 __attribute__((unused)) void *data)
12492 {
12493         struct cmd_mcast_addr_result *res = parsed_result;
12494
12495         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12496                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12497                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12498                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12499                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12500                 return;
12501         }
12502         if (strcmp(res->what, "add") == 0)
12503                 mcast_addr_add(res->port_num, &res->mc_addr);
12504         else
12505                 mcast_addr_remove(res->port_num, &res->mc_addr);
12506 }
12507
12508 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12509         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12510                                  mcast_addr_cmd, "mcast_addr");
12511 cmdline_parse_token_string_t cmd_mcast_addr_what =
12512         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12513                                  "add#remove");
12514 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12515         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12516 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12517         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12518
12519 cmdline_parse_inst_t cmd_mcast_addr = {
12520         .f = cmd_mcast_addr_parsed,
12521         .data = (void *)0,
12522         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12523                 "Add/Remove multicast MAC address on port_id",
12524         .tokens = {
12525                 (void *)&cmd_mcast_addr_cmd,
12526                 (void *)&cmd_mcast_addr_what,
12527                 (void *)&cmd_mcast_addr_portnum,
12528                 (void *)&cmd_mcast_addr_addr,
12529                 NULL,
12530         },
12531 };
12532
12533 /* l2 tunnel config
12534  * only support E-tag now.
12535  */
12536
12537 /* Ether type config */
12538 struct cmd_config_l2_tunnel_eth_type_result {
12539         cmdline_fixed_string_t port;
12540         cmdline_fixed_string_t config;
12541         cmdline_fixed_string_t all;
12542         portid_t id;
12543         cmdline_fixed_string_t l2_tunnel;
12544         cmdline_fixed_string_t l2_tunnel_type;
12545         cmdline_fixed_string_t eth_type;
12546         uint16_t eth_type_val;
12547 };
12548
12549 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12550         TOKEN_STRING_INITIALIZER
12551                 (struct cmd_config_l2_tunnel_eth_type_result,
12552                  port, "port");
12553 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12554         TOKEN_STRING_INITIALIZER
12555                 (struct cmd_config_l2_tunnel_eth_type_result,
12556                  config, "config");
12557 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12558         TOKEN_STRING_INITIALIZER
12559                 (struct cmd_config_l2_tunnel_eth_type_result,
12560                  all, "all");
12561 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12562         TOKEN_NUM_INITIALIZER
12563                 (struct cmd_config_l2_tunnel_eth_type_result,
12564                  id, UINT16);
12565 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12566         TOKEN_STRING_INITIALIZER
12567                 (struct cmd_config_l2_tunnel_eth_type_result,
12568                  l2_tunnel, "l2-tunnel");
12569 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12570         TOKEN_STRING_INITIALIZER
12571                 (struct cmd_config_l2_tunnel_eth_type_result,
12572                  l2_tunnel_type, "E-tag");
12573 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12574         TOKEN_STRING_INITIALIZER
12575                 (struct cmd_config_l2_tunnel_eth_type_result,
12576                  eth_type, "ether-type");
12577 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12578         TOKEN_NUM_INITIALIZER
12579                 (struct cmd_config_l2_tunnel_eth_type_result,
12580                  eth_type_val, UINT16);
12581
12582 static enum rte_eth_tunnel_type
12583 str2fdir_l2_tunnel_type(char *string)
12584 {
12585         uint32_t i = 0;
12586
12587         static const struct {
12588                 char str[32];
12589                 enum rte_eth_tunnel_type type;
12590         } l2_tunnel_type_str[] = {
12591                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12592         };
12593
12594         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12595                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12596                         return l2_tunnel_type_str[i].type;
12597         }
12598         return RTE_TUNNEL_TYPE_NONE;
12599 }
12600
12601 /* ether type config for all ports */
12602 static void
12603 cmd_config_l2_tunnel_eth_type_all_parsed
12604         (void *parsed_result,
12605          __attribute__((unused)) struct cmdline *cl,
12606          __attribute__((unused)) void *data)
12607 {
12608         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12609         struct rte_eth_l2_tunnel_conf entry;
12610         portid_t pid;
12611
12612         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12613         entry.ether_type = res->eth_type_val;
12614
12615         RTE_ETH_FOREACH_DEV(pid) {
12616                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12617         }
12618 }
12619
12620 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12621         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12622         .data = NULL,
12623         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12624         .tokens = {
12625                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12626                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12627                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12628                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12629                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12630                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12631                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12632                 NULL,
12633         },
12634 };
12635
12636 /* ether type config for a specific port */
12637 static void
12638 cmd_config_l2_tunnel_eth_type_specific_parsed(
12639         void *parsed_result,
12640         __attribute__((unused)) struct cmdline *cl,
12641         __attribute__((unused)) void *data)
12642 {
12643         struct cmd_config_l2_tunnel_eth_type_result *res =
12644                  parsed_result;
12645         struct rte_eth_l2_tunnel_conf entry;
12646
12647         if (port_id_is_invalid(res->id, ENABLED_WARN))
12648                 return;
12649
12650         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12651         entry.ether_type = res->eth_type_val;
12652
12653         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12654 }
12655
12656 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12657         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12658         .data = NULL,
12659         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12660         .tokens = {
12661                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12662                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12663                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12664                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12665                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12666                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12667                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12668                 NULL,
12669         },
12670 };
12671
12672 /* Enable/disable l2 tunnel */
12673 struct cmd_config_l2_tunnel_en_dis_result {
12674         cmdline_fixed_string_t port;
12675         cmdline_fixed_string_t config;
12676         cmdline_fixed_string_t all;
12677         portid_t id;
12678         cmdline_fixed_string_t l2_tunnel;
12679         cmdline_fixed_string_t l2_tunnel_type;
12680         cmdline_fixed_string_t en_dis;
12681 };
12682
12683 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12684         TOKEN_STRING_INITIALIZER
12685                 (struct cmd_config_l2_tunnel_en_dis_result,
12686                  port, "port");
12687 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12688         TOKEN_STRING_INITIALIZER
12689                 (struct cmd_config_l2_tunnel_en_dis_result,
12690                  config, "config");
12691 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12692         TOKEN_STRING_INITIALIZER
12693                 (struct cmd_config_l2_tunnel_en_dis_result,
12694                  all, "all");
12695 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12696         TOKEN_NUM_INITIALIZER
12697                 (struct cmd_config_l2_tunnel_en_dis_result,
12698                  id, UINT16);
12699 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12700         TOKEN_STRING_INITIALIZER
12701                 (struct cmd_config_l2_tunnel_en_dis_result,
12702                  l2_tunnel, "l2-tunnel");
12703 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12704         TOKEN_STRING_INITIALIZER
12705                 (struct cmd_config_l2_tunnel_en_dis_result,
12706                  l2_tunnel_type, "E-tag");
12707 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12708         TOKEN_STRING_INITIALIZER
12709                 (struct cmd_config_l2_tunnel_en_dis_result,
12710                  en_dis, "enable#disable");
12711
12712 /* enable/disable l2 tunnel for all ports */
12713 static void
12714 cmd_config_l2_tunnel_en_dis_all_parsed(
12715         void *parsed_result,
12716         __attribute__((unused)) struct cmdline *cl,
12717         __attribute__((unused)) void *data)
12718 {
12719         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12720         struct rte_eth_l2_tunnel_conf entry;
12721         portid_t pid;
12722         uint8_t en;
12723
12724         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12725
12726         if (!strcmp("enable", res->en_dis))
12727                 en = 1;
12728         else
12729                 en = 0;
12730
12731         RTE_ETH_FOREACH_DEV(pid) {
12732                 rte_eth_dev_l2_tunnel_offload_set(pid,
12733                                                   &entry,
12734                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12735                                                   en);
12736         }
12737 }
12738
12739 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12740         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12741         .data = NULL,
12742         .help_str = "port config all l2-tunnel E-tag enable|disable",
12743         .tokens = {
12744                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12745                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12746                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12747                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12748                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12749                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12750                 NULL,
12751         },
12752 };
12753
12754 /* enable/disable l2 tunnel for a port */
12755 static void
12756 cmd_config_l2_tunnel_en_dis_specific_parsed(
12757         void *parsed_result,
12758         __attribute__((unused)) struct cmdline *cl,
12759         __attribute__((unused)) void *data)
12760 {
12761         struct cmd_config_l2_tunnel_en_dis_result *res =
12762                 parsed_result;
12763         struct rte_eth_l2_tunnel_conf entry;
12764
12765         if (port_id_is_invalid(res->id, ENABLED_WARN))
12766                 return;
12767
12768         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12769
12770         if (!strcmp("enable", res->en_dis))
12771                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12772                                                   &entry,
12773                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12774                                                   1);
12775         else
12776                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12777                                                   &entry,
12778                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12779                                                   0);
12780 }
12781
12782 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12783         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12784         .data = NULL,
12785         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12786         .tokens = {
12787                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12788                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12789                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12790                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12791                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12792                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12793                 NULL,
12794         },
12795 };
12796
12797 /* E-tag configuration */
12798
12799 /* Common result structure for all E-tag configuration */
12800 struct cmd_config_e_tag_result {
12801         cmdline_fixed_string_t e_tag;
12802         cmdline_fixed_string_t set;
12803         cmdline_fixed_string_t insertion;
12804         cmdline_fixed_string_t stripping;
12805         cmdline_fixed_string_t forwarding;
12806         cmdline_fixed_string_t filter;
12807         cmdline_fixed_string_t add;
12808         cmdline_fixed_string_t del;
12809         cmdline_fixed_string_t on;
12810         cmdline_fixed_string_t off;
12811         cmdline_fixed_string_t on_off;
12812         cmdline_fixed_string_t port_tag_id;
12813         uint32_t port_tag_id_val;
12814         cmdline_fixed_string_t e_tag_id;
12815         uint16_t e_tag_id_val;
12816         cmdline_fixed_string_t dst_pool;
12817         uint8_t dst_pool_val;
12818         cmdline_fixed_string_t port;
12819         portid_t port_id;
12820         cmdline_fixed_string_t vf;
12821         uint8_t vf_id;
12822 };
12823
12824 /* Common CLI fields for all E-tag configuration */
12825 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12826         TOKEN_STRING_INITIALIZER
12827                 (struct cmd_config_e_tag_result,
12828                  e_tag, "E-tag");
12829 cmdline_parse_token_string_t cmd_config_e_tag_set =
12830         TOKEN_STRING_INITIALIZER
12831                 (struct cmd_config_e_tag_result,
12832                  set, "set");
12833 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12834         TOKEN_STRING_INITIALIZER
12835                 (struct cmd_config_e_tag_result,
12836                  insertion, "insertion");
12837 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_config_e_tag_result,
12840                  stripping, "stripping");
12841 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12842         TOKEN_STRING_INITIALIZER
12843                 (struct cmd_config_e_tag_result,
12844                  forwarding, "forwarding");
12845 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12846         TOKEN_STRING_INITIALIZER
12847                 (struct cmd_config_e_tag_result,
12848                  filter, "filter");
12849 cmdline_parse_token_string_t cmd_config_e_tag_add =
12850         TOKEN_STRING_INITIALIZER
12851                 (struct cmd_config_e_tag_result,
12852                  add, "add");
12853 cmdline_parse_token_string_t cmd_config_e_tag_del =
12854         TOKEN_STRING_INITIALIZER
12855                 (struct cmd_config_e_tag_result,
12856                  del, "del");
12857 cmdline_parse_token_string_t cmd_config_e_tag_on =
12858         TOKEN_STRING_INITIALIZER
12859                 (struct cmd_config_e_tag_result,
12860                  on, "on");
12861 cmdline_parse_token_string_t cmd_config_e_tag_off =
12862         TOKEN_STRING_INITIALIZER
12863                 (struct cmd_config_e_tag_result,
12864                  off, "off");
12865 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12866         TOKEN_STRING_INITIALIZER
12867                 (struct cmd_config_e_tag_result,
12868                  on_off, "on#off");
12869 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12870         TOKEN_STRING_INITIALIZER
12871                 (struct cmd_config_e_tag_result,
12872                  port_tag_id, "port-tag-id");
12873 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12874         TOKEN_NUM_INITIALIZER
12875                 (struct cmd_config_e_tag_result,
12876                  port_tag_id_val, UINT32);
12877 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12878         TOKEN_STRING_INITIALIZER
12879                 (struct cmd_config_e_tag_result,
12880                  e_tag_id, "e-tag-id");
12881 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12882         TOKEN_NUM_INITIALIZER
12883                 (struct cmd_config_e_tag_result,
12884                  e_tag_id_val, UINT16);
12885 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12886         TOKEN_STRING_INITIALIZER
12887                 (struct cmd_config_e_tag_result,
12888                  dst_pool, "dst-pool");
12889 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12890         TOKEN_NUM_INITIALIZER
12891                 (struct cmd_config_e_tag_result,
12892                  dst_pool_val, UINT8);
12893 cmdline_parse_token_string_t cmd_config_e_tag_port =
12894         TOKEN_STRING_INITIALIZER
12895                 (struct cmd_config_e_tag_result,
12896                  port, "port");
12897 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12898         TOKEN_NUM_INITIALIZER
12899                 (struct cmd_config_e_tag_result,
12900                  port_id, UINT16);
12901 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12902         TOKEN_STRING_INITIALIZER
12903                 (struct cmd_config_e_tag_result,
12904                  vf, "vf");
12905 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12906         TOKEN_NUM_INITIALIZER
12907                 (struct cmd_config_e_tag_result,
12908                  vf_id, UINT8);
12909
12910 /* E-tag insertion configuration */
12911 static void
12912 cmd_config_e_tag_insertion_en_parsed(
12913         void *parsed_result,
12914         __attribute__((unused)) struct cmdline *cl,
12915         __attribute__((unused)) void *data)
12916 {
12917         struct cmd_config_e_tag_result *res =
12918                 parsed_result;
12919         struct rte_eth_l2_tunnel_conf entry;
12920
12921         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12922                 return;
12923
12924         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12925         entry.tunnel_id = res->port_tag_id_val;
12926         entry.vf_id = res->vf_id;
12927         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12928                                           &entry,
12929                                           ETH_L2_TUNNEL_INSERTION_MASK,
12930                                           1);
12931 }
12932
12933 static void
12934 cmd_config_e_tag_insertion_dis_parsed(
12935         void *parsed_result,
12936         __attribute__((unused)) struct cmdline *cl,
12937         __attribute__((unused)) void *data)
12938 {
12939         struct cmd_config_e_tag_result *res =
12940                 parsed_result;
12941         struct rte_eth_l2_tunnel_conf entry;
12942
12943         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12944                 return;
12945
12946         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12947         entry.vf_id = res->vf_id;
12948
12949         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12950                                           &entry,
12951                                           ETH_L2_TUNNEL_INSERTION_MASK,
12952                                           0);
12953 }
12954
12955 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12956         .f = cmd_config_e_tag_insertion_en_parsed,
12957         .data = NULL,
12958         .help_str = "E-tag ... : E-tag insertion enable",
12959         .tokens = {
12960                 (void *)&cmd_config_e_tag_e_tag,
12961                 (void *)&cmd_config_e_tag_set,
12962                 (void *)&cmd_config_e_tag_insertion,
12963                 (void *)&cmd_config_e_tag_on,
12964                 (void *)&cmd_config_e_tag_port_tag_id,
12965                 (void *)&cmd_config_e_tag_port_tag_id_val,
12966                 (void *)&cmd_config_e_tag_port,
12967                 (void *)&cmd_config_e_tag_port_id,
12968                 (void *)&cmd_config_e_tag_vf,
12969                 (void *)&cmd_config_e_tag_vf_id,
12970                 NULL,
12971         },
12972 };
12973
12974 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12975         .f = cmd_config_e_tag_insertion_dis_parsed,
12976         .data = NULL,
12977         .help_str = "E-tag ... : E-tag insertion disable",
12978         .tokens = {
12979                 (void *)&cmd_config_e_tag_e_tag,
12980                 (void *)&cmd_config_e_tag_set,
12981                 (void *)&cmd_config_e_tag_insertion,
12982                 (void *)&cmd_config_e_tag_off,
12983                 (void *)&cmd_config_e_tag_port,
12984                 (void *)&cmd_config_e_tag_port_id,
12985                 (void *)&cmd_config_e_tag_vf,
12986                 (void *)&cmd_config_e_tag_vf_id,
12987                 NULL,
12988         },
12989 };
12990
12991 /* E-tag stripping configuration */
12992 static void
12993 cmd_config_e_tag_stripping_parsed(
12994         void *parsed_result,
12995         __attribute__((unused)) struct cmdline *cl,
12996         __attribute__((unused)) void *data)
12997 {
12998         struct cmd_config_e_tag_result *res =
12999                 parsed_result;
13000         struct rte_eth_l2_tunnel_conf entry;
13001
13002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13003                 return;
13004
13005         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13006
13007         if (!strcmp(res->on_off, "on"))
13008                 rte_eth_dev_l2_tunnel_offload_set
13009                         (res->port_id,
13010                          &entry,
13011                          ETH_L2_TUNNEL_STRIPPING_MASK,
13012                          1);
13013         else
13014                 rte_eth_dev_l2_tunnel_offload_set
13015                         (res->port_id,
13016                          &entry,
13017                          ETH_L2_TUNNEL_STRIPPING_MASK,
13018                          0);
13019 }
13020
13021 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13022         .f = cmd_config_e_tag_stripping_parsed,
13023         .data = NULL,
13024         .help_str = "E-tag ... : E-tag stripping enable/disable",
13025         .tokens = {
13026                 (void *)&cmd_config_e_tag_e_tag,
13027                 (void *)&cmd_config_e_tag_set,
13028                 (void *)&cmd_config_e_tag_stripping,
13029                 (void *)&cmd_config_e_tag_on_off,
13030                 (void *)&cmd_config_e_tag_port,
13031                 (void *)&cmd_config_e_tag_port_id,
13032                 NULL,
13033         },
13034 };
13035
13036 /* E-tag forwarding configuration */
13037 static void
13038 cmd_config_e_tag_forwarding_parsed(
13039         void *parsed_result,
13040         __attribute__((unused)) struct cmdline *cl,
13041         __attribute__((unused)) void *data)
13042 {
13043         struct cmd_config_e_tag_result *res = parsed_result;
13044         struct rte_eth_l2_tunnel_conf entry;
13045
13046         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13047                 return;
13048
13049         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13050
13051         if (!strcmp(res->on_off, "on"))
13052                 rte_eth_dev_l2_tunnel_offload_set
13053                         (res->port_id,
13054                          &entry,
13055                          ETH_L2_TUNNEL_FORWARDING_MASK,
13056                          1);
13057         else
13058                 rte_eth_dev_l2_tunnel_offload_set
13059                         (res->port_id,
13060                          &entry,
13061                          ETH_L2_TUNNEL_FORWARDING_MASK,
13062                          0);
13063 }
13064
13065 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13066         .f = cmd_config_e_tag_forwarding_parsed,
13067         .data = NULL,
13068         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13069         .tokens = {
13070                 (void *)&cmd_config_e_tag_e_tag,
13071                 (void *)&cmd_config_e_tag_set,
13072                 (void *)&cmd_config_e_tag_forwarding,
13073                 (void *)&cmd_config_e_tag_on_off,
13074                 (void *)&cmd_config_e_tag_port,
13075                 (void *)&cmd_config_e_tag_port_id,
13076                 NULL,
13077         },
13078 };
13079
13080 /* E-tag filter configuration */
13081 static void
13082 cmd_config_e_tag_filter_add_parsed(
13083         void *parsed_result,
13084         __attribute__((unused)) struct cmdline *cl,
13085         __attribute__((unused)) void *data)
13086 {
13087         struct cmd_config_e_tag_result *res = parsed_result;
13088         struct rte_eth_l2_tunnel_conf entry;
13089         int ret = 0;
13090
13091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13092                 return;
13093
13094         if (res->e_tag_id_val > 0x3fff) {
13095                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13096                 return;
13097         }
13098
13099         ret = rte_eth_dev_filter_supported(res->port_id,
13100                                            RTE_ETH_FILTER_L2_TUNNEL);
13101         if (ret < 0) {
13102                 printf("E-tag filter is not supported on port %u.\n",
13103                        res->port_id);
13104                 return;
13105         }
13106
13107         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13108         entry.tunnel_id = res->e_tag_id_val;
13109         entry.pool = res->dst_pool_val;
13110
13111         ret = rte_eth_dev_filter_ctrl(res->port_id,
13112                                       RTE_ETH_FILTER_L2_TUNNEL,
13113                                       RTE_ETH_FILTER_ADD,
13114                                       &entry);
13115         if (ret < 0)
13116                 printf("E-tag filter programming error: (%s)\n",
13117                        strerror(-ret));
13118 }
13119
13120 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13121         .f = cmd_config_e_tag_filter_add_parsed,
13122         .data = NULL,
13123         .help_str = "E-tag ... : E-tag filter add",
13124         .tokens = {
13125                 (void *)&cmd_config_e_tag_e_tag,
13126                 (void *)&cmd_config_e_tag_set,
13127                 (void *)&cmd_config_e_tag_filter,
13128                 (void *)&cmd_config_e_tag_add,
13129                 (void *)&cmd_config_e_tag_e_tag_id,
13130                 (void *)&cmd_config_e_tag_e_tag_id_val,
13131                 (void *)&cmd_config_e_tag_dst_pool,
13132                 (void *)&cmd_config_e_tag_dst_pool_val,
13133                 (void *)&cmd_config_e_tag_port,
13134                 (void *)&cmd_config_e_tag_port_id,
13135                 NULL,
13136         },
13137 };
13138
13139 static void
13140 cmd_config_e_tag_filter_del_parsed(
13141         void *parsed_result,
13142         __attribute__((unused)) struct cmdline *cl,
13143         __attribute__((unused)) void *data)
13144 {
13145         struct cmd_config_e_tag_result *res = parsed_result;
13146         struct rte_eth_l2_tunnel_conf entry;
13147         int ret = 0;
13148
13149         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13150                 return;
13151
13152         if (res->e_tag_id_val > 0x3fff) {
13153                 printf("e-tag-id must be less than 0x3fff.\n");
13154                 return;
13155         }
13156
13157         ret = rte_eth_dev_filter_supported(res->port_id,
13158                                            RTE_ETH_FILTER_L2_TUNNEL);
13159         if (ret < 0) {
13160                 printf("E-tag filter is not supported on port %u.\n",
13161                        res->port_id);
13162                 return;
13163         }
13164
13165         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13166         entry.tunnel_id = res->e_tag_id_val;
13167
13168         ret = rte_eth_dev_filter_ctrl(res->port_id,
13169                                       RTE_ETH_FILTER_L2_TUNNEL,
13170                                       RTE_ETH_FILTER_DELETE,
13171                                       &entry);
13172         if (ret < 0)
13173                 printf("E-tag filter programming error: (%s)\n",
13174                        strerror(-ret));
13175 }
13176
13177 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13178         .f = cmd_config_e_tag_filter_del_parsed,
13179         .data = NULL,
13180         .help_str = "E-tag ... : E-tag filter delete",
13181         .tokens = {
13182                 (void *)&cmd_config_e_tag_e_tag,
13183                 (void *)&cmd_config_e_tag_set,
13184                 (void *)&cmd_config_e_tag_filter,
13185                 (void *)&cmd_config_e_tag_del,
13186                 (void *)&cmd_config_e_tag_e_tag_id,
13187                 (void *)&cmd_config_e_tag_e_tag_id_val,
13188                 (void *)&cmd_config_e_tag_port,
13189                 (void *)&cmd_config_e_tag_port_id,
13190                 NULL,
13191         },
13192 };
13193
13194 /* vf vlan anti spoof configuration */
13195
13196 /* Common result structure for vf vlan anti spoof */
13197 struct cmd_vf_vlan_anti_spoof_result {
13198         cmdline_fixed_string_t set;
13199         cmdline_fixed_string_t vf;
13200         cmdline_fixed_string_t vlan;
13201         cmdline_fixed_string_t antispoof;
13202         portid_t port_id;
13203         uint32_t vf_id;
13204         cmdline_fixed_string_t on_off;
13205 };
13206
13207 /* Common CLI fields for vf vlan anti spoof enable disable */
13208 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13209         TOKEN_STRING_INITIALIZER
13210                 (struct cmd_vf_vlan_anti_spoof_result,
13211                  set, "set");
13212 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_vf_vlan_anti_spoof_result,
13215                  vf, "vf");
13216 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13217         TOKEN_STRING_INITIALIZER
13218                 (struct cmd_vf_vlan_anti_spoof_result,
13219                  vlan, "vlan");
13220 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13221         TOKEN_STRING_INITIALIZER
13222                 (struct cmd_vf_vlan_anti_spoof_result,
13223                  antispoof, "antispoof");
13224 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13225         TOKEN_NUM_INITIALIZER
13226                 (struct cmd_vf_vlan_anti_spoof_result,
13227                  port_id, UINT16);
13228 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13229         TOKEN_NUM_INITIALIZER
13230                 (struct cmd_vf_vlan_anti_spoof_result,
13231                  vf_id, UINT32);
13232 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13233         TOKEN_STRING_INITIALIZER
13234                 (struct cmd_vf_vlan_anti_spoof_result,
13235                  on_off, "on#off");
13236
13237 static void
13238 cmd_set_vf_vlan_anti_spoof_parsed(
13239         void *parsed_result,
13240         __attribute__((unused)) struct cmdline *cl,
13241         __attribute__((unused)) void *data)
13242 {
13243         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13244         int ret = -ENOTSUP;
13245
13246         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13247
13248         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13249                 return;
13250
13251 #ifdef RTE_LIBRTE_IXGBE_PMD
13252         if (ret == -ENOTSUP)
13253                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13254                                 res->vf_id, is_on);
13255 #endif
13256 #ifdef RTE_LIBRTE_I40E_PMD
13257         if (ret == -ENOTSUP)
13258                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13259                                 res->vf_id, is_on);
13260 #endif
13261 #ifdef RTE_LIBRTE_BNXT_PMD
13262         if (ret == -ENOTSUP)
13263                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13264                                 res->vf_id, is_on);
13265 #endif
13266
13267         switch (ret) {
13268         case 0:
13269                 break;
13270         case -EINVAL:
13271                 printf("invalid vf_id %d\n", res->vf_id);
13272                 break;
13273         case -ENODEV:
13274                 printf("invalid port_id %d\n", res->port_id);
13275                 break;
13276         case -ENOTSUP:
13277                 printf("function not implemented\n");
13278                 break;
13279         default:
13280                 printf("programming error: (%s)\n", strerror(-ret));
13281         }
13282 }
13283
13284 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13285         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13286         .data = NULL,
13287         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13288         .tokens = {
13289                 (void *)&cmd_vf_vlan_anti_spoof_set,
13290                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13291                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13292                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13293                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13294                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13295                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13296                 NULL,
13297         },
13298 };
13299
13300 /* vf mac anti spoof configuration */
13301
13302 /* Common result structure for vf mac anti spoof */
13303 struct cmd_vf_mac_anti_spoof_result {
13304         cmdline_fixed_string_t set;
13305         cmdline_fixed_string_t vf;
13306         cmdline_fixed_string_t mac;
13307         cmdline_fixed_string_t antispoof;
13308         portid_t port_id;
13309         uint32_t vf_id;
13310         cmdline_fixed_string_t on_off;
13311 };
13312
13313 /* Common CLI fields for vf mac anti spoof enable disable */
13314 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13315         TOKEN_STRING_INITIALIZER
13316                 (struct cmd_vf_mac_anti_spoof_result,
13317                  set, "set");
13318 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_vf_mac_anti_spoof_result,
13321                  vf, "vf");
13322 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13323         TOKEN_STRING_INITIALIZER
13324                 (struct cmd_vf_mac_anti_spoof_result,
13325                  mac, "mac");
13326 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13327         TOKEN_STRING_INITIALIZER
13328                 (struct cmd_vf_mac_anti_spoof_result,
13329                  antispoof, "antispoof");
13330 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13331         TOKEN_NUM_INITIALIZER
13332                 (struct cmd_vf_mac_anti_spoof_result,
13333                  port_id, UINT16);
13334 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13335         TOKEN_NUM_INITIALIZER
13336                 (struct cmd_vf_mac_anti_spoof_result,
13337                  vf_id, UINT32);
13338 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13339         TOKEN_STRING_INITIALIZER
13340                 (struct cmd_vf_mac_anti_spoof_result,
13341                  on_off, "on#off");
13342
13343 static void
13344 cmd_set_vf_mac_anti_spoof_parsed(
13345         void *parsed_result,
13346         __attribute__((unused)) struct cmdline *cl,
13347         __attribute__((unused)) void *data)
13348 {
13349         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13350         int ret = -ENOTSUP;
13351
13352         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13353
13354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13355                 return;
13356
13357 #ifdef RTE_LIBRTE_IXGBE_PMD
13358         if (ret == -ENOTSUP)
13359                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13360                         res->vf_id, is_on);
13361 #endif
13362 #ifdef RTE_LIBRTE_I40E_PMD
13363         if (ret == -ENOTSUP)
13364                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13365                         res->vf_id, is_on);
13366 #endif
13367 #ifdef RTE_LIBRTE_BNXT_PMD
13368         if (ret == -ENOTSUP)
13369                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13370                         res->vf_id, is_on);
13371 #endif
13372
13373         switch (ret) {
13374         case 0:
13375                 break;
13376         case -EINVAL:
13377                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13378                 break;
13379         case -ENODEV:
13380                 printf("invalid port_id %d\n", res->port_id);
13381                 break;
13382         case -ENOTSUP:
13383                 printf("function not implemented\n");
13384                 break;
13385         default:
13386                 printf("programming error: (%s)\n", strerror(-ret));
13387         }
13388 }
13389
13390 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13391         .f = cmd_set_vf_mac_anti_spoof_parsed,
13392         .data = NULL,
13393         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13394         .tokens = {
13395                 (void *)&cmd_vf_mac_anti_spoof_set,
13396                 (void *)&cmd_vf_mac_anti_spoof_vf,
13397                 (void *)&cmd_vf_mac_anti_spoof_mac,
13398                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13399                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13400                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13401                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13402                 NULL,
13403         },
13404 };
13405
13406 /* vf vlan strip queue configuration */
13407
13408 /* Common result structure for vf mac anti spoof */
13409 struct cmd_vf_vlan_stripq_result {
13410         cmdline_fixed_string_t set;
13411         cmdline_fixed_string_t vf;
13412         cmdline_fixed_string_t vlan;
13413         cmdline_fixed_string_t stripq;
13414         portid_t port_id;
13415         uint16_t vf_id;
13416         cmdline_fixed_string_t on_off;
13417 };
13418
13419 /* Common CLI fields for vf vlan strip enable disable */
13420 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13421         TOKEN_STRING_INITIALIZER
13422                 (struct cmd_vf_vlan_stripq_result,
13423                  set, "set");
13424 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13425         TOKEN_STRING_INITIALIZER
13426                 (struct cmd_vf_vlan_stripq_result,
13427                  vf, "vf");
13428 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13429         TOKEN_STRING_INITIALIZER
13430                 (struct cmd_vf_vlan_stripq_result,
13431                  vlan, "vlan");
13432 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13433         TOKEN_STRING_INITIALIZER
13434                 (struct cmd_vf_vlan_stripq_result,
13435                  stripq, "stripq");
13436 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13437         TOKEN_NUM_INITIALIZER
13438                 (struct cmd_vf_vlan_stripq_result,
13439                  port_id, UINT16);
13440 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13441         TOKEN_NUM_INITIALIZER
13442                 (struct cmd_vf_vlan_stripq_result,
13443                  vf_id, UINT16);
13444 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13445         TOKEN_STRING_INITIALIZER
13446                 (struct cmd_vf_vlan_stripq_result,
13447                  on_off, "on#off");
13448
13449 static void
13450 cmd_set_vf_vlan_stripq_parsed(
13451         void *parsed_result,
13452         __attribute__((unused)) struct cmdline *cl,
13453         __attribute__((unused)) void *data)
13454 {
13455         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13456         int ret = -ENOTSUP;
13457
13458         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13459
13460         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13461                 return;
13462
13463 #ifdef RTE_LIBRTE_IXGBE_PMD
13464         if (ret == -ENOTSUP)
13465                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13466                         res->vf_id, is_on);
13467 #endif
13468 #ifdef RTE_LIBRTE_I40E_PMD
13469         if (ret == -ENOTSUP)
13470                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13471                         res->vf_id, is_on);
13472 #endif
13473 #ifdef RTE_LIBRTE_BNXT_PMD
13474         if (ret == -ENOTSUP)
13475                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13476                         res->vf_id, is_on);
13477 #endif
13478
13479         switch (ret) {
13480         case 0:
13481                 break;
13482         case -EINVAL:
13483                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13484                 break;
13485         case -ENODEV:
13486                 printf("invalid port_id %d\n", res->port_id);
13487                 break;
13488         case -ENOTSUP:
13489                 printf("function not implemented\n");
13490                 break;
13491         default:
13492                 printf("programming error: (%s)\n", strerror(-ret));
13493         }
13494 }
13495
13496 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13497         .f = cmd_set_vf_vlan_stripq_parsed,
13498         .data = NULL,
13499         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13500         .tokens = {
13501                 (void *)&cmd_vf_vlan_stripq_set,
13502                 (void *)&cmd_vf_vlan_stripq_vf,
13503                 (void *)&cmd_vf_vlan_stripq_vlan,
13504                 (void *)&cmd_vf_vlan_stripq_stripq,
13505                 (void *)&cmd_vf_vlan_stripq_port_id,
13506                 (void *)&cmd_vf_vlan_stripq_vf_id,
13507                 (void *)&cmd_vf_vlan_stripq_on_off,
13508                 NULL,
13509         },
13510 };
13511
13512 /* vf vlan insert configuration */
13513
13514 /* Common result structure for vf vlan insert */
13515 struct cmd_vf_vlan_insert_result {
13516         cmdline_fixed_string_t set;
13517         cmdline_fixed_string_t vf;
13518         cmdline_fixed_string_t vlan;
13519         cmdline_fixed_string_t insert;
13520         portid_t port_id;
13521         uint16_t vf_id;
13522         uint16_t vlan_id;
13523 };
13524
13525 /* Common CLI fields for vf vlan insert enable disable */
13526 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13527         TOKEN_STRING_INITIALIZER
13528                 (struct cmd_vf_vlan_insert_result,
13529                  set, "set");
13530 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13531         TOKEN_STRING_INITIALIZER
13532                 (struct cmd_vf_vlan_insert_result,
13533                  vf, "vf");
13534 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13535         TOKEN_STRING_INITIALIZER
13536                 (struct cmd_vf_vlan_insert_result,
13537                  vlan, "vlan");
13538 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13539         TOKEN_STRING_INITIALIZER
13540                 (struct cmd_vf_vlan_insert_result,
13541                  insert, "insert");
13542 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13543         TOKEN_NUM_INITIALIZER
13544                 (struct cmd_vf_vlan_insert_result,
13545                  port_id, UINT16);
13546 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13547         TOKEN_NUM_INITIALIZER
13548                 (struct cmd_vf_vlan_insert_result,
13549                  vf_id, UINT16);
13550 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13551         TOKEN_NUM_INITIALIZER
13552                 (struct cmd_vf_vlan_insert_result,
13553                  vlan_id, UINT16);
13554
13555 static void
13556 cmd_set_vf_vlan_insert_parsed(
13557         void *parsed_result,
13558         __attribute__((unused)) struct cmdline *cl,
13559         __attribute__((unused)) void *data)
13560 {
13561         struct cmd_vf_vlan_insert_result *res = parsed_result;
13562         int ret = -ENOTSUP;
13563
13564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13565                 return;
13566
13567 #ifdef RTE_LIBRTE_IXGBE_PMD
13568         if (ret == -ENOTSUP)
13569                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13570                         res->vlan_id);
13571 #endif
13572 #ifdef RTE_LIBRTE_I40E_PMD
13573         if (ret == -ENOTSUP)
13574                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13575                         res->vlan_id);
13576 #endif
13577 #ifdef RTE_LIBRTE_BNXT_PMD
13578         if (ret == -ENOTSUP)
13579                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13580                         res->vlan_id);
13581 #endif
13582
13583         switch (ret) {
13584         case 0:
13585                 break;
13586         case -EINVAL:
13587                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13588                 break;
13589         case -ENODEV:
13590                 printf("invalid port_id %d\n", res->port_id);
13591                 break;
13592         case -ENOTSUP:
13593                 printf("function not implemented\n");
13594                 break;
13595         default:
13596                 printf("programming error: (%s)\n", strerror(-ret));
13597         }
13598 }
13599
13600 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13601         .f = cmd_set_vf_vlan_insert_parsed,
13602         .data = NULL,
13603         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13604         .tokens = {
13605                 (void *)&cmd_vf_vlan_insert_set,
13606                 (void *)&cmd_vf_vlan_insert_vf,
13607                 (void *)&cmd_vf_vlan_insert_vlan,
13608                 (void *)&cmd_vf_vlan_insert_insert,
13609                 (void *)&cmd_vf_vlan_insert_port_id,
13610                 (void *)&cmd_vf_vlan_insert_vf_id,
13611                 (void *)&cmd_vf_vlan_insert_vlan_id,
13612                 NULL,
13613         },
13614 };
13615
13616 /* tx loopback configuration */
13617
13618 /* Common result structure for tx loopback */
13619 struct cmd_tx_loopback_result {
13620         cmdline_fixed_string_t set;
13621         cmdline_fixed_string_t tx;
13622         cmdline_fixed_string_t loopback;
13623         portid_t port_id;
13624         cmdline_fixed_string_t on_off;
13625 };
13626
13627 /* Common CLI fields for tx loopback enable disable */
13628 cmdline_parse_token_string_t cmd_tx_loopback_set =
13629         TOKEN_STRING_INITIALIZER
13630                 (struct cmd_tx_loopback_result,
13631                  set, "set");
13632 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13633         TOKEN_STRING_INITIALIZER
13634                 (struct cmd_tx_loopback_result,
13635                  tx, "tx");
13636 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13637         TOKEN_STRING_INITIALIZER
13638                 (struct cmd_tx_loopback_result,
13639                  loopback, "loopback");
13640 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13641         TOKEN_NUM_INITIALIZER
13642                 (struct cmd_tx_loopback_result,
13643                  port_id, UINT16);
13644 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13645         TOKEN_STRING_INITIALIZER
13646                 (struct cmd_tx_loopback_result,
13647                  on_off, "on#off");
13648
13649 static void
13650 cmd_set_tx_loopback_parsed(
13651         void *parsed_result,
13652         __attribute__((unused)) struct cmdline *cl,
13653         __attribute__((unused)) void *data)
13654 {
13655         struct cmd_tx_loopback_result *res = parsed_result;
13656         int ret = -ENOTSUP;
13657
13658         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13659
13660         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13661                 return;
13662
13663 #ifdef RTE_LIBRTE_IXGBE_PMD
13664         if (ret == -ENOTSUP)
13665                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13666 #endif
13667 #ifdef RTE_LIBRTE_I40E_PMD
13668         if (ret == -ENOTSUP)
13669                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13670 #endif
13671 #ifdef RTE_LIBRTE_BNXT_PMD
13672         if (ret == -ENOTSUP)
13673                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13674 #endif
13675 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13676         if (ret == -ENOTSUP)
13677                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13678 #endif
13679
13680         switch (ret) {
13681         case 0:
13682                 break;
13683         case -EINVAL:
13684                 printf("invalid is_on %d\n", is_on);
13685                 break;
13686         case -ENODEV:
13687                 printf("invalid port_id %d\n", res->port_id);
13688                 break;
13689         case -ENOTSUP:
13690                 printf("function not implemented\n");
13691                 break;
13692         default:
13693                 printf("programming error: (%s)\n", strerror(-ret));
13694         }
13695 }
13696
13697 cmdline_parse_inst_t cmd_set_tx_loopback = {
13698         .f = cmd_set_tx_loopback_parsed,
13699         .data = NULL,
13700         .help_str = "set tx loopback <port_id> on|off",
13701         .tokens = {
13702                 (void *)&cmd_tx_loopback_set,
13703                 (void *)&cmd_tx_loopback_tx,
13704                 (void *)&cmd_tx_loopback_loopback,
13705                 (void *)&cmd_tx_loopback_port_id,
13706                 (void *)&cmd_tx_loopback_on_off,
13707                 NULL,
13708         },
13709 };
13710
13711 /* all queues drop enable configuration */
13712
13713 /* Common result structure for all queues drop enable */
13714 struct cmd_all_queues_drop_en_result {
13715         cmdline_fixed_string_t set;
13716         cmdline_fixed_string_t all;
13717         cmdline_fixed_string_t queues;
13718         cmdline_fixed_string_t drop;
13719         portid_t port_id;
13720         cmdline_fixed_string_t on_off;
13721 };
13722
13723 /* Common CLI fields for tx loopback enable disable */
13724 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13725         TOKEN_STRING_INITIALIZER
13726                 (struct cmd_all_queues_drop_en_result,
13727                  set, "set");
13728 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13729         TOKEN_STRING_INITIALIZER
13730                 (struct cmd_all_queues_drop_en_result,
13731                  all, "all");
13732 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13733         TOKEN_STRING_INITIALIZER
13734                 (struct cmd_all_queues_drop_en_result,
13735                  queues, "queues");
13736 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13737         TOKEN_STRING_INITIALIZER
13738                 (struct cmd_all_queues_drop_en_result,
13739                  drop, "drop");
13740 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13741         TOKEN_NUM_INITIALIZER
13742                 (struct cmd_all_queues_drop_en_result,
13743                  port_id, UINT16);
13744 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_all_queues_drop_en_result,
13747                  on_off, "on#off");
13748
13749 static void
13750 cmd_set_all_queues_drop_en_parsed(
13751         void *parsed_result,
13752         __attribute__((unused)) struct cmdline *cl,
13753         __attribute__((unused)) void *data)
13754 {
13755         struct cmd_all_queues_drop_en_result *res = parsed_result;
13756         int ret = -ENOTSUP;
13757         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13758
13759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13760                 return;
13761
13762 #ifdef RTE_LIBRTE_IXGBE_PMD
13763         if (ret == -ENOTSUP)
13764                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13765 #endif
13766 #ifdef RTE_LIBRTE_BNXT_PMD
13767         if (ret == -ENOTSUP)
13768                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13769 #endif
13770         switch (ret) {
13771         case 0:
13772                 break;
13773         case -EINVAL:
13774                 printf("invalid is_on %d\n", is_on);
13775                 break;
13776         case -ENODEV:
13777                 printf("invalid port_id %d\n", res->port_id);
13778                 break;
13779         case -ENOTSUP:
13780                 printf("function not implemented\n");
13781                 break;
13782         default:
13783                 printf("programming error: (%s)\n", strerror(-ret));
13784         }
13785 }
13786
13787 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13788         .f = cmd_set_all_queues_drop_en_parsed,
13789         .data = NULL,
13790         .help_str = "set all queues drop <port_id> on|off",
13791         .tokens = {
13792                 (void *)&cmd_all_queues_drop_en_set,
13793                 (void *)&cmd_all_queues_drop_en_all,
13794                 (void *)&cmd_all_queues_drop_en_queues,
13795                 (void *)&cmd_all_queues_drop_en_drop,
13796                 (void *)&cmd_all_queues_drop_en_port_id,
13797                 (void *)&cmd_all_queues_drop_en_on_off,
13798                 NULL,
13799         },
13800 };
13801
13802 /* vf split drop enable configuration */
13803
13804 /* Common result structure for vf split drop enable */
13805 struct cmd_vf_split_drop_en_result {
13806         cmdline_fixed_string_t set;
13807         cmdline_fixed_string_t vf;
13808         cmdline_fixed_string_t split;
13809         cmdline_fixed_string_t drop;
13810         portid_t port_id;
13811         uint16_t vf_id;
13812         cmdline_fixed_string_t on_off;
13813 };
13814
13815 /* Common CLI fields for vf split drop enable disable */
13816 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13817         TOKEN_STRING_INITIALIZER
13818                 (struct cmd_vf_split_drop_en_result,
13819                  set, "set");
13820 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13821         TOKEN_STRING_INITIALIZER
13822                 (struct cmd_vf_split_drop_en_result,
13823                  vf, "vf");
13824 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13825         TOKEN_STRING_INITIALIZER
13826                 (struct cmd_vf_split_drop_en_result,
13827                  split, "split");
13828 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13829         TOKEN_STRING_INITIALIZER
13830                 (struct cmd_vf_split_drop_en_result,
13831                  drop, "drop");
13832 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13833         TOKEN_NUM_INITIALIZER
13834                 (struct cmd_vf_split_drop_en_result,
13835                  port_id, UINT16);
13836 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13837         TOKEN_NUM_INITIALIZER
13838                 (struct cmd_vf_split_drop_en_result,
13839                  vf_id, UINT16);
13840 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13841         TOKEN_STRING_INITIALIZER
13842                 (struct cmd_vf_split_drop_en_result,
13843                  on_off, "on#off");
13844
13845 static void
13846 cmd_set_vf_split_drop_en_parsed(
13847         void *parsed_result,
13848         __attribute__((unused)) struct cmdline *cl,
13849         __attribute__((unused)) void *data)
13850 {
13851         struct cmd_vf_split_drop_en_result *res = parsed_result;
13852         int ret = -ENOTSUP;
13853         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13854
13855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13856                 return;
13857
13858 #ifdef RTE_LIBRTE_IXGBE_PMD
13859         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13860                         is_on);
13861 #endif
13862         switch (ret) {
13863         case 0:
13864                 break;
13865         case -EINVAL:
13866                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13867                 break;
13868         case -ENODEV:
13869                 printf("invalid port_id %d\n", res->port_id);
13870                 break;
13871         case -ENOTSUP:
13872                 printf("not supported on port %d\n", res->port_id);
13873                 break;
13874         default:
13875                 printf("programming error: (%s)\n", strerror(-ret));
13876         }
13877 }
13878
13879 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13880         .f = cmd_set_vf_split_drop_en_parsed,
13881         .data = NULL,
13882         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13883         .tokens = {
13884                 (void *)&cmd_vf_split_drop_en_set,
13885                 (void *)&cmd_vf_split_drop_en_vf,
13886                 (void *)&cmd_vf_split_drop_en_split,
13887                 (void *)&cmd_vf_split_drop_en_drop,
13888                 (void *)&cmd_vf_split_drop_en_port_id,
13889                 (void *)&cmd_vf_split_drop_en_vf_id,
13890                 (void *)&cmd_vf_split_drop_en_on_off,
13891                 NULL,
13892         },
13893 };
13894
13895 /* vf mac address configuration */
13896
13897 /* Common result structure for vf mac address */
13898 struct cmd_set_vf_mac_addr_result {
13899         cmdline_fixed_string_t set;
13900         cmdline_fixed_string_t vf;
13901         cmdline_fixed_string_t mac;
13902         cmdline_fixed_string_t addr;
13903         portid_t port_id;
13904         uint16_t vf_id;
13905         struct rte_ether_addr mac_addr;
13906
13907 };
13908
13909 /* Common CLI fields for vf split drop enable disable */
13910 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13911         TOKEN_STRING_INITIALIZER
13912                 (struct cmd_set_vf_mac_addr_result,
13913                  set, "set");
13914 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13915         TOKEN_STRING_INITIALIZER
13916                 (struct cmd_set_vf_mac_addr_result,
13917                  vf, "vf");
13918 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13919         TOKEN_STRING_INITIALIZER
13920                 (struct cmd_set_vf_mac_addr_result,
13921                  mac, "mac");
13922 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13923         TOKEN_STRING_INITIALIZER
13924                 (struct cmd_set_vf_mac_addr_result,
13925                  addr, "addr");
13926 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13927         TOKEN_NUM_INITIALIZER
13928                 (struct cmd_set_vf_mac_addr_result,
13929                  port_id, UINT16);
13930 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13931         TOKEN_NUM_INITIALIZER
13932                 (struct cmd_set_vf_mac_addr_result,
13933                  vf_id, UINT16);
13934 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13935         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13936                  mac_addr);
13937
13938 static void
13939 cmd_set_vf_mac_addr_parsed(
13940         void *parsed_result,
13941         __attribute__((unused)) struct cmdline *cl,
13942         __attribute__((unused)) void *data)
13943 {
13944         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13945         int ret = -ENOTSUP;
13946
13947         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13948                 return;
13949
13950 #ifdef RTE_LIBRTE_IXGBE_PMD
13951         if (ret == -ENOTSUP)
13952                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13953                                 &res->mac_addr);
13954 #endif
13955 #ifdef RTE_LIBRTE_I40E_PMD
13956         if (ret == -ENOTSUP)
13957                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13958                                 &res->mac_addr);
13959 #endif
13960 #ifdef RTE_LIBRTE_BNXT_PMD
13961         if (ret == -ENOTSUP)
13962                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13963                                 &res->mac_addr);
13964 #endif
13965
13966         switch (ret) {
13967         case 0:
13968                 break;
13969         case -EINVAL:
13970                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13971                 break;
13972         case -ENODEV:
13973                 printf("invalid port_id %d\n", res->port_id);
13974                 break;
13975         case -ENOTSUP:
13976                 printf("function not implemented\n");
13977                 break;
13978         default:
13979                 printf("programming error: (%s)\n", strerror(-ret));
13980         }
13981 }
13982
13983 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13984         .f = cmd_set_vf_mac_addr_parsed,
13985         .data = NULL,
13986         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13987         .tokens = {
13988                 (void *)&cmd_set_vf_mac_addr_set,
13989                 (void *)&cmd_set_vf_mac_addr_vf,
13990                 (void *)&cmd_set_vf_mac_addr_mac,
13991                 (void *)&cmd_set_vf_mac_addr_addr,
13992                 (void *)&cmd_set_vf_mac_addr_port_id,
13993                 (void *)&cmd_set_vf_mac_addr_vf_id,
13994                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13995                 NULL,
13996         },
13997 };
13998
13999 /* MACsec configuration */
14000
14001 /* Common result structure for MACsec offload enable */
14002 struct cmd_macsec_offload_on_result {
14003         cmdline_fixed_string_t set;
14004         cmdline_fixed_string_t macsec;
14005         cmdline_fixed_string_t offload;
14006         portid_t port_id;
14007         cmdline_fixed_string_t on;
14008         cmdline_fixed_string_t encrypt;
14009         cmdline_fixed_string_t en_on_off;
14010         cmdline_fixed_string_t replay_protect;
14011         cmdline_fixed_string_t rp_on_off;
14012 };
14013
14014 /* Common CLI fields for MACsec offload disable */
14015 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_macsec_offload_on_result,
14018                  set, "set");
14019 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_macsec_offload_on_result,
14022                  macsec, "macsec");
14023 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14024         TOKEN_STRING_INITIALIZER
14025                 (struct cmd_macsec_offload_on_result,
14026                  offload, "offload");
14027 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14028         TOKEN_NUM_INITIALIZER
14029                 (struct cmd_macsec_offload_on_result,
14030                  port_id, UINT16);
14031 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14032         TOKEN_STRING_INITIALIZER
14033                 (struct cmd_macsec_offload_on_result,
14034                  on, "on");
14035 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14036         TOKEN_STRING_INITIALIZER
14037                 (struct cmd_macsec_offload_on_result,
14038                  encrypt, "encrypt");
14039 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14040         TOKEN_STRING_INITIALIZER
14041                 (struct cmd_macsec_offload_on_result,
14042                  en_on_off, "on#off");
14043 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14044         TOKEN_STRING_INITIALIZER
14045                 (struct cmd_macsec_offload_on_result,
14046                  replay_protect, "replay-protect");
14047 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14048         TOKEN_STRING_INITIALIZER
14049                 (struct cmd_macsec_offload_on_result,
14050                  rp_on_off, "on#off");
14051
14052 static void
14053 cmd_set_macsec_offload_on_parsed(
14054         void *parsed_result,
14055         __attribute__((unused)) struct cmdline *cl,
14056         __attribute__((unused)) void *data)
14057 {
14058         struct cmd_macsec_offload_on_result *res = parsed_result;
14059         int ret = -ENOTSUP;
14060         portid_t port_id = res->port_id;
14061         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14062         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14063         struct rte_eth_dev_info dev_info;
14064
14065         if (port_id_is_invalid(port_id, ENABLED_WARN))
14066                 return;
14067         if (!port_is_stopped(port_id)) {
14068                 printf("Please stop port %d first\n", port_id);
14069                 return;
14070         }
14071
14072         rte_eth_dev_info_get(port_id, &dev_info);
14073         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14074 #ifdef RTE_LIBRTE_IXGBE_PMD
14075                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14076 #endif
14077         }
14078         RTE_SET_USED(en);
14079         RTE_SET_USED(rp);
14080
14081         switch (ret) {
14082         case 0:
14083                 ports[port_id].dev_conf.txmode.offloads |=
14084                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14085                 cmd_reconfig_device_queue(port_id, 1, 1);
14086                 break;
14087         case -ENODEV:
14088                 printf("invalid port_id %d\n", port_id);
14089                 break;
14090         case -ENOTSUP:
14091                 printf("not supported on port %d\n", port_id);
14092                 break;
14093         default:
14094                 printf("programming error: (%s)\n", strerror(-ret));
14095         }
14096 }
14097
14098 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14099         .f = cmd_set_macsec_offload_on_parsed,
14100         .data = NULL,
14101         .help_str = "set macsec offload <port_id> on "
14102                 "encrypt on|off replay-protect on|off",
14103         .tokens = {
14104                 (void *)&cmd_macsec_offload_on_set,
14105                 (void *)&cmd_macsec_offload_on_macsec,
14106                 (void *)&cmd_macsec_offload_on_offload,
14107                 (void *)&cmd_macsec_offload_on_port_id,
14108                 (void *)&cmd_macsec_offload_on_on,
14109                 (void *)&cmd_macsec_offload_on_encrypt,
14110                 (void *)&cmd_macsec_offload_on_en_on_off,
14111                 (void *)&cmd_macsec_offload_on_replay_protect,
14112                 (void *)&cmd_macsec_offload_on_rp_on_off,
14113                 NULL,
14114         },
14115 };
14116
14117 /* Common result structure for MACsec offload disable */
14118 struct cmd_macsec_offload_off_result {
14119         cmdline_fixed_string_t set;
14120         cmdline_fixed_string_t macsec;
14121         cmdline_fixed_string_t offload;
14122         portid_t port_id;
14123         cmdline_fixed_string_t off;
14124 };
14125
14126 /* Common CLI fields for MACsec offload disable */
14127 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14128         TOKEN_STRING_INITIALIZER
14129                 (struct cmd_macsec_offload_off_result,
14130                  set, "set");
14131 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14132         TOKEN_STRING_INITIALIZER
14133                 (struct cmd_macsec_offload_off_result,
14134                  macsec, "macsec");
14135 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14136         TOKEN_STRING_INITIALIZER
14137                 (struct cmd_macsec_offload_off_result,
14138                  offload, "offload");
14139 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14140         TOKEN_NUM_INITIALIZER
14141                 (struct cmd_macsec_offload_off_result,
14142                  port_id, UINT16);
14143 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14144         TOKEN_STRING_INITIALIZER
14145                 (struct cmd_macsec_offload_off_result,
14146                  off, "off");
14147
14148 static void
14149 cmd_set_macsec_offload_off_parsed(
14150         void *parsed_result,
14151         __attribute__((unused)) struct cmdline *cl,
14152         __attribute__((unused)) void *data)
14153 {
14154         struct cmd_macsec_offload_off_result *res = parsed_result;
14155         int ret = -ENOTSUP;
14156         struct rte_eth_dev_info dev_info;
14157         portid_t port_id = res->port_id;
14158
14159         if (port_id_is_invalid(port_id, ENABLED_WARN))
14160                 return;
14161         if (!port_is_stopped(port_id)) {
14162                 printf("Please stop port %d first\n", port_id);
14163                 return;
14164         }
14165
14166         rte_eth_dev_info_get(port_id, &dev_info);
14167         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14168 #ifdef RTE_LIBRTE_IXGBE_PMD
14169                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14170 #endif
14171         }
14172         switch (ret) {
14173         case 0:
14174                 ports[port_id].dev_conf.txmode.offloads &=
14175                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14176                 cmd_reconfig_device_queue(port_id, 1, 1);
14177                 break;
14178         case -ENODEV:
14179                 printf("invalid port_id %d\n", port_id);
14180                 break;
14181         case -ENOTSUP:
14182                 printf("not supported on port %d\n", port_id);
14183                 break;
14184         default:
14185                 printf("programming error: (%s)\n", strerror(-ret));
14186         }
14187 }
14188
14189 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14190         .f = cmd_set_macsec_offload_off_parsed,
14191         .data = NULL,
14192         .help_str = "set macsec offload <port_id> off",
14193         .tokens = {
14194                 (void *)&cmd_macsec_offload_off_set,
14195                 (void *)&cmd_macsec_offload_off_macsec,
14196                 (void *)&cmd_macsec_offload_off_offload,
14197                 (void *)&cmd_macsec_offload_off_port_id,
14198                 (void *)&cmd_macsec_offload_off_off,
14199                 NULL,
14200         },
14201 };
14202
14203 /* Common result structure for MACsec secure connection configure */
14204 struct cmd_macsec_sc_result {
14205         cmdline_fixed_string_t set;
14206         cmdline_fixed_string_t macsec;
14207         cmdline_fixed_string_t sc;
14208         cmdline_fixed_string_t tx_rx;
14209         portid_t port_id;
14210         struct rte_ether_addr mac;
14211         uint16_t pi;
14212 };
14213
14214 /* Common CLI fields for MACsec secure connection configure */
14215 cmdline_parse_token_string_t cmd_macsec_sc_set =
14216         TOKEN_STRING_INITIALIZER
14217                 (struct cmd_macsec_sc_result,
14218                  set, "set");
14219 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14220         TOKEN_STRING_INITIALIZER
14221                 (struct cmd_macsec_sc_result,
14222                  macsec, "macsec");
14223 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14224         TOKEN_STRING_INITIALIZER
14225                 (struct cmd_macsec_sc_result,
14226                  sc, "sc");
14227 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14228         TOKEN_STRING_INITIALIZER
14229                 (struct cmd_macsec_sc_result,
14230                  tx_rx, "tx#rx");
14231 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14232         TOKEN_NUM_INITIALIZER
14233                 (struct cmd_macsec_sc_result,
14234                  port_id, UINT16);
14235 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14236         TOKEN_ETHERADDR_INITIALIZER
14237                 (struct cmd_macsec_sc_result,
14238                  mac);
14239 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14240         TOKEN_NUM_INITIALIZER
14241                 (struct cmd_macsec_sc_result,
14242                  pi, UINT16);
14243
14244 static void
14245 cmd_set_macsec_sc_parsed(
14246         void *parsed_result,
14247         __attribute__((unused)) struct cmdline *cl,
14248         __attribute__((unused)) void *data)
14249 {
14250         struct cmd_macsec_sc_result *res = parsed_result;
14251         int ret = -ENOTSUP;
14252         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14253
14254 #ifdef RTE_LIBRTE_IXGBE_PMD
14255         ret = is_tx ?
14256                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14257                                 res->mac.addr_bytes) :
14258                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14259                                 res->mac.addr_bytes, res->pi);
14260 #endif
14261         RTE_SET_USED(is_tx);
14262
14263         switch (ret) {
14264         case 0:
14265                 break;
14266         case -ENODEV:
14267                 printf("invalid port_id %d\n", res->port_id);
14268                 break;
14269         case -ENOTSUP:
14270                 printf("not supported on port %d\n", res->port_id);
14271                 break;
14272         default:
14273                 printf("programming error: (%s)\n", strerror(-ret));
14274         }
14275 }
14276
14277 cmdline_parse_inst_t cmd_set_macsec_sc = {
14278         .f = cmd_set_macsec_sc_parsed,
14279         .data = NULL,
14280         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14281         .tokens = {
14282                 (void *)&cmd_macsec_sc_set,
14283                 (void *)&cmd_macsec_sc_macsec,
14284                 (void *)&cmd_macsec_sc_sc,
14285                 (void *)&cmd_macsec_sc_tx_rx,
14286                 (void *)&cmd_macsec_sc_port_id,
14287                 (void *)&cmd_macsec_sc_mac,
14288                 (void *)&cmd_macsec_sc_pi,
14289                 NULL,
14290         },
14291 };
14292
14293 /* Common result structure for MACsec secure connection configure */
14294 struct cmd_macsec_sa_result {
14295         cmdline_fixed_string_t set;
14296         cmdline_fixed_string_t macsec;
14297         cmdline_fixed_string_t sa;
14298         cmdline_fixed_string_t tx_rx;
14299         portid_t port_id;
14300         uint8_t idx;
14301         uint8_t an;
14302         uint32_t pn;
14303         cmdline_fixed_string_t key;
14304 };
14305
14306 /* Common CLI fields for MACsec secure connection configure */
14307 cmdline_parse_token_string_t cmd_macsec_sa_set =
14308         TOKEN_STRING_INITIALIZER
14309                 (struct cmd_macsec_sa_result,
14310                  set, "set");
14311 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14312         TOKEN_STRING_INITIALIZER
14313                 (struct cmd_macsec_sa_result,
14314                  macsec, "macsec");
14315 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14316         TOKEN_STRING_INITIALIZER
14317                 (struct cmd_macsec_sa_result,
14318                  sa, "sa");
14319 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14320         TOKEN_STRING_INITIALIZER
14321                 (struct cmd_macsec_sa_result,
14322                  tx_rx, "tx#rx");
14323 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14324         TOKEN_NUM_INITIALIZER
14325                 (struct cmd_macsec_sa_result,
14326                  port_id, UINT16);
14327 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14328         TOKEN_NUM_INITIALIZER
14329                 (struct cmd_macsec_sa_result,
14330                  idx, UINT8);
14331 cmdline_parse_token_num_t cmd_macsec_sa_an =
14332         TOKEN_NUM_INITIALIZER
14333                 (struct cmd_macsec_sa_result,
14334                  an, UINT8);
14335 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14336         TOKEN_NUM_INITIALIZER
14337                 (struct cmd_macsec_sa_result,
14338                  pn, UINT32);
14339 cmdline_parse_token_string_t cmd_macsec_sa_key =
14340         TOKEN_STRING_INITIALIZER
14341                 (struct cmd_macsec_sa_result,
14342                  key, NULL);
14343
14344 static void
14345 cmd_set_macsec_sa_parsed(
14346         void *parsed_result,
14347         __attribute__((unused)) struct cmdline *cl,
14348         __attribute__((unused)) void *data)
14349 {
14350         struct cmd_macsec_sa_result *res = parsed_result;
14351         int ret = -ENOTSUP;
14352         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14353         uint8_t key[16] = { 0 };
14354         uint8_t xdgt0;
14355         uint8_t xdgt1;
14356         int key_len;
14357         int i;
14358
14359         key_len = strlen(res->key) / 2;
14360         if (key_len > 16)
14361                 key_len = 16;
14362
14363         for (i = 0; i < key_len; i++) {
14364                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14365                 if (xdgt0 == 0xFF)
14366                         return;
14367                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14368                 if (xdgt1 == 0xFF)
14369                         return;
14370                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14371         }
14372
14373 #ifdef RTE_LIBRTE_IXGBE_PMD
14374         ret = is_tx ?
14375                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14376                         res->idx, res->an, res->pn, key) :
14377                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14378                         res->idx, res->an, res->pn, key);
14379 #endif
14380         RTE_SET_USED(is_tx);
14381         RTE_SET_USED(key);
14382
14383         switch (ret) {
14384         case 0:
14385                 break;
14386         case -EINVAL:
14387                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14388                 break;
14389         case -ENODEV:
14390                 printf("invalid port_id %d\n", res->port_id);
14391                 break;
14392         case -ENOTSUP:
14393                 printf("not supported on port %d\n", res->port_id);
14394                 break;
14395         default:
14396                 printf("programming error: (%s)\n", strerror(-ret));
14397         }
14398 }
14399
14400 cmdline_parse_inst_t cmd_set_macsec_sa = {
14401         .f = cmd_set_macsec_sa_parsed,
14402         .data = NULL,
14403         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14404         .tokens = {
14405                 (void *)&cmd_macsec_sa_set,
14406                 (void *)&cmd_macsec_sa_macsec,
14407                 (void *)&cmd_macsec_sa_sa,
14408                 (void *)&cmd_macsec_sa_tx_rx,
14409                 (void *)&cmd_macsec_sa_port_id,
14410                 (void *)&cmd_macsec_sa_idx,
14411                 (void *)&cmd_macsec_sa_an,
14412                 (void *)&cmd_macsec_sa_pn,
14413                 (void *)&cmd_macsec_sa_key,
14414                 NULL,
14415         },
14416 };
14417
14418 /* VF unicast promiscuous mode configuration */
14419
14420 /* Common result structure for VF unicast promiscuous mode */
14421 struct cmd_vf_promisc_result {
14422         cmdline_fixed_string_t set;
14423         cmdline_fixed_string_t vf;
14424         cmdline_fixed_string_t promisc;
14425         portid_t port_id;
14426         uint32_t vf_id;
14427         cmdline_fixed_string_t on_off;
14428 };
14429
14430 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14431 cmdline_parse_token_string_t cmd_vf_promisc_set =
14432         TOKEN_STRING_INITIALIZER
14433                 (struct cmd_vf_promisc_result,
14434                  set, "set");
14435 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14436         TOKEN_STRING_INITIALIZER
14437                 (struct cmd_vf_promisc_result,
14438                  vf, "vf");
14439 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14440         TOKEN_STRING_INITIALIZER
14441                 (struct cmd_vf_promisc_result,
14442                  promisc, "promisc");
14443 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14444         TOKEN_NUM_INITIALIZER
14445                 (struct cmd_vf_promisc_result,
14446                  port_id, UINT16);
14447 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14448         TOKEN_NUM_INITIALIZER
14449                 (struct cmd_vf_promisc_result,
14450                  vf_id, UINT32);
14451 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14452         TOKEN_STRING_INITIALIZER
14453                 (struct cmd_vf_promisc_result,
14454                  on_off, "on#off");
14455
14456 static void
14457 cmd_set_vf_promisc_parsed(
14458         void *parsed_result,
14459         __attribute__((unused)) struct cmdline *cl,
14460         __attribute__((unused)) void *data)
14461 {
14462         struct cmd_vf_promisc_result *res = parsed_result;
14463         int ret = -ENOTSUP;
14464
14465         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14466
14467         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14468                 return;
14469
14470 #ifdef RTE_LIBRTE_I40E_PMD
14471         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14472                                                   res->vf_id, is_on);
14473 #endif
14474
14475         switch (ret) {
14476         case 0:
14477                 break;
14478         case -EINVAL:
14479                 printf("invalid vf_id %d\n", res->vf_id);
14480                 break;
14481         case -ENODEV:
14482                 printf("invalid port_id %d\n", res->port_id);
14483                 break;
14484         case -ENOTSUP:
14485                 printf("function not implemented\n");
14486                 break;
14487         default:
14488                 printf("programming error: (%s)\n", strerror(-ret));
14489         }
14490 }
14491
14492 cmdline_parse_inst_t cmd_set_vf_promisc = {
14493         .f = cmd_set_vf_promisc_parsed,
14494         .data = NULL,
14495         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14496                 "Set unicast promiscuous mode for a VF from the PF",
14497         .tokens = {
14498                 (void *)&cmd_vf_promisc_set,
14499                 (void *)&cmd_vf_promisc_vf,
14500                 (void *)&cmd_vf_promisc_promisc,
14501                 (void *)&cmd_vf_promisc_port_id,
14502                 (void *)&cmd_vf_promisc_vf_id,
14503                 (void *)&cmd_vf_promisc_on_off,
14504                 NULL,
14505         },
14506 };
14507
14508 /* VF multicast promiscuous mode configuration */
14509
14510 /* Common result structure for VF multicast promiscuous mode */
14511 struct cmd_vf_allmulti_result {
14512         cmdline_fixed_string_t set;
14513         cmdline_fixed_string_t vf;
14514         cmdline_fixed_string_t allmulti;
14515         portid_t port_id;
14516         uint32_t vf_id;
14517         cmdline_fixed_string_t on_off;
14518 };
14519
14520 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14521 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14522         TOKEN_STRING_INITIALIZER
14523                 (struct cmd_vf_allmulti_result,
14524                  set, "set");
14525 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14526         TOKEN_STRING_INITIALIZER
14527                 (struct cmd_vf_allmulti_result,
14528                  vf, "vf");
14529 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14530         TOKEN_STRING_INITIALIZER
14531                 (struct cmd_vf_allmulti_result,
14532                  allmulti, "allmulti");
14533 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14534         TOKEN_NUM_INITIALIZER
14535                 (struct cmd_vf_allmulti_result,
14536                  port_id, UINT16);
14537 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14538         TOKEN_NUM_INITIALIZER
14539                 (struct cmd_vf_allmulti_result,
14540                  vf_id, UINT32);
14541 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14542         TOKEN_STRING_INITIALIZER
14543                 (struct cmd_vf_allmulti_result,
14544                  on_off, "on#off");
14545
14546 static void
14547 cmd_set_vf_allmulti_parsed(
14548         void *parsed_result,
14549         __attribute__((unused)) struct cmdline *cl,
14550         __attribute__((unused)) void *data)
14551 {
14552         struct cmd_vf_allmulti_result *res = parsed_result;
14553         int ret = -ENOTSUP;
14554
14555         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14556
14557         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14558                 return;
14559
14560 #ifdef RTE_LIBRTE_I40E_PMD
14561         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14562                                                     res->vf_id, is_on);
14563 #endif
14564
14565         switch (ret) {
14566         case 0:
14567                 break;
14568         case -EINVAL:
14569                 printf("invalid vf_id %d\n", res->vf_id);
14570                 break;
14571         case -ENODEV:
14572                 printf("invalid port_id %d\n", res->port_id);
14573                 break;
14574         case -ENOTSUP:
14575                 printf("function not implemented\n");
14576                 break;
14577         default:
14578                 printf("programming error: (%s)\n", strerror(-ret));
14579         }
14580 }
14581
14582 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14583         .f = cmd_set_vf_allmulti_parsed,
14584         .data = NULL,
14585         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14586                 "Set multicast promiscuous mode for a VF from the PF",
14587         .tokens = {
14588                 (void *)&cmd_vf_allmulti_set,
14589                 (void *)&cmd_vf_allmulti_vf,
14590                 (void *)&cmd_vf_allmulti_allmulti,
14591                 (void *)&cmd_vf_allmulti_port_id,
14592                 (void *)&cmd_vf_allmulti_vf_id,
14593                 (void *)&cmd_vf_allmulti_on_off,
14594                 NULL,
14595         },
14596 };
14597
14598 /* vf broadcast mode configuration */
14599
14600 /* Common result structure for vf broadcast */
14601 struct cmd_set_vf_broadcast_result {
14602         cmdline_fixed_string_t set;
14603         cmdline_fixed_string_t vf;
14604         cmdline_fixed_string_t broadcast;
14605         portid_t port_id;
14606         uint16_t vf_id;
14607         cmdline_fixed_string_t on_off;
14608 };
14609
14610 /* Common CLI fields for vf broadcast enable disable */
14611 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14612         TOKEN_STRING_INITIALIZER
14613                 (struct cmd_set_vf_broadcast_result,
14614                  set, "set");
14615 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14616         TOKEN_STRING_INITIALIZER
14617                 (struct cmd_set_vf_broadcast_result,
14618                  vf, "vf");
14619 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14620         TOKEN_STRING_INITIALIZER
14621                 (struct cmd_set_vf_broadcast_result,
14622                  broadcast, "broadcast");
14623 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14624         TOKEN_NUM_INITIALIZER
14625                 (struct cmd_set_vf_broadcast_result,
14626                  port_id, UINT16);
14627 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14628         TOKEN_NUM_INITIALIZER
14629                 (struct cmd_set_vf_broadcast_result,
14630                  vf_id, UINT16);
14631 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14632         TOKEN_STRING_INITIALIZER
14633                 (struct cmd_set_vf_broadcast_result,
14634                  on_off, "on#off");
14635
14636 static void
14637 cmd_set_vf_broadcast_parsed(
14638         void *parsed_result,
14639         __attribute__((unused)) struct cmdline *cl,
14640         __attribute__((unused)) void *data)
14641 {
14642         struct cmd_set_vf_broadcast_result *res = parsed_result;
14643         int ret = -ENOTSUP;
14644
14645         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14646
14647         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14648                 return;
14649
14650 #ifdef RTE_LIBRTE_I40E_PMD
14651         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14652                                             res->vf_id, is_on);
14653 #endif
14654
14655         switch (ret) {
14656         case 0:
14657                 break;
14658         case -EINVAL:
14659                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14660                 break;
14661         case -ENODEV:
14662                 printf("invalid port_id %d\n", res->port_id);
14663                 break;
14664         case -ENOTSUP:
14665                 printf("function not implemented\n");
14666                 break;
14667         default:
14668                 printf("programming error: (%s)\n", strerror(-ret));
14669         }
14670 }
14671
14672 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14673         .f = cmd_set_vf_broadcast_parsed,
14674         .data = NULL,
14675         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14676         .tokens = {
14677                 (void *)&cmd_set_vf_broadcast_set,
14678                 (void *)&cmd_set_vf_broadcast_vf,
14679                 (void *)&cmd_set_vf_broadcast_broadcast,
14680                 (void *)&cmd_set_vf_broadcast_port_id,
14681                 (void *)&cmd_set_vf_broadcast_vf_id,
14682                 (void *)&cmd_set_vf_broadcast_on_off,
14683                 NULL,
14684         },
14685 };
14686
14687 /* vf vlan tag configuration */
14688
14689 /* Common result structure for vf vlan tag */
14690 struct cmd_set_vf_vlan_tag_result {
14691         cmdline_fixed_string_t set;
14692         cmdline_fixed_string_t vf;
14693         cmdline_fixed_string_t vlan;
14694         cmdline_fixed_string_t tag;
14695         portid_t port_id;
14696         uint16_t vf_id;
14697         cmdline_fixed_string_t on_off;
14698 };
14699
14700 /* Common CLI fields for vf vlan tag enable disable */
14701 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14702         TOKEN_STRING_INITIALIZER
14703                 (struct cmd_set_vf_vlan_tag_result,
14704                  set, "set");
14705 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14706         TOKEN_STRING_INITIALIZER
14707                 (struct cmd_set_vf_vlan_tag_result,
14708                  vf, "vf");
14709 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14710         TOKEN_STRING_INITIALIZER
14711                 (struct cmd_set_vf_vlan_tag_result,
14712                  vlan, "vlan");
14713 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14714         TOKEN_STRING_INITIALIZER
14715                 (struct cmd_set_vf_vlan_tag_result,
14716                  tag, "tag");
14717 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14718         TOKEN_NUM_INITIALIZER
14719                 (struct cmd_set_vf_vlan_tag_result,
14720                  port_id, UINT16);
14721 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14722         TOKEN_NUM_INITIALIZER
14723                 (struct cmd_set_vf_vlan_tag_result,
14724                  vf_id, UINT16);
14725 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14726         TOKEN_STRING_INITIALIZER
14727                 (struct cmd_set_vf_vlan_tag_result,
14728                  on_off, "on#off");
14729
14730 static void
14731 cmd_set_vf_vlan_tag_parsed(
14732         void *parsed_result,
14733         __attribute__((unused)) struct cmdline *cl,
14734         __attribute__((unused)) void *data)
14735 {
14736         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14737         int ret = -ENOTSUP;
14738
14739         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
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_vlan_tag(res->port_id,
14746                                            res->vf_id, is_on);
14747 #endif
14748
14749         switch (ret) {
14750         case 0:
14751                 break;
14752         case -EINVAL:
14753                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14754                 break;
14755         case -ENODEV:
14756                 printf("invalid port_id %d\n", res->port_id);
14757                 break;
14758         case -ENOTSUP:
14759                 printf("function not implemented\n");
14760                 break;
14761         default:
14762                 printf("programming error: (%s)\n", strerror(-ret));
14763         }
14764 }
14765
14766 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14767         .f = cmd_set_vf_vlan_tag_parsed,
14768         .data = NULL,
14769         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14770         .tokens = {
14771                 (void *)&cmd_set_vf_vlan_tag_set,
14772                 (void *)&cmd_set_vf_vlan_tag_vf,
14773                 (void *)&cmd_set_vf_vlan_tag_vlan,
14774                 (void *)&cmd_set_vf_vlan_tag_tag,
14775                 (void *)&cmd_set_vf_vlan_tag_port_id,
14776                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14777                 (void *)&cmd_set_vf_vlan_tag_on_off,
14778                 NULL,
14779         },
14780 };
14781
14782 /* Common definition of VF and TC TX bandwidth configuration */
14783 struct cmd_vf_tc_bw_result {
14784         cmdline_fixed_string_t set;
14785         cmdline_fixed_string_t vf;
14786         cmdline_fixed_string_t tc;
14787         cmdline_fixed_string_t tx;
14788         cmdline_fixed_string_t min_bw;
14789         cmdline_fixed_string_t max_bw;
14790         cmdline_fixed_string_t strict_link_prio;
14791         portid_t port_id;
14792         uint16_t vf_id;
14793         uint8_t tc_no;
14794         uint32_t bw;
14795         cmdline_fixed_string_t bw_list;
14796         uint8_t tc_map;
14797 };
14798
14799 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14800         TOKEN_STRING_INITIALIZER
14801                 (struct cmd_vf_tc_bw_result,
14802                  set, "set");
14803 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14804         TOKEN_STRING_INITIALIZER
14805                 (struct cmd_vf_tc_bw_result,
14806                  vf, "vf");
14807 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14808         TOKEN_STRING_INITIALIZER
14809                 (struct cmd_vf_tc_bw_result,
14810                  tc, "tc");
14811 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14812         TOKEN_STRING_INITIALIZER
14813                 (struct cmd_vf_tc_bw_result,
14814                  tx, "tx");
14815 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14816         TOKEN_STRING_INITIALIZER
14817                 (struct cmd_vf_tc_bw_result,
14818                  strict_link_prio, "strict-link-priority");
14819 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14820         TOKEN_STRING_INITIALIZER
14821                 (struct cmd_vf_tc_bw_result,
14822                  min_bw, "min-bandwidth");
14823 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14824         TOKEN_STRING_INITIALIZER
14825                 (struct cmd_vf_tc_bw_result,
14826                  max_bw, "max-bandwidth");
14827 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14828         TOKEN_NUM_INITIALIZER
14829                 (struct cmd_vf_tc_bw_result,
14830                  port_id, UINT16);
14831 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14832         TOKEN_NUM_INITIALIZER
14833                 (struct cmd_vf_tc_bw_result,
14834                  vf_id, UINT16);
14835 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14836         TOKEN_NUM_INITIALIZER
14837                 (struct cmd_vf_tc_bw_result,
14838                  tc_no, UINT8);
14839 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14840         TOKEN_NUM_INITIALIZER
14841                 (struct cmd_vf_tc_bw_result,
14842                  bw, UINT32);
14843 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14844         TOKEN_STRING_INITIALIZER
14845                 (struct cmd_vf_tc_bw_result,
14846                  bw_list, NULL);
14847 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14848         TOKEN_NUM_INITIALIZER
14849                 (struct cmd_vf_tc_bw_result,
14850                  tc_map, UINT8);
14851
14852 /* VF max bandwidth setting */
14853 static void
14854 cmd_vf_max_bw_parsed(
14855         void *parsed_result,
14856         __attribute__((unused)) struct cmdline *cl,
14857         __attribute__((unused)) void *data)
14858 {
14859         struct cmd_vf_tc_bw_result *res = parsed_result;
14860         int ret = -ENOTSUP;
14861
14862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14863                 return;
14864
14865 #ifdef RTE_LIBRTE_I40E_PMD
14866         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14867                                          res->vf_id, res->bw);
14868 #endif
14869
14870         switch (ret) {
14871         case 0:
14872                 break;
14873         case -EINVAL:
14874                 printf("invalid vf_id %d or bandwidth %d\n",
14875                        res->vf_id, res->bw);
14876                 break;
14877         case -ENODEV:
14878                 printf("invalid port_id %d\n", res->port_id);
14879                 break;
14880         case -ENOTSUP:
14881                 printf("function not implemented\n");
14882                 break;
14883         default:
14884                 printf("programming error: (%s)\n", strerror(-ret));
14885         }
14886 }
14887
14888 cmdline_parse_inst_t cmd_vf_max_bw = {
14889         .f = cmd_vf_max_bw_parsed,
14890         .data = NULL,
14891         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14892         .tokens = {
14893                 (void *)&cmd_vf_tc_bw_set,
14894                 (void *)&cmd_vf_tc_bw_vf,
14895                 (void *)&cmd_vf_tc_bw_tx,
14896                 (void *)&cmd_vf_tc_bw_max_bw,
14897                 (void *)&cmd_vf_tc_bw_port_id,
14898                 (void *)&cmd_vf_tc_bw_vf_id,
14899                 (void *)&cmd_vf_tc_bw_bw,
14900                 NULL,
14901         },
14902 };
14903
14904 static int
14905 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14906                            uint8_t *tc_num,
14907                            char *str)
14908 {
14909         uint32_t size;
14910         const char *p, *p0 = str;
14911         char s[256];
14912         char *end;
14913         char *str_fld[16];
14914         uint16_t i;
14915         int ret;
14916
14917         p = strchr(p0, '(');
14918         if (p == NULL) {
14919                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14920                 return -1;
14921         }
14922         p++;
14923         p0 = strchr(p, ')');
14924         if (p0 == NULL) {
14925                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14926                 return -1;
14927         }
14928         size = p0 - p;
14929         if (size >= sizeof(s)) {
14930                 printf("The string size exceeds the internal buffer size\n");
14931                 return -1;
14932         }
14933         snprintf(s, sizeof(s), "%.*s", size, p);
14934         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14935         if (ret <= 0) {
14936                 printf("Failed to get the bandwidth list. ");
14937                 return -1;
14938         }
14939         *tc_num = ret;
14940         for (i = 0; i < ret; i++)
14941                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14942
14943         return 0;
14944 }
14945
14946 /* TC min bandwidth setting */
14947 static void
14948 cmd_vf_tc_min_bw_parsed(
14949         void *parsed_result,
14950         __attribute__((unused)) struct cmdline *cl,
14951         __attribute__((unused)) void *data)
14952 {
14953         struct cmd_vf_tc_bw_result *res = parsed_result;
14954         uint8_t tc_num;
14955         uint8_t bw[16];
14956         int ret = -ENOTSUP;
14957
14958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14959                 return;
14960
14961         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14962         if (ret)
14963                 return;
14964
14965 #ifdef RTE_LIBRTE_I40E_PMD
14966         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14967                                               tc_num, bw);
14968 #endif
14969
14970         switch (ret) {
14971         case 0:
14972                 break;
14973         case -EINVAL:
14974                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14975                 break;
14976         case -ENODEV:
14977                 printf("invalid port_id %d\n", res->port_id);
14978                 break;
14979         case -ENOTSUP:
14980                 printf("function not implemented\n");
14981                 break;
14982         default:
14983                 printf("programming error: (%s)\n", strerror(-ret));
14984         }
14985 }
14986
14987 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14988         .f = cmd_vf_tc_min_bw_parsed,
14989         .data = NULL,
14990         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14991                     " <bw1, bw2, ...>",
14992         .tokens = {
14993                 (void *)&cmd_vf_tc_bw_set,
14994                 (void *)&cmd_vf_tc_bw_vf,
14995                 (void *)&cmd_vf_tc_bw_tc,
14996                 (void *)&cmd_vf_tc_bw_tx,
14997                 (void *)&cmd_vf_tc_bw_min_bw,
14998                 (void *)&cmd_vf_tc_bw_port_id,
14999                 (void *)&cmd_vf_tc_bw_vf_id,
15000                 (void *)&cmd_vf_tc_bw_bw_list,
15001                 NULL,
15002         },
15003 };
15004
15005 static void
15006 cmd_tc_min_bw_parsed(
15007         void *parsed_result,
15008         __attribute__((unused)) struct cmdline *cl,
15009         __attribute__((unused)) void *data)
15010 {
15011         struct cmd_vf_tc_bw_result *res = parsed_result;
15012         struct rte_port *port;
15013         uint8_t tc_num;
15014         uint8_t bw[16];
15015         int ret = -ENOTSUP;
15016
15017         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15018                 return;
15019
15020         port = &ports[res->port_id];
15021         /** Check if the port is not started **/
15022         if (port->port_status != RTE_PORT_STOPPED) {
15023                 printf("Please stop port %d first\n", res->port_id);
15024                 return;
15025         }
15026
15027         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15028         if (ret)
15029                 return;
15030
15031 #ifdef RTE_LIBRTE_IXGBE_PMD
15032         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15033 #endif
15034
15035         switch (ret) {
15036         case 0:
15037                 break;
15038         case -EINVAL:
15039                 printf("invalid bandwidth\n");
15040                 break;
15041         case -ENODEV:
15042                 printf("invalid port_id %d\n", res->port_id);
15043                 break;
15044         case -ENOTSUP:
15045                 printf("function not implemented\n");
15046                 break;
15047         default:
15048                 printf("programming error: (%s)\n", strerror(-ret));
15049         }
15050 }
15051
15052 cmdline_parse_inst_t cmd_tc_min_bw = {
15053         .f = cmd_tc_min_bw_parsed,
15054         .data = NULL,
15055         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15056         .tokens = {
15057                 (void *)&cmd_vf_tc_bw_set,
15058                 (void *)&cmd_vf_tc_bw_tc,
15059                 (void *)&cmd_vf_tc_bw_tx,
15060                 (void *)&cmd_vf_tc_bw_min_bw,
15061                 (void *)&cmd_vf_tc_bw_port_id,
15062                 (void *)&cmd_vf_tc_bw_bw_list,
15063                 NULL,
15064         },
15065 };
15066
15067 /* TC max bandwidth setting */
15068 static void
15069 cmd_vf_tc_max_bw_parsed(
15070         void *parsed_result,
15071         __attribute__((unused)) struct cmdline *cl,
15072         __attribute__((unused)) void *data)
15073 {
15074         struct cmd_vf_tc_bw_result *res = parsed_result;
15075         int ret = -ENOTSUP;
15076
15077         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15078                 return;
15079
15080 #ifdef RTE_LIBRTE_I40E_PMD
15081         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15082                                             res->tc_no, res->bw);
15083 #endif
15084
15085         switch (ret) {
15086         case 0:
15087                 break;
15088         case -EINVAL:
15089                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15090                        res->vf_id, res->tc_no, res->bw);
15091                 break;
15092         case -ENODEV:
15093                 printf("invalid port_id %d\n", res->port_id);
15094                 break;
15095         case -ENOTSUP:
15096                 printf("function not implemented\n");
15097                 break;
15098         default:
15099                 printf("programming error: (%s)\n", strerror(-ret));
15100         }
15101 }
15102
15103 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15104         .f = cmd_vf_tc_max_bw_parsed,
15105         .data = NULL,
15106         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15107                     " <bandwidth>",
15108         .tokens = {
15109                 (void *)&cmd_vf_tc_bw_set,
15110                 (void *)&cmd_vf_tc_bw_vf,
15111                 (void *)&cmd_vf_tc_bw_tc,
15112                 (void *)&cmd_vf_tc_bw_tx,
15113                 (void *)&cmd_vf_tc_bw_max_bw,
15114                 (void *)&cmd_vf_tc_bw_port_id,
15115                 (void *)&cmd_vf_tc_bw_vf_id,
15116                 (void *)&cmd_vf_tc_bw_tc_no,
15117                 (void *)&cmd_vf_tc_bw_bw,
15118                 NULL,
15119         },
15120 };
15121
15122
15123 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15124
15125 /* *** Set Port default Traffic Management Hierarchy *** */
15126 struct cmd_set_port_tm_hierarchy_default_result {
15127         cmdline_fixed_string_t set;
15128         cmdline_fixed_string_t port;
15129         cmdline_fixed_string_t tm;
15130         cmdline_fixed_string_t hierarchy;
15131         cmdline_fixed_string_t def;
15132         portid_t port_id;
15133 };
15134
15135 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15136         TOKEN_STRING_INITIALIZER(
15137                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15138 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15139         TOKEN_STRING_INITIALIZER(
15140                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15141 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15142         TOKEN_STRING_INITIALIZER(
15143                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15144 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15145         TOKEN_STRING_INITIALIZER(
15146                 struct cmd_set_port_tm_hierarchy_default_result,
15147                         hierarchy, "hierarchy");
15148 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15149         TOKEN_STRING_INITIALIZER(
15150                 struct cmd_set_port_tm_hierarchy_default_result,
15151                         def, "default");
15152 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15153         TOKEN_NUM_INITIALIZER(
15154                 struct cmd_set_port_tm_hierarchy_default_result,
15155                         port_id, UINT16);
15156
15157 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15158         __attribute__((unused)) struct cmdline *cl,
15159         __attribute__((unused)) void *data)
15160 {
15161         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15162         struct rte_port *p;
15163         portid_t port_id = res->port_id;
15164
15165         if (port_id_is_invalid(port_id, ENABLED_WARN))
15166                 return;
15167
15168         p = &ports[port_id];
15169
15170         /* Forward mode: tm */
15171         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15172                 printf("  softnicfwd mode not enabled(error)\n");
15173                 return;
15174         }
15175
15176         /* Set the default tm hierarchy */
15177         p->softport.default_tm_hierarchy_enable = 1;
15178 }
15179
15180 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15181         .f = cmd_set_port_tm_hierarchy_default_parsed,
15182         .data = NULL,
15183         .help_str = "set port tm hierarchy default <port_id>",
15184         .tokens = {
15185                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15186                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15187                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15188                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15189                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15190                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15191                 NULL,
15192         },
15193 };
15194 #endif
15195
15196 /** Set VXLAN encapsulation details */
15197 struct cmd_set_vxlan_result {
15198         cmdline_fixed_string_t set;
15199         cmdline_fixed_string_t vxlan;
15200         cmdline_fixed_string_t pos_token;
15201         cmdline_fixed_string_t ip_version;
15202         uint32_t vlan_present:1;
15203         uint32_t vni;
15204         uint16_t udp_src;
15205         uint16_t udp_dst;
15206         cmdline_ipaddr_t ip_src;
15207         cmdline_ipaddr_t ip_dst;
15208         uint16_t tci;
15209         uint8_t tos;
15210         uint8_t ttl;
15211         struct rte_ether_addr eth_src;
15212         struct rte_ether_addr eth_dst;
15213 };
15214
15215 cmdline_parse_token_string_t cmd_set_vxlan_set =
15216         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15217 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15218         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15219 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15220         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15221                                  "vxlan-tos-ttl");
15222 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15223         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15224                                  "vxlan-with-vlan");
15225 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15226         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15227                                  "ip-version");
15228 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15229         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15230                                  "ipv4#ipv6");
15231 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15232         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15233                                  "vni");
15234 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15235         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15236 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15237         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15238                                  "udp-src");
15239 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15240         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15241 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15242         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15243                                  "udp-dst");
15244 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15245         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15246 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15247         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15248                                  "ip-tos");
15249 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15250         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15251 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15252         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15253                                  "ip-ttl");
15254 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15255         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15256 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15257         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15258                                  "ip-src");
15259 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15260         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15261 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15262         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15263                                  "ip-dst");
15264 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15265         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15266 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15267         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15268                                  "vlan-tci");
15269 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15270         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15271 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15272         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15273                                  "eth-src");
15274 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15275         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15276 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15277         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15278                                  "eth-dst");
15279 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15280         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15281
15282 static void cmd_set_vxlan_parsed(void *parsed_result,
15283         __attribute__((unused)) struct cmdline *cl,
15284         __attribute__((unused)) void *data)
15285 {
15286         struct cmd_set_vxlan_result *res = parsed_result;
15287         union {
15288                 uint32_t vxlan_id;
15289                 uint8_t vni[4];
15290         } id = {
15291                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15292         };
15293
15294         vxlan_encap_conf.select_tos_ttl = 0;
15295         if (strcmp(res->vxlan, "vxlan") == 0)
15296                 vxlan_encap_conf.select_vlan = 0;
15297         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15298                 vxlan_encap_conf.select_vlan = 1;
15299         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15300                 vxlan_encap_conf.select_vlan = 0;
15301                 vxlan_encap_conf.select_tos_ttl = 1;
15302         }
15303         if (strcmp(res->ip_version, "ipv4") == 0)
15304                 vxlan_encap_conf.select_ipv4 = 1;
15305         else if (strcmp(res->ip_version, "ipv6") == 0)
15306                 vxlan_encap_conf.select_ipv4 = 0;
15307         else
15308                 return;
15309         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15310         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15311         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15312         vxlan_encap_conf.ip_tos = res->tos;
15313         vxlan_encap_conf.ip_ttl = res->ttl;
15314         if (vxlan_encap_conf.select_ipv4) {
15315                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15316                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15317         } else {
15318                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15319                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15320         }
15321         if (vxlan_encap_conf.select_vlan)
15322                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15323         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15324                    RTE_ETHER_ADDR_LEN);
15325         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15326                    RTE_ETHER_ADDR_LEN);
15327 }
15328
15329 cmdline_parse_inst_t cmd_set_vxlan = {
15330         .f = cmd_set_vxlan_parsed,
15331         .data = NULL,
15332         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15333                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15334                 " eth-src <eth-src> eth-dst <eth-dst>",
15335         .tokens = {
15336                 (void *)&cmd_set_vxlan_set,
15337                 (void *)&cmd_set_vxlan_vxlan,
15338                 (void *)&cmd_set_vxlan_ip_version,
15339                 (void *)&cmd_set_vxlan_ip_version_value,
15340                 (void *)&cmd_set_vxlan_vni,
15341                 (void *)&cmd_set_vxlan_vni_value,
15342                 (void *)&cmd_set_vxlan_udp_src,
15343                 (void *)&cmd_set_vxlan_udp_src_value,
15344                 (void *)&cmd_set_vxlan_udp_dst,
15345                 (void *)&cmd_set_vxlan_udp_dst_value,
15346                 (void *)&cmd_set_vxlan_ip_src,
15347                 (void *)&cmd_set_vxlan_ip_src_value,
15348                 (void *)&cmd_set_vxlan_ip_dst,
15349                 (void *)&cmd_set_vxlan_ip_dst_value,
15350                 (void *)&cmd_set_vxlan_eth_src,
15351                 (void *)&cmd_set_vxlan_eth_src_value,
15352                 (void *)&cmd_set_vxlan_eth_dst,
15353                 (void *)&cmd_set_vxlan_eth_dst_value,
15354                 NULL,
15355         },
15356 };
15357
15358 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15359         .f = cmd_set_vxlan_parsed,
15360         .data = NULL,
15361         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15362                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15363                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15364                 " eth-dst <eth-dst>",
15365         .tokens = {
15366                 (void *)&cmd_set_vxlan_set,
15367                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15368                 (void *)&cmd_set_vxlan_ip_version,
15369                 (void *)&cmd_set_vxlan_ip_version_value,
15370                 (void *)&cmd_set_vxlan_vni,
15371                 (void *)&cmd_set_vxlan_vni_value,
15372                 (void *)&cmd_set_vxlan_udp_src,
15373                 (void *)&cmd_set_vxlan_udp_src_value,
15374                 (void *)&cmd_set_vxlan_udp_dst,
15375                 (void *)&cmd_set_vxlan_udp_dst_value,
15376                 (void *)&cmd_set_vxlan_ip_tos,
15377                 (void *)&cmd_set_vxlan_ip_tos_value,
15378                 (void *)&cmd_set_vxlan_ip_ttl,
15379                 (void *)&cmd_set_vxlan_ip_ttl_value,
15380                 (void *)&cmd_set_vxlan_ip_src,
15381                 (void *)&cmd_set_vxlan_ip_src_value,
15382                 (void *)&cmd_set_vxlan_ip_dst,
15383                 (void *)&cmd_set_vxlan_ip_dst_value,
15384                 (void *)&cmd_set_vxlan_eth_src,
15385                 (void *)&cmd_set_vxlan_eth_src_value,
15386                 (void *)&cmd_set_vxlan_eth_dst,
15387                 (void *)&cmd_set_vxlan_eth_dst_value,
15388                 NULL,
15389         },
15390 };
15391
15392 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15393         .f = cmd_set_vxlan_parsed,
15394         .data = NULL,
15395         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15396                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15397                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15398                 " <eth-dst>",
15399         .tokens = {
15400                 (void *)&cmd_set_vxlan_set,
15401                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15402                 (void *)&cmd_set_vxlan_ip_version,
15403                 (void *)&cmd_set_vxlan_ip_version_value,
15404                 (void *)&cmd_set_vxlan_vni,
15405                 (void *)&cmd_set_vxlan_vni_value,
15406                 (void *)&cmd_set_vxlan_udp_src,
15407                 (void *)&cmd_set_vxlan_udp_src_value,
15408                 (void *)&cmd_set_vxlan_udp_dst,
15409                 (void *)&cmd_set_vxlan_udp_dst_value,
15410                 (void *)&cmd_set_vxlan_ip_src,
15411                 (void *)&cmd_set_vxlan_ip_src_value,
15412                 (void *)&cmd_set_vxlan_ip_dst,
15413                 (void *)&cmd_set_vxlan_ip_dst_value,
15414                 (void *)&cmd_set_vxlan_vlan,
15415                 (void *)&cmd_set_vxlan_vlan_value,
15416                 (void *)&cmd_set_vxlan_eth_src,
15417                 (void *)&cmd_set_vxlan_eth_src_value,
15418                 (void *)&cmd_set_vxlan_eth_dst,
15419                 (void *)&cmd_set_vxlan_eth_dst_value,
15420                 NULL,
15421         },
15422 };
15423
15424 /** Set NVGRE encapsulation details */
15425 struct cmd_set_nvgre_result {
15426         cmdline_fixed_string_t set;
15427         cmdline_fixed_string_t nvgre;
15428         cmdline_fixed_string_t pos_token;
15429         cmdline_fixed_string_t ip_version;
15430         uint32_t tni;
15431         cmdline_ipaddr_t ip_src;
15432         cmdline_ipaddr_t ip_dst;
15433         uint16_t tci;
15434         struct rte_ether_addr eth_src;
15435         struct rte_ether_addr eth_dst;
15436 };
15437
15438 cmdline_parse_token_string_t cmd_set_nvgre_set =
15439         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15440 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15441         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15442 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15443         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15444                                  "nvgre-with-vlan");
15445 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15446         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15447                                  "ip-version");
15448 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15449         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15450                                  "ipv4#ipv6");
15451 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15453                                  "tni");
15454 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15455         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15456 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15457         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15458                                  "ip-src");
15459 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15460         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15461 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15462         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15463                                  "ip-dst");
15464 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15465         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15466 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15467         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15468                                  "vlan-tci");
15469 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15470         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15471 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15472         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15473                                  "eth-src");
15474 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15475         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15476 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15477         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15478                                  "eth-dst");
15479 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15480         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15481
15482 static void cmd_set_nvgre_parsed(void *parsed_result,
15483         __attribute__((unused)) struct cmdline *cl,
15484         __attribute__((unused)) void *data)
15485 {
15486         struct cmd_set_nvgre_result *res = parsed_result;
15487         union {
15488                 uint32_t nvgre_tni;
15489                 uint8_t tni[4];
15490         } id = {
15491                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15492         };
15493
15494         if (strcmp(res->nvgre, "nvgre") == 0)
15495                 nvgre_encap_conf.select_vlan = 0;
15496         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15497                 nvgre_encap_conf.select_vlan = 1;
15498         if (strcmp(res->ip_version, "ipv4") == 0)
15499                 nvgre_encap_conf.select_ipv4 = 1;
15500         else if (strcmp(res->ip_version, "ipv6") == 0)
15501                 nvgre_encap_conf.select_ipv4 = 0;
15502         else
15503                 return;
15504         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15505         if (nvgre_encap_conf.select_ipv4) {
15506                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15507                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15508         } else {
15509                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15510                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15511         }
15512         if (nvgre_encap_conf.select_vlan)
15513                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15514         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15515                    RTE_ETHER_ADDR_LEN);
15516         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15517                    RTE_ETHER_ADDR_LEN);
15518 }
15519
15520 cmdline_parse_inst_t cmd_set_nvgre = {
15521         .f = cmd_set_nvgre_parsed,
15522         .data = NULL,
15523         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15524                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15525                 " eth-dst <eth-dst>",
15526         .tokens = {
15527                 (void *)&cmd_set_nvgre_set,
15528                 (void *)&cmd_set_nvgre_nvgre,
15529                 (void *)&cmd_set_nvgre_ip_version,
15530                 (void *)&cmd_set_nvgre_ip_version_value,
15531                 (void *)&cmd_set_nvgre_tni,
15532                 (void *)&cmd_set_nvgre_tni_value,
15533                 (void *)&cmd_set_nvgre_ip_src,
15534                 (void *)&cmd_set_nvgre_ip_src_value,
15535                 (void *)&cmd_set_nvgre_ip_dst,
15536                 (void *)&cmd_set_nvgre_ip_dst_value,
15537                 (void *)&cmd_set_nvgre_eth_src,
15538                 (void *)&cmd_set_nvgre_eth_src_value,
15539                 (void *)&cmd_set_nvgre_eth_dst,
15540                 (void *)&cmd_set_nvgre_eth_dst_value,
15541                 NULL,
15542         },
15543 };
15544
15545 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15546         .f = cmd_set_nvgre_parsed,
15547         .data = NULL,
15548         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15549                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15550                 " eth-src <eth-src> eth-dst <eth-dst>",
15551         .tokens = {
15552                 (void *)&cmd_set_nvgre_set,
15553                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15554                 (void *)&cmd_set_nvgre_ip_version,
15555                 (void *)&cmd_set_nvgre_ip_version_value,
15556                 (void *)&cmd_set_nvgre_tni,
15557                 (void *)&cmd_set_nvgre_tni_value,
15558                 (void *)&cmd_set_nvgre_ip_src,
15559                 (void *)&cmd_set_nvgre_ip_src_value,
15560                 (void *)&cmd_set_nvgre_ip_dst,
15561                 (void *)&cmd_set_nvgre_ip_dst_value,
15562                 (void *)&cmd_set_nvgre_vlan,
15563                 (void *)&cmd_set_nvgre_vlan_value,
15564                 (void *)&cmd_set_nvgre_eth_src,
15565                 (void *)&cmd_set_nvgre_eth_src_value,
15566                 (void *)&cmd_set_nvgre_eth_dst,
15567                 (void *)&cmd_set_nvgre_eth_dst_value,
15568                 NULL,
15569         },
15570 };
15571
15572 /** Set L2 encapsulation details */
15573 struct cmd_set_l2_encap_result {
15574         cmdline_fixed_string_t set;
15575         cmdline_fixed_string_t l2_encap;
15576         cmdline_fixed_string_t pos_token;
15577         cmdline_fixed_string_t ip_version;
15578         uint32_t vlan_present:1;
15579         uint16_t tci;
15580         struct rte_ether_addr eth_src;
15581         struct rte_ether_addr eth_dst;
15582 };
15583
15584 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15585         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15586 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15587         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15588 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15589         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15590                                  "l2_encap-with-vlan");
15591 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15592         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15593                                  "ip-version");
15594 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15595         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15596                                  "ipv4#ipv6");
15597 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15598         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15599                                  "vlan-tci");
15600 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15601         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15602 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15603         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15604                                  "eth-src");
15605 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15606         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15607 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15608         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15609                                  "eth-dst");
15610 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15611         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15612
15613 static void cmd_set_l2_encap_parsed(void *parsed_result,
15614         __attribute__((unused)) struct cmdline *cl,
15615         __attribute__((unused)) void *data)
15616 {
15617         struct cmd_set_l2_encap_result *res = parsed_result;
15618
15619         if (strcmp(res->l2_encap, "l2_encap") == 0)
15620                 l2_encap_conf.select_vlan = 0;
15621         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15622                 l2_encap_conf.select_vlan = 1;
15623         if (strcmp(res->ip_version, "ipv4") == 0)
15624                 l2_encap_conf.select_ipv4 = 1;
15625         else if (strcmp(res->ip_version, "ipv6") == 0)
15626                 l2_encap_conf.select_ipv4 = 0;
15627         else
15628                 return;
15629         if (l2_encap_conf.select_vlan)
15630                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15631         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15632                    RTE_ETHER_ADDR_LEN);
15633         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15634                    RTE_ETHER_ADDR_LEN);
15635 }
15636
15637 cmdline_parse_inst_t cmd_set_l2_encap = {
15638         .f = cmd_set_l2_encap_parsed,
15639         .data = NULL,
15640         .help_str = "set l2_encap ip-version ipv4|ipv6"
15641                 " eth-src <eth-src> eth-dst <eth-dst>",
15642         .tokens = {
15643                 (void *)&cmd_set_l2_encap_set,
15644                 (void *)&cmd_set_l2_encap_l2_encap,
15645                 (void *)&cmd_set_l2_encap_ip_version,
15646                 (void *)&cmd_set_l2_encap_ip_version_value,
15647                 (void *)&cmd_set_l2_encap_eth_src,
15648                 (void *)&cmd_set_l2_encap_eth_src_value,
15649                 (void *)&cmd_set_l2_encap_eth_dst,
15650                 (void *)&cmd_set_l2_encap_eth_dst_value,
15651                 NULL,
15652         },
15653 };
15654
15655 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15656         .f = cmd_set_l2_encap_parsed,
15657         .data = NULL,
15658         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15659                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15660         .tokens = {
15661                 (void *)&cmd_set_l2_encap_set,
15662                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15663                 (void *)&cmd_set_l2_encap_ip_version,
15664                 (void *)&cmd_set_l2_encap_ip_version_value,
15665                 (void *)&cmd_set_l2_encap_vlan,
15666                 (void *)&cmd_set_l2_encap_vlan_value,
15667                 (void *)&cmd_set_l2_encap_eth_src,
15668                 (void *)&cmd_set_l2_encap_eth_src_value,
15669                 (void *)&cmd_set_l2_encap_eth_dst,
15670                 (void *)&cmd_set_l2_encap_eth_dst_value,
15671                 NULL,
15672         },
15673 };
15674
15675 /** Set L2 decapsulation details */
15676 struct cmd_set_l2_decap_result {
15677         cmdline_fixed_string_t set;
15678         cmdline_fixed_string_t l2_decap;
15679         cmdline_fixed_string_t pos_token;
15680         uint32_t vlan_present:1;
15681 };
15682
15683 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15684         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15685 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15686         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15687                                  "l2_decap");
15688 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15689         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15690                                  "l2_decap-with-vlan");
15691
15692 static void cmd_set_l2_decap_parsed(void *parsed_result,
15693         __attribute__((unused)) struct cmdline *cl,
15694         __attribute__((unused)) void *data)
15695 {
15696         struct cmd_set_l2_decap_result *res = parsed_result;
15697
15698         if (strcmp(res->l2_decap, "l2_decap") == 0)
15699                 l2_decap_conf.select_vlan = 0;
15700         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15701                 l2_decap_conf.select_vlan = 1;
15702 }
15703
15704 cmdline_parse_inst_t cmd_set_l2_decap = {
15705         .f = cmd_set_l2_decap_parsed,
15706         .data = NULL,
15707         .help_str = "set l2_decap",
15708         .tokens = {
15709                 (void *)&cmd_set_l2_decap_set,
15710                 (void *)&cmd_set_l2_decap_l2_decap,
15711                 NULL,
15712         },
15713 };
15714
15715 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15716         .f = cmd_set_l2_decap_parsed,
15717         .data = NULL,
15718         .help_str = "set l2_decap-with-vlan",
15719         .tokens = {
15720                 (void *)&cmd_set_l2_decap_set,
15721                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15722                 NULL,
15723         },
15724 };
15725
15726 /** Set MPLSoGRE encapsulation details */
15727 struct cmd_set_mplsogre_encap_result {
15728         cmdline_fixed_string_t set;
15729         cmdline_fixed_string_t mplsogre;
15730         cmdline_fixed_string_t pos_token;
15731         cmdline_fixed_string_t ip_version;
15732         uint32_t vlan_present:1;
15733         uint32_t label;
15734         cmdline_ipaddr_t ip_src;
15735         cmdline_ipaddr_t ip_dst;
15736         uint16_t tci;
15737         struct rte_ether_addr eth_src;
15738         struct rte_ether_addr eth_dst;
15739 };
15740
15741 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15743                                  "set");
15744 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15746                                  "mplsogre_encap");
15747 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15749                                  mplsogre, "mplsogre_encap-with-vlan");
15750 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15752                                  pos_token, "ip-version");
15753 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15755                                  ip_version, "ipv4#ipv6");
15756 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15757         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15758                                  pos_token, "label");
15759 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15760         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15761                               UINT32);
15762 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15763         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15764                                  pos_token, "ip-src");
15765 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15766         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15767 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15768         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15769                                  pos_token, "ip-dst");
15770 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15771         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15772 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15773         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15774                                  pos_token, "vlan-tci");
15775 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15776         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15777                               UINT16);
15778 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15780                                  pos_token, "eth-src");
15781 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15782         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15783                                     eth_src);
15784 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15785         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15786                                  pos_token, "eth-dst");
15787 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15788         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15789                                     eth_dst);
15790
15791 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15792         __attribute__((unused)) struct cmdline *cl,
15793         __attribute__((unused)) void *data)
15794 {
15795         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15796         union {
15797                 uint32_t mplsogre_label;
15798                 uint8_t label[4];
15799         } id = {
15800                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15801         };
15802
15803         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15804                 mplsogre_encap_conf.select_vlan = 0;
15805         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15806                 mplsogre_encap_conf.select_vlan = 1;
15807         if (strcmp(res->ip_version, "ipv4") == 0)
15808                 mplsogre_encap_conf.select_ipv4 = 1;
15809         else if (strcmp(res->ip_version, "ipv6") == 0)
15810                 mplsogre_encap_conf.select_ipv4 = 0;
15811         else
15812                 return;
15813         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15814         if (mplsogre_encap_conf.select_ipv4) {
15815                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15816                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15817         } else {
15818                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15819                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15820         }
15821         if (mplsogre_encap_conf.select_vlan)
15822                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15823         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15824                    RTE_ETHER_ADDR_LEN);
15825         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15826                    RTE_ETHER_ADDR_LEN);
15827 }
15828
15829 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15830         .f = cmd_set_mplsogre_encap_parsed,
15831         .data = NULL,
15832         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15833                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15834                 " eth-dst <eth-dst>",
15835         .tokens = {
15836                 (void *)&cmd_set_mplsogre_encap_set,
15837                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15838                 (void *)&cmd_set_mplsogre_encap_ip_version,
15839                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15840                 (void *)&cmd_set_mplsogre_encap_label,
15841                 (void *)&cmd_set_mplsogre_encap_label_value,
15842                 (void *)&cmd_set_mplsogre_encap_ip_src,
15843                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15844                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15845                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15846                 (void *)&cmd_set_mplsogre_encap_eth_src,
15847                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15848                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15849                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15850                 NULL,
15851         },
15852 };
15853
15854 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15855         .f = cmd_set_mplsogre_encap_parsed,
15856         .data = NULL,
15857         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15858                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15859                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15860         .tokens = {
15861                 (void *)&cmd_set_mplsogre_encap_set,
15862                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15863                 (void *)&cmd_set_mplsogre_encap_ip_version,
15864                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15865                 (void *)&cmd_set_mplsogre_encap_label,
15866                 (void *)&cmd_set_mplsogre_encap_label_value,
15867                 (void *)&cmd_set_mplsogre_encap_ip_src,
15868                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15869                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15870                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15871                 (void *)&cmd_set_mplsogre_encap_vlan,
15872                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15873                 (void *)&cmd_set_mplsogre_encap_eth_src,
15874                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15875                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15876                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15877                 NULL,
15878         },
15879 };
15880
15881 /** Set MPLSoGRE decapsulation details */
15882 struct cmd_set_mplsogre_decap_result {
15883         cmdline_fixed_string_t set;
15884         cmdline_fixed_string_t mplsogre;
15885         cmdline_fixed_string_t pos_token;
15886         cmdline_fixed_string_t ip_version;
15887         uint32_t vlan_present:1;
15888 };
15889
15890 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15892                                  "set");
15893 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15894         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15895                                  "mplsogre_decap");
15896 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15897         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15898                                  mplsogre, "mplsogre_decap-with-vlan");
15899 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15900         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15901                                  pos_token, "ip-version");
15902 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15903         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15904                                  ip_version, "ipv4#ipv6");
15905
15906 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15907         __attribute__((unused)) struct cmdline *cl,
15908         __attribute__((unused)) void *data)
15909 {
15910         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15911
15912         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15913                 mplsogre_decap_conf.select_vlan = 0;
15914         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15915                 mplsogre_decap_conf.select_vlan = 1;
15916         if (strcmp(res->ip_version, "ipv4") == 0)
15917                 mplsogre_decap_conf.select_ipv4 = 1;
15918         else if (strcmp(res->ip_version, "ipv6") == 0)
15919                 mplsogre_decap_conf.select_ipv4 = 0;
15920 }
15921
15922 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15923         .f = cmd_set_mplsogre_decap_parsed,
15924         .data = NULL,
15925         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15926         .tokens = {
15927                 (void *)&cmd_set_mplsogre_decap_set,
15928                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15929                 (void *)&cmd_set_mplsogre_decap_ip_version,
15930                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15931                 NULL,
15932         },
15933 };
15934
15935 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15936         .f = cmd_set_mplsogre_decap_parsed,
15937         .data = NULL,
15938         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15939         .tokens = {
15940                 (void *)&cmd_set_mplsogre_decap_set,
15941                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15942                 (void *)&cmd_set_mplsogre_decap_ip_version,
15943                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15944                 NULL,
15945         },
15946 };
15947
15948 /** Set MPLSoUDP encapsulation details */
15949 struct cmd_set_mplsoudp_encap_result {
15950         cmdline_fixed_string_t set;
15951         cmdline_fixed_string_t mplsoudp;
15952         cmdline_fixed_string_t pos_token;
15953         cmdline_fixed_string_t ip_version;
15954         uint32_t vlan_present:1;
15955         uint32_t label;
15956         uint16_t udp_src;
15957         uint16_t udp_dst;
15958         cmdline_ipaddr_t ip_src;
15959         cmdline_ipaddr_t ip_dst;
15960         uint16_t tci;
15961         struct rte_ether_addr eth_src;
15962         struct rte_ether_addr eth_dst;
15963 };
15964
15965 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15966         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15967                                  "set");
15968 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15969         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15970                                  "mplsoudp_encap");
15971 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15972         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15973                                  mplsoudp, "mplsoudp_encap-with-vlan");
15974 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15975         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15976                                  pos_token, "ip-version");
15977 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15979                                  ip_version, "ipv4#ipv6");
15980 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15981         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15982                                  pos_token, "label");
15983 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15984         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15985                               UINT32);
15986 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15987         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15988                                  pos_token, "udp-src");
15989 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15990         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15991                               UINT16);
15992 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15993         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15994                                  pos_token, "udp-dst");
15995 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15996         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15997                               UINT16);
15998 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16000                                  pos_token, "ip-src");
16001 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16002         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16003 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16004         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16005                                  pos_token, "ip-dst");
16006 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16007         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16008 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16009         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16010                                  pos_token, "vlan-tci");
16011 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16012         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16013                               UINT16);
16014 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16016                                  pos_token, "eth-src");
16017 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16018         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16019                                     eth_src);
16020 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16021         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16022                                  pos_token, "eth-dst");
16023 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16024         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16025                                     eth_dst);
16026
16027 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16028         __attribute__((unused)) struct cmdline *cl,
16029         __attribute__((unused)) void *data)
16030 {
16031         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16032         union {
16033                 uint32_t mplsoudp_label;
16034                 uint8_t label[4];
16035         } id = {
16036                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16037         };
16038
16039         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16040                 mplsoudp_encap_conf.select_vlan = 0;
16041         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16042                 mplsoudp_encap_conf.select_vlan = 1;
16043         if (strcmp(res->ip_version, "ipv4") == 0)
16044                 mplsoudp_encap_conf.select_ipv4 = 1;
16045         else if (strcmp(res->ip_version, "ipv6") == 0)
16046                 mplsoudp_encap_conf.select_ipv4 = 0;
16047         else
16048                 return;
16049         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16050         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16051         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16052         if (mplsoudp_encap_conf.select_ipv4) {
16053                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16054                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16055         } else {
16056                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16057                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16058         }
16059         if (mplsoudp_encap_conf.select_vlan)
16060                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16061         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16062                    RTE_ETHER_ADDR_LEN);
16063         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16064                    RTE_ETHER_ADDR_LEN);
16065 }
16066
16067 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16068         .f = cmd_set_mplsoudp_encap_parsed,
16069         .data = NULL,
16070         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16071                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16072                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16073         .tokens = {
16074                 (void *)&cmd_set_mplsoudp_encap_set,
16075                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16076                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16077                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16078                 (void *)&cmd_set_mplsoudp_encap_label,
16079                 (void *)&cmd_set_mplsoudp_encap_label_value,
16080                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16081                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16082                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16083                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16084                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16085                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16086                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16087                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16088                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16089                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16090                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16091                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16092                 NULL,
16093         },
16094 };
16095
16096 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16097         .f = cmd_set_mplsoudp_encap_parsed,
16098         .data = NULL,
16099         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16100                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16101                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16102                 " eth-src <eth-src> eth-dst <eth-dst>",
16103         .tokens = {
16104                 (void *)&cmd_set_mplsoudp_encap_set,
16105                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16106                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16107                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16108                 (void *)&cmd_set_mplsoudp_encap_label,
16109                 (void *)&cmd_set_mplsoudp_encap_label_value,
16110                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16111                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16112                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16113                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16114                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16115                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16116                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16117                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16118                 (void *)&cmd_set_mplsoudp_encap_vlan,
16119                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16120                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16121                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16122                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16123                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16124                 NULL,
16125         },
16126 };
16127
16128 /** Set MPLSoUDP decapsulation details */
16129 struct cmd_set_mplsoudp_decap_result {
16130         cmdline_fixed_string_t set;
16131         cmdline_fixed_string_t mplsoudp;
16132         cmdline_fixed_string_t pos_token;
16133         cmdline_fixed_string_t ip_version;
16134         uint32_t vlan_present:1;
16135 };
16136
16137 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16138         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16139                                  "set");
16140 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16141         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16142                                  "mplsoudp_decap");
16143 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16144         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16145                                  mplsoudp, "mplsoudp_decap-with-vlan");
16146 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16147         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16148                                  pos_token, "ip-version");
16149 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16150         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16151                                  ip_version, "ipv4#ipv6");
16152
16153 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16154         __attribute__((unused)) struct cmdline *cl,
16155         __attribute__((unused)) void *data)
16156 {
16157         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16158
16159         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16160                 mplsoudp_decap_conf.select_vlan = 0;
16161         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16162                 mplsoudp_decap_conf.select_vlan = 1;
16163         if (strcmp(res->ip_version, "ipv4") == 0)
16164                 mplsoudp_decap_conf.select_ipv4 = 1;
16165         else if (strcmp(res->ip_version, "ipv6") == 0)
16166                 mplsoudp_decap_conf.select_ipv4 = 0;
16167 }
16168
16169 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16170         .f = cmd_set_mplsoudp_decap_parsed,
16171         .data = NULL,
16172         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16173         .tokens = {
16174                 (void *)&cmd_set_mplsoudp_decap_set,
16175                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16176                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16177                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16178                 NULL,
16179         },
16180 };
16181
16182 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16183         .f = cmd_set_mplsoudp_decap_parsed,
16184         .data = NULL,
16185         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16186         .tokens = {
16187                 (void *)&cmd_set_mplsoudp_decap_set,
16188                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16189                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16190                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16191                 NULL,
16192         },
16193 };
16194
16195 /* Strict link priority scheduling mode setting */
16196 static void
16197 cmd_strict_link_prio_parsed(
16198         void *parsed_result,
16199         __attribute__((unused)) struct cmdline *cl,
16200         __attribute__((unused)) void *data)
16201 {
16202         struct cmd_vf_tc_bw_result *res = parsed_result;
16203         int ret = -ENOTSUP;
16204
16205         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16206                 return;
16207
16208 #ifdef RTE_LIBRTE_I40E_PMD
16209         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16210 #endif
16211
16212         switch (ret) {
16213         case 0:
16214                 break;
16215         case -EINVAL:
16216                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16217                 break;
16218         case -ENODEV:
16219                 printf("invalid port_id %d\n", res->port_id);
16220                 break;
16221         case -ENOTSUP:
16222                 printf("function not implemented\n");
16223                 break;
16224         default:
16225                 printf("programming error: (%s)\n", strerror(-ret));
16226         }
16227 }
16228
16229 cmdline_parse_inst_t cmd_strict_link_prio = {
16230         .f = cmd_strict_link_prio_parsed,
16231         .data = NULL,
16232         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16233         .tokens = {
16234                 (void *)&cmd_vf_tc_bw_set,
16235                 (void *)&cmd_vf_tc_bw_tx,
16236                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16237                 (void *)&cmd_vf_tc_bw_port_id,
16238                 (void *)&cmd_vf_tc_bw_tc_map,
16239                 NULL,
16240         },
16241 };
16242
16243 /* Load dynamic device personalization*/
16244 struct cmd_ddp_add_result {
16245         cmdline_fixed_string_t ddp;
16246         cmdline_fixed_string_t add;
16247         portid_t port_id;
16248         char filepath[];
16249 };
16250
16251 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16252         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16253 cmdline_parse_token_string_t cmd_ddp_add_add =
16254         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16255 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16256         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16257 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16258         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16259
16260 static void
16261 cmd_ddp_add_parsed(
16262         void *parsed_result,
16263         __attribute__((unused)) struct cmdline *cl,
16264         __attribute__((unused)) void *data)
16265 {
16266         struct cmd_ddp_add_result *res = parsed_result;
16267         uint8_t *buff;
16268         uint32_t size;
16269         char *filepath;
16270         char *file_fld[2];
16271         int file_num;
16272         int ret = -ENOTSUP;
16273
16274         if (!all_ports_stopped()) {
16275                 printf("Please stop all ports first\n");
16276                 return;
16277         }
16278
16279         filepath = strdup(res->filepath);
16280         if (filepath == NULL) {
16281                 printf("Failed to allocate memory\n");
16282                 return;
16283         }
16284         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16285
16286         buff = open_file(file_fld[0], &size);
16287         if (!buff) {
16288                 free((void *)filepath);
16289                 return;
16290         }
16291
16292 #ifdef RTE_LIBRTE_I40E_PMD
16293         if (ret == -ENOTSUP)
16294                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16295                                                buff, size,
16296                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16297 #endif
16298
16299         if (ret == -EEXIST)
16300                 printf("Profile has already existed.\n");
16301         else if (ret < 0)
16302                 printf("Failed to load profile.\n");
16303         else if (file_num == 2)
16304                 save_file(file_fld[1], buff, size);
16305
16306         close_file(buff);
16307         free((void *)filepath);
16308 }
16309
16310 cmdline_parse_inst_t cmd_ddp_add = {
16311         .f = cmd_ddp_add_parsed,
16312         .data = NULL,
16313         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16314         .tokens = {
16315                 (void *)&cmd_ddp_add_ddp,
16316                 (void *)&cmd_ddp_add_add,
16317                 (void *)&cmd_ddp_add_port_id,
16318                 (void *)&cmd_ddp_add_filepath,
16319                 NULL,
16320         },
16321 };
16322
16323 /* Delete dynamic device personalization*/
16324 struct cmd_ddp_del_result {
16325         cmdline_fixed_string_t ddp;
16326         cmdline_fixed_string_t del;
16327         portid_t port_id;
16328         char filepath[];
16329 };
16330
16331 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16332         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16333 cmdline_parse_token_string_t cmd_ddp_del_del =
16334         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16335 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16336         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16337 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16338         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16339
16340 static void
16341 cmd_ddp_del_parsed(
16342         void *parsed_result,
16343         __attribute__((unused)) struct cmdline *cl,
16344         __attribute__((unused)) void *data)
16345 {
16346         struct cmd_ddp_del_result *res = parsed_result;
16347         uint8_t *buff;
16348         uint32_t size;
16349         int ret = -ENOTSUP;
16350
16351         if (!all_ports_stopped()) {
16352                 printf("Please stop all ports first\n");
16353                 return;
16354         }
16355
16356         buff = open_file(res->filepath, &size);
16357         if (!buff)
16358                 return;
16359
16360 #ifdef RTE_LIBRTE_I40E_PMD
16361         if (ret == -ENOTSUP)
16362                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16363                                                buff, size,
16364                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16365 #endif
16366
16367         if (ret == -EACCES)
16368                 printf("Profile does not exist.\n");
16369         else if (ret < 0)
16370                 printf("Failed to delete profile.\n");
16371
16372         close_file(buff);
16373 }
16374
16375 cmdline_parse_inst_t cmd_ddp_del = {
16376         .f = cmd_ddp_del_parsed,
16377         .data = NULL,
16378         .help_str = "ddp del <port_id> <backup_profile_path>",
16379         .tokens = {
16380                 (void *)&cmd_ddp_del_ddp,
16381                 (void *)&cmd_ddp_del_del,
16382                 (void *)&cmd_ddp_del_port_id,
16383                 (void *)&cmd_ddp_del_filepath,
16384                 NULL,
16385         },
16386 };
16387
16388 /* Get dynamic device personalization profile info */
16389 struct cmd_ddp_info_result {
16390         cmdline_fixed_string_t ddp;
16391         cmdline_fixed_string_t get;
16392         cmdline_fixed_string_t info;
16393         char filepath[];
16394 };
16395
16396 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16397         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16398 cmdline_parse_token_string_t cmd_ddp_info_get =
16399         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16400 cmdline_parse_token_string_t cmd_ddp_info_info =
16401         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16402 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16403         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16404
16405 static void
16406 cmd_ddp_info_parsed(
16407         void *parsed_result,
16408         __attribute__((unused)) struct cmdline *cl,
16409         __attribute__((unused)) void *data)
16410 {
16411         struct cmd_ddp_info_result *res = parsed_result;
16412         uint8_t *pkg;
16413         uint32_t pkg_size;
16414         int ret = -ENOTSUP;
16415 #ifdef RTE_LIBRTE_I40E_PMD
16416         uint32_t i, j, n;
16417         uint8_t *buff;
16418         uint32_t buff_size = 0;
16419         struct rte_pmd_i40e_profile_info info;
16420         uint32_t dev_num = 0;
16421         struct rte_pmd_i40e_ddp_device_id *devs;
16422         uint32_t proto_num = 0;
16423         struct rte_pmd_i40e_proto_info *proto = NULL;
16424         uint32_t pctype_num = 0;
16425         struct rte_pmd_i40e_ptype_info *pctype;
16426         uint32_t ptype_num = 0;
16427         struct rte_pmd_i40e_ptype_info *ptype;
16428         uint8_t proto_id;
16429
16430 #endif
16431
16432         pkg = open_file(res->filepath, &pkg_size);
16433         if (!pkg)
16434                 return;
16435
16436 #ifdef RTE_LIBRTE_I40E_PMD
16437         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16438                                 (uint8_t *)&info, sizeof(info),
16439                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16440         if (!ret) {
16441                 printf("Global Track id:       0x%x\n", info.track_id);
16442                 printf("Global Version:        %d.%d.%d.%d\n",
16443                         info.version.major,
16444                         info.version.minor,
16445                         info.version.update,
16446                         info.version.draft);
16447                 printf("Global Package name:   %s\n\n", info.name);
16448         }
16449
16450         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16451                                 (uint8_t *)&info, sizeof(info),
16452                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16453         if (!ret) {
16454                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16455                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16456                         info.version.major,
16457                         info.version.minor,
16458                         info.version.update,
16459                         info.version.draft);
16460                 printf("i40e Profile name:     %s\n\n", info.name);
16461         }
16462
16463         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16464                                 (uint8_t *)&buff_size, sizeof(buff_size),
16465                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16466         if (!ret && buff_size) {
16467                 buff = (uint8_t *)malloc(buff_size);
16468                 if (buff) {
16469                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16470                                                 buff, buff_size,
16471                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16472                         if (!ret)
16473                                 printf("Package Notes:\n%s\n\n", buff);
16474                         free(buff);
16475                 }
16476         }
16477
16478         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16479                                 (uint8_t *)&dev_num, sizeof(dev_num),
16480                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16481         if (!ret && dev_num) {
16482                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16483                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16484                 if (devs) {
16485                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16486                                                 (uint8_t *)devs, buff_size,
16487                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16488                         if (!ret) {
16489                                 printf("List of supported devices:\n");
16490                                 for (i = 0; i < dev_num; i++) {
16491                                         printf("  %04X:%04X %04X:%04X\n",
16492                                                 devs[i].vendor_dev_id >> 16,
16493                                                 devs[i].vendor_dev_id & 0xFFFF,
16494                                                 devs[i].sub_vendor_dev_id >> 16,
16495                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16496                                 }
16497                                 printf("\n");
16498                         }
16499                         free(devs);
16500                 }
16501         }
16502
16503         /* get information about protocols and packet types */
16504         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16505                 (uint8_t *)&proto_num, sizeof(proto_num),
16506                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16507         if (ret || !proto_num)
16508                 goto no_print_return;
16509
16510         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16511         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16512         if (!proto)
16513                 goto no_print_return;
16514
16515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16516                                         buff_size,
16517                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16518         if (!ret) {
16519                 printf("List of used protocols:\n");
16520                 for (i = 0; i < proto_num; i++)
16521                         printf("  %2u: %s\n", proto[i].proto_id,
16522                                proto[i].name);
16523                 printf("\n");
16524         }
16525         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16526                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16527                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16528         if (ret || !pctype_num)
16529                 goto no_print_pctypes;
16530
16531         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16532         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16533         if (!pctype)
16534                 goto no_print_pctypes;
16535
16536         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16537                                         buff_size,
16538                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16539         if (ret) {
16540                 free(pctype);
16541                 goto no_print_pctypes;
16542         }
16543
16544         printf("List of defined packet classification types:\n");
16545         for (i = 0; i < pctype_num; i++) {
16546                 printf("  %2u:", pctype[i].ptype_id);
16547                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16548                         proto_id = pctype[i].protocols[j];
16549                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16550                                 for (n = 0; n < proto_num; n++) {
16551                                         if (proto[n].proto_id == proto_id) {
16552                                                 printf(" %s", proto[n].name);
16553                                                 break;
16554                                         }
16555                                 }
16556                         }
16557                 }
16558                 printf("\n");
16559         }
16560         printf("\n");
16561         free(pctype);
16562
16563 no_print_pctypes:
16564
16565         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16566                                         sizeof(ptype_num),
16567                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16568         if (ret || !ptype_num)
16569                 goto no_print_return;
16570
16571         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16572         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16573         if (!ptype)
16574                 goto no_print_return;
16575
16576         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16577                                         buff_size,
16578                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16579         if (ret) {
16580                 free(ptype);
16581                 goto no_print_return;
16582         }
16583         printf("List of defined packet types:\n");
16584         for (i = 0; i < ptype_num; i++) {
16585                 printf("  %2u:", ptype[i].ptype_id);
16586                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16587                         proto_id = ptype[i].protocols[j];
16588                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16589                                 for (n = 0; n < proto_num; n++) {
16590                                         if (proto[n].proto_id == proto_id) {
16591                                                 printf(" %s", proto[n].name);
16592                                                 break;
16593                                         }
16594                                 }
16595                         }
16596                 }
16597                 printf("\n");
16598         }
16599         free(ptype);
16600         printf("\n");
16601
16602         ret = 0;
16603 no_print_return:
16604         if (proto)
16605                 free(proto);
16606 #endif
16607         if (ret == -ENOTSUP)
16608                 printf("Function not supported in PMD driver\n");
16609         close_file(pkg);
16610 }
16611
16612 cmdline_parse_inst_t cmd_ddp_get_info = {
16613         .f = cmd_ddp_info_parsed,
16614         .data = NULL,
16615         .help_str = "ddp get info <profile_path>",
16616         .tokens = {
16617                 (void *)&cmd_ddp_info_ddp,
16618                 (void *)&cmd_ddp_info_get,
16619                 (void *)&cmd_ddp_info_info,
16620                 (void *)&cmd_ddp_info_filepath,
16621                 NULL,
16622         },
16623 };
16624
16625 /* Get dynamic device personalization profile info list*/
16626 #define PROFILE_INFO_SIZE 48
16627 #define MAX_PROFILE_NUM 16
16628
16629 struct cmd_ddp_get_list_result {
16630         cmdline_fixed_string_t ddp;
16631         cmdline_fixed_string_t get;
16632         cmdline_fixed_string_t list;
16633         portid_t port_id;
16634 };
16635
16636 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16637         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16638 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16639         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16640 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16641         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16642 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16643         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16644
16645 static void
16646 cmd_ddp_get_list_parsed(
16647         __attribute__((unused)) void *parsed_result,
16648         __attribute__((unused)) struct cmdline *cl,
16649         __attribute__((unused)) void *data)
16650 {
16651 #ifdef RTE_LIBRTE_I40E_PMD
16652         struct cmd_ddp_get_list_result *res = parsed_result;
16653         struct rte_pmd_i40e_profile_list *p_list;
16654         struct rte_pmd_i40e_profile_info *p_info;
16655         uint32_t p_num;
16656         uint32_t size;
16657         uint32_t i;
16658 #endif
16659         int ret = -ENOTSUP;
16660
16661 #ifdef RTE_LIBRTE_I40E_PMD
16662         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16663         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16664         if (!p_list)
16665                 printf("%s: Failed to malloc buffer\n", __func__);
16666
16667         if (ret == -ENOTSUP)
16668                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16669                                                 (uint8_t *)p_list, size);
16670
16671         if (!ret) {
16672                 p_num = p_list->p_count;
16673                 printf("Profile number is: %d\n\n", p_num);
16674
16675                 for (i = 0; i < p_num; i++) {
16676                         p_info = &p_list->p_info[i];
16677                         printf("Profile %d:\n", i);
16678                         printf("Track id:     0x%x\n", p_info->track_id);
16679                         printf("Version:      %d.%d.%d.%d\n",
16680                                p_info->version.major,
16681                                p_info->version.minor,
16682                                p_info->version.update,
16683                                p_info->version.draft);
16684                         printf("Profile name: %s\n\n", p_info->name);
16685                 }
16686         }
16687
16688         free(p_list);
16689 #endif
16690
16691         if (ret < 0)
16692                 printf("Failed to get ddp list\n");
16693 }
16694
16695 cmdline_parse_inst_t cmd_ddp_get_list = {
16696         .f = cmd_ddp_get_list_parsed,
16697         .data = NULL,
16698         .help_str = "ddp get list <port_id>",
16699         .tokens = {
16700                 (void *)&cmd_ddp_get_list_ddp,
16701                 (void *)&cmd_ddp_get_list_get,
16702                 (void *)&cmd_ddp_get_list_list,
16703                 (void *)&cmd_ddp_get_list_port_id,
16704                 NULL,
16705         },
16706 };
16707
16708 /* Configure input set */
16709 struct cmd_cfg_input_set_result {
16710         cmdline_fixed_string_t port;
16711         cmdline_fixed_string_t cfg;
16712         portid_t port_id;
16713         cmdline_fixed_string_t pctype;
16714         uint8_t pctype_id;
16715         cmdline_fixed_string_t inset_type;
16716         cmdline_fixed_string_t opt;
16717         cmdline_fixed_string_t field;
16718         uint8_t field_idx;
16719 };
16720
16721 static void
16722 cmd_cfg_input_set_parsed(
16723         __attribute__((unused)) void *parsed_result,
16724         __attribute__((unused)) struct cmdline *cl,
16725         __attribute__((unused)) void *data)
16726 {
16727 #ifdef RTE_LIBRTE_I40E_PMD
16728         struct cmd_cfg_input_set_result *res = parsed_result;
16729         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16730         struct rte_pmd_i40e_inset inset;
16731 #endif
16732         int ret = -ENOTSUP;
16733
16734         if (!all_ports_stopped()) {
16735                 printf("Please stop all ports first\n");
16736                 return;
16737         }
16738
16739 #ifdef RTE_LIBRTE_I40E_PMD
16740         if (!strcmp(res->inset_type, "hash_inset"))
16741                 inset_type = INSET_HASH;
16742         else if (!strcmp(res->inset_type, "fdir_inset"))
16743                 inset_type = INSET_FDIR;
16744         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16745                 inset_type = INSET_FDIR_FLX;
16746         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16747                                      &inset, inset_type);
16748         if (ret) {
16749                 printf("Failed to get input set.\n");
16750                 return;
16751         }
16752
16753         if (!strcmp(res->opt, "get")) {
16754                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16755                                                    res->field_idx);
16756                 if (ret)
16757                         printf("Field index %d is enabled.\n", res->field_idx);
16758                 else
16759                         printf("Field index %d is disabled.\n", res->field_idx);
16760                 return;
16761         } else if (!strcmp(res->opt, "set"))
16762                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16763                                                    res->field_idx);
16764         else if (!strcmp(res->opt, "clear"))
16765                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16766                                                      res->field_idx);
16767         if (ret) {
16768                 printf("Failed to configure input set field.\n");
16769                 return;
16770         }
16771
16772         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16773                                      &inset, inset_type);
16774         if (ret) {
16775                 printf("Failed to set input set.\n");
16776                 return;
16777         }
16778 #endif
16779
16780         if (ret == -ENOTSUP)
16781                 printf("Function not supported\n");
16782 }
16783
16784 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16785         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16786                                  port, "port");
16787 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16788         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16789                                  cfg, "config");
16790 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16791         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16792                               port_id, UINT16);
16793 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16794         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16795                                  pctype, "pctype");
16796 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16797         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16798                               pctype_id, UINT8);
16799 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16800         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16801                                  inset_type,
16802                                  "hash_inset#fdir_inset#fdir_flx_inset");
16803 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16804         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16805                                  opt, "get#set#clear");
16806 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16807         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16808                                  field, "field");
16809 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16810         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16811                               field_idx, UINT8);
16812
16813 cmdline_parse_inst_t cmd_cfg_input_set = {
16814         .f = cmd_cfg_input_set_parsed,
16815         .data = NULL,
16816         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16817                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16818         .tokens = {
16819                 (void *)&cmd_cfg_input_set_port,
16820                 (void *)&cmd_cfg_input_set_cfg,
16821                 (void *)&cmd_cfg_input_set_port_id,
16822                 (void *)&cmd_cfg_input_set_pctype,
16823                 (void *)&cmd_cfg_input_set_pctype_id,
16824                 (void *)&cmd_cfg_input_set_inset_type,
16825                 (void *)&cmd_cfg_input_set_opt,
16826                 (void *)&cmd_cfg_input_set_field,
16827                 (void *)&cmd_cfg_input_set_field_idx,
16828                 NULL,
16829         },
16830 };
16831
16832 /* Clear input set */
16833 struct cmd_clear_input_set_result {
16834         cmdline_fixed_string_t port;
16835         cmdline_fixed_string_t cfg;
16836         portid_t port_id;
16837         cmdline_fixed_string_t pctype;
16838         uint8_t pctype_id;
16839         cmdline_fixed_string_t inset_type;
16840         cmdline_fixed_string_t clear;
16841         cmdline_fixed_string_t all;
16842 };
16843
16844 static void
16845 cmd_clear_input_set_parsed(
16846         __attribute__((unused)) void *parsed_result,
16847         __attribute__((unused)) struct cmdline *cl,
16848         __attribute__((unused)) void *data)
16849 {
16850 #ifdef RTE_LIBRTE_I40E_PMD
16851         struct cmd_clear_input_set_result *res = parsed_result;
16852         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16853         struct rte_pmd_i40e_inset inset;
16854 #endif
16855         int ret = -ENOTSUP;
16856
16857         if (!all_ports_stopped()) {
16858                 printf("Please stop all ports first\n");
16859                 return;
16860         }
16861
16862 #ifdef RTE_LIBRTE_I40E_PMD
16863         if (!strcmp(res->inset_type, "hash_inset"))
16864                 inset_type = INSET_HASH;
16865         else if (!strcmp(res->inset_type, "fdir_inset"))
16866                 inset_type = INSET_FDIR;
16867         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16868                 inset_type = INSET_FDIR_FLX;
16869
16870         memset(&inset, 0, sizeof(inset));
16871
16872         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16873                                      &inset, inset_type);
16874         if (ret) {
16875                 printf("Failed to clear input set.\n");
16876                 return;
16877         }
16878
16879 #endif
16880
16881         if (ret == -ENOTSUP)
16882                 printf("Function not supported\n");
16883 }
16884
16885 cmdline_parse_token_string_t cmd_clear_input_set_port =
16886         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16887                                  port, "port");
16888 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16889         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16890                                  cfg, "config");
16891 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16892         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16893                               port_id, UINT16);
16894 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16895         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16896                                  pctype, "pctype");
16897 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16898         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16899                               pctype_id, UINT8);
16900 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16901         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16902                                  inset_type,
16903                                  "hash_inset#fdir_inset#fdir_flx_inset");
16904 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16905         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16906                                  clear, "clear");
16907 cmdline_parse_token_string_t cmd_clear_input_set_all =
16908         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16909                                  all, "all");
16910
16911 cmdline_parse_inst_t cmd_clear_input_set = {
16912         .f = cmd_clear_input_set_parsed,
16913         .data = NULL,
16914         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16915                     "fdir_inset|fdir_flx_inset clear all",
16916         .tokens = {
16917                 (void *)&cmd_clear_input_set_port,
16918                 (void *)&cmd_clear_input_set_cfg,
16919                 (void *)&cmd_clear_input_set_port_id,
16920                 (void *)&cmd_clear_input_set_pctype,
16921                 (void *)&cmd_clear_input_set_pctype_id,
16922                 (void *)&cmd_clear_input_set_inset_type,
16923                 (void *)&cmd_clear_input_set_clear,
16924                 (void *)&cmd_clear_input_set_all,
16925                 NULL,
16926         },
16927 };
16928
16929 /* show vf stats */
16930
16931 /* Common result structure for show vf stats */
16932 struct cmd_show_vf_stats_result {
16933         cmdline_fixed_string_t show;
16934         cmdline_fixed_string_t vf;
16935         cmdline_fixed_string_t stats;
16936         portid_t port_id;
16937         uint16_t vf_id;
16938 };
16939
16940 /* Common CLI fields show vf stats*/
16941 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16942         TOKEN_STRING_INITIALIZER
16943                 (struct cmd_show_vf_stats_result,
16944                  show, "show");
16945 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16946         TOKEN_STRING_INITIALIZER
16947                 (struct cmd_show_vf_stats_result,
16948                  vf, "vf");
16949 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16950         TOKEN_STRING_INITIALIZER
16951                 (struct cmd_show_vf_stats_result,
16952                  stats, "stats");
16953 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16954         TOKEN_NUM_INITIALIZER
16955                 (struct cmd_show_vf_stats_result,
16956                  port_id, UINT16);
16957 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16958         TOKEN_NUM_INITIALIZER
16959                 (struct cmd_show_vf_stats_result,
16960                  vf_id, UINT16);
16961
16962 static void
16963 cmd_show_vf_stats_parsed(
16964         void *parsed_result,
16965         __attribute__((unused)) struct cmdline *cl,
16966         __attribute__((unused)) void *data)
16967 {
16968         struct cmd_show_vf_stats_result *res = parsed_result;
16969         struct rte_eth_stats stats;
16970         int ret = -ENOTSUP;
16971         static const char *nic_stats_border = "########################";
16972
16973         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16974                 return;
16975
16976         memset(&stats, 0, sizeof(stats));
16977
16978 #ifdef RTE_LIBRTE_I40E_PMD
16979         if (ret == -ENOTSUP)
16980                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16981                                                 res->vf_id,
16982                                                 &stats);
16983 #endif
16984 #ifdef RTE_LIBRTE_BNXT_PMD
16985         if (ret == -ENOTSUP)
16986                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16987                                                 res->vf_id,
16988                                                 &stats);
16989 #endif
16990
16991         switch (ret) {
16992         case 0:
16993                 break;
16994         case -EINVAL:
16995                 printf("invalid vf_id %d\n", res->vf_id);
16996                 break;
16997         case -ENODEV:
16998                 printf("invalid port_id %d\n", res->port_id);
16999                 break;
17000         case -ENOTSUP:
17001                 printf("function not implemented\n");
17002                 break;
17003         default:
17004                 printf("programming error: (%s)\n", strerror(-ret));
17005         }
17006
17007         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17008                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17009
17010         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17011                "%-"PRIu64"\n",
17012                stats.ipackets, stats.imissed, stats.ibytes);
17013         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17014         printf("  RX-nombuf:  %-10"PRIu64"\n",
17015                stats.rx_nombuf);
17016         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17017                "%-"PRIu64"\n",
17018                stats.opackets, stats.oerrors, stats.obytes);
17019
17020         printf("  %s############################%s\n",
17021                                nic_stats_border, nic_stats_border);
17022 }
17023
17024 cmdline_parse_inst_t cmd_show_vf_stats = {
17025         .f = cmd_show_vf_stats_parsed,
17026         .data = NULL,
17027         .help_str = "show vf stats <port_id> <vf_id>",
17028         .tokens = {
17029                 (void *)&cmd_show_vf_stats_show,
17030                 (void *)&cmd_show_vf_stats_vf,
17031                 (void *)&cmd_show_vf_stats_stats,
17032                 (void *)&cmd_show_vf_stats_port_id,
17033                 (void *)&cmd_show_vf_stats_vf_id,
17034                 NULL,
17035         },
17036 };
17037
17038 /* clear vf stats */
17039
17040 /* Common result structure for clear vf stats */
17041 struct cmd_clear_vf_stats_result {
17042         cmdline_fixed_string_t clear;
17043         cmdline_fixed_string_t vf;
17044         cmdline_fixed_string_t stats;
17045         portid_t port_id;
17046         uint16_t vf_id;
17047 };
17048
17049 /* Common CLI fields clear vf stats*/
17050 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17051         TOKEN_STRING_INITIALIZER
17052                 (struct cmd_clear_vf_stats_result,
17053                  clear, "clear");
17054 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17055         TOKEN_STRING_INITIALIZER
17056                 (struct cmd_clear_vf_stats_result,
17057                  vf, "vf");
17058 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17059         TOKEN_STRING_INITIALIZER
17060                 (struct cmd_clear_vf_stats_result,
17061                  stats, "stats");
17062 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17063         TOKEN_NUM_INITIALIZER
17064                 (struct cmd_clear_vf_stats_result,
17065                  port_id, UINT16);
17066 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17067         TOKEN_NUM_INITIALIZER
17068                 (struct cmd_clear_vf_stats_result,
17069                  vf_id, UINT16);
17070
17071 static void
17072 cmd_clear_vf_stats_parsed(
17073         void *parsed_result,
17074         __attribute__((unused)) struct cmdline *cl,
17075         __attribute__((unused)) void *data)
17076 {
17077         struct cmd_clear_vf_stats_result *res = parsed_result;
17078         int ret = -ENOTSUP;
17079
17080         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17081                 return;
17082
17083 #ifdef RTE_LIBRTE_I40E_PMD
17084         if (ret == -ENOTSUP)
17085                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17086                                                   res->vf_id);
17087 #endif
17088 #ifdef RTE_LIBRTE_BNXT_PMD
17089         if (ret == -ENOTSUP)
17090                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17091                                                   res->vf_id);
17092 #endif
17093
17094         switch (ret) {
17095         case 0:
17096                 break;
17097         case -EINVAL:
17098                 printf("invalid vf_id %d\n", res->vf_id);
17099                 break;
17100         case -ENODEV:
17101                 printf("invalid port_id %d\n", res->port_id);
17102                 break;
17103         case -ENOTSUP:
17104                 printf("function not implemented\n");
17105                 break;
17106         default:
17107                 printf("programming error: (%s)\n", strerror(-ret));
17108         }
17109 }
17110
17111 cmdline_parse_inst_t cmd_clear_vf_stats = {
17112         .f = cmd_clear_vf_stats_parsed,
17113         .data = NULL,
17114         .help_str = "clear vf stats <port_id> <vf_id>",
17115         .tokens = {
17116                 (void *)&cmd_clear_vf_stats_clear,
17117                 (void *)&cmd_clear_vf_stats_vf,
17118                 (void *)&cmd_clear_vf_stats_stats,
17119                 (void *)&cmd_clear_vf_stats_port_id,
17120                 (void *)&cmd_clear_vf_stats_vf_id,
17121                 NULL,
17122         },
17123 };
17124
17125 /* port config pctype mapping reset */
17126
17127 /* Common result structure for port config pctype mapping reset */
17128 struct cmd_pctype_mapping_reset_result {
17129         cmdline_fixed_string_t port;
17130         cmdline_fixed_string_t config;
17131         portid_t port_id;
17132         cmdline_fixed_string_t pctype;
17133         cmdline_fixed_string_t mapping;
17134         cmdline_fixed_string_t reset;
17135 };
17136
17137 /* Common CLI fields for port config pctype mapping reset*/
17138 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17139         TOKEN_STRING_INITIALIZER
17140                 (struct cmd_pctype_mapping_reset_result,
17141                  port, "port");
17142 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17143         TOKEN_STRING_INITIALIZER
17144                 (struct cmd_pctype_mapping_reset_result,
17145                  config, "config");
17146 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17147         TOKEN_NUM_INITIALIZER
17148                 (struct cmd_pctype_mapping_reset_result,
17149                  port_id, UINT16);
17150 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17151         TOKEN_STRING_INITIALIZER
17152                 (struct cmd_pctype_mapping_reset_result,
17153                  pctype, "pctype");
17154 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17155         TOKEN_STRING_INITIALIZER
17156                 (struct cmd_pctype_mapping_reset_result,
17157                  mapping, "mapping");
17158 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17159         TOKEN_STRING_INITIALIZER
17160                 (struct cmd_pctype_mapping_reset_result,
17161                  reset, "reset");
17162
17163 static void
17164 cmd_pctype_mapping_reset_parsed(
17165         void *parsed_result,
17166         __attribute__((unused)) struct cmdline *cl,
17167         __attribute__((unused)) void *data)
17168 {
17169         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17170         int ret = -ENOTSUP;
17171
17172         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17173                 return;
17174
17175 #ifdef RTE_LIBRTE_I40E_PMD
17176         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17177 #endif
17178
17179         switch (ret) {
17180         case 0:
17181                 break;
17182         case -ENODEV:
17183                 printf("invalid port_id %d\n", res->port_id);
17184                 break;
17185         case -ENOTSUP:
17186                 printf("function not implemented\n");
17187                 break;
17188         default:
17189                 printf("programming error: (%s)\n", strerror(-ret));
17190         }
17191 }
17192
17193 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17194         .f = cmd_pctype_mapping_reset_parsed,
17195         .data = NULL,
17196         .help_str = "port config <port_id> pctype mapping reset",
17197         .tokens = {
17198                 (void *)&cmd_pctype_mapping_reset_port,
17199                 (void *)&cmd_pctype_mapping_reset_config,
17200                 (void *)&cmd_pctype_mapping_reset_port_id,
17201                 (void *)&cmd_pctype_mapping_reset_pctype,
17202                 (void *)&cmd_pctype_mapping_reset_mapping,
17203                 (void *)&cmd_pctype_mapping_reset_reset,
17204                 NULL,
17205         },
17206 };
17207
17208 /* show port pctype mapping */
17209
17210 /* Common result structure for show port pctype mapping */
17211 struct cmd_pctype_mapping_get_result {
17212         cmdline_fixed_string_t show;
17213         cmdline_fixed_string_t port;
17214         portid_t port_id;
17215         cmdline_fixed_string_t pctype;
17216         cmdline_fixed_string_t mapping;
17217 };
17218
17219 /* Common CLI fields for pctype mapping get */
17220 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17221         TOKEN_STRING_INITIALIZER
17222                 (struct cmd_pctype_mapping_get_result,
17223                  show, "show");
17224 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17225         TOKEN_STRING_INITIALIZER
17226                 (struct cmd_pctype_mapping_get_result,
17227                  port, "port");
17228 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17229         TOKEN_NUM_INITIALIZER
17230                 (struct cmd_pctype_mapping_get_result,
17231                  port_id, UINT16);
17232 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17233         TOKEN_STRING_INITIALIZER
17234                 (struct cmd_pctype_mapping_get_result,
17235                  pctype, "pctype");
17236 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17237         TOKEN_STRING_INITIALIZER
17238                 (struct cmd_pctype_mapping_get_result,
17239                  mapping, "mapping");
17240
17241 static void
17242 cmd_pctype_mapping_get_parsed(
17243         void *parsed_result,
17244         __attribute__((unused)) struct cmdline *cl,
17245         __attribute__((unused)) void *data)
17246 {
17247         struct cmd_pctype_mapping_get_result *res = parsed_result;
17248         int ret = -ENOTSUP;
17249 #ifdef RTE_LIBRTE_I40E_PMD
17250         struct rte_pmd_i40e_flow_type_mapping
17251                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17252         int i, j, first_pctype;
17253 #endif
17254
17255         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17256                 return;
17257
17258 #ifdef RTE_LIBRTE_I40E_PMD
17259         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17260 #endif
17261
17262         switch (ret) {
17263         case 0:
17264                 break;
17265         case -ENODEV:
17266                 printf("invalid port_id %d\n", res->port_id);
17267                 return;
17268         case -ENOTSUP:
17269                 printf("function not implemented\n");
17270                 return;
17271         default:
17272                 printf("programming error: (%s)\n", strerror(-ret));
17273                 return;
17274         }
17275
17276 #ifdef RTE_LIBRTE_I40E_PMD
17277         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17278                 if (mapping[i].pctype != 0ULL) {
17279                         first_pctype = 1;
17280
17281                         printf("pctype: ");
17282                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17283                                 if (mapping[i].pctype & (1ULL << j)) {
17284                                         printf(first_pctype ?
17285                                                "%02d" : ",%02d", j);
17286                                         first_pctype = 0;
17287                                 }
17288                         }
17289                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17290                 }
17291         }
17292 #endif
17293 }
17294
17295 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17296         .f = cmd_pctype_mapping_get_parsed,
17297         .data = NULL,
17298         .help_str = "show port <port_id> pctype mapping",
17299         .tokens = {
17300                 (void *)&cmd_pctype_mapping_get_show,
17301                 (void *)&cmd_pctype_mapping_get_port,
17302                 (void *)&cmd_pctype_mapping_get_port_id,
17303                 (void *)&cmd_pctype_mapping_get_pctype,
17304                 (void *)&cmd_pctype_mapping_get_mapping,
17305                 NULL,
17306         },
17307 };
17308
17309 /* port config pctype mapping update */
17310
17311 /* Common result structure for port config pctype mapping update */
17312 struct cmd_pctype_mapping_update_result {
17313         cmdline_fixed_string_t port;
17314         cmdline_fixed_string_t config;
17315         portid_t port_id;
17316         cmdline_fixed_string_t pctype;
17317         cmdline_fixed_string_t mapping;
17318         cmdline_fixed_string_t update;
17319         cmdline_fixed_string_t pctype_list;
17320         uint16_t flow_type;
17321 };
17322
17323 /* Common CLI fields for pctype mapping update*/
17324 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17325         TOKEN_STRING_INITIALIZER
17326                 (struct cmd_pctype_mapping_update_result,
17327                  port, "port");
17328 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17329         TOKEN_STRING_INITIALIZER
17330                 (struct cmd_pctype_mapping_update_result,
17331                  config, "config");
17332 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17333         TOKEN_NUM_INITIALIZER
17334                 (struct cmd_pctype_mapping_update_result,
17335                  port_id, UINT16);
17336 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17337         TOKEN_STRING_INITIALIZER
17338                 (struct cmd_pctype_mapping_update_result,
17339                  pctype, "pctype");
17340 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17341         TOKEN_STRING_INITIALIZER
17342                 (struct cmd_pctype_mapping_update_result,
17343                  mapping, "mapping");
17344 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17345         TOKEN_STRING_INITIALIZER
17346                 (struct cmd_pctype_mapping_update_result,
17347                  update, "update");
17348 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17349         TOKEN_STRING_INITIALIZER
17350                 (struct cmd_pctype_mapping_update_result,
17351                  pctype_list, NULL);
17352 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17353         TOKEN_NUM_INITIALIZER
17354                 (struct cmd_pctype_mapping_update_result,
17355                  flow_type, UINT16);
17356
17357 static void
17358 cmd_pctype_mapping_update_parsed(
17359         void *parsed_result,
17360         __attribute__((unused)) struct cmdline *cl,
17361         __attribute__((unused)) void *data)
17362 {
17363         struct cmd_pctype_mapping_update_result *res = parsed_result;
17364         int ret = -ENOTSUP;
17365 #ifdef RTE_LIBRTE_I40E_PMD
17366         struct rte_pmd_i40e_flow_type_mapping mapping;
17367         unsigned int i;
17368         unsigned int nb_item;
17369         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17370 #endif
17371
17372         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17373                 return;
17374
17375 #ifdef RTE_LIBRTE_I40E_PMD
17376         nb_item = parse_item_list(res->pctype_list, "pctypes",
17377                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17378         mapping.flow_type = res->flow_type;
17379         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17380                 mapping.pctype |= (1ULL << pctype_list[i]);
17381         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17382                                                 &mapping,
17383                                                 1,
17384                                                 0);
17385 #endif
17386
17387         switch (ret) {
17388         case 0:
17389                 break;
17390         case -EINVAL:
17391                 printf("invalid pctype or flow type\n");
17392                 break;
17393         case -ENODEV:
17394                 printf("invalid port_id %d\n", res->port_id);
17395                 break;
17396         case -ENOTSUP:
17397                 printf("function not implemented\n");
17398                 break;
17399         default:
17400                 printf("programming error: (%s)\n", strerror(-ret));
17401         }
17402 }
17403
17404 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17405         .f = cmd_pctype_mapping_update_parsed,
17406         .data = NULL,
17407         .help_str = "port config <port_id> pctype mapping update"
17408         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17409         .tokens = {
17410                 (void *)&cmd_pctype_mapping_update_port,
17411                 (void *)&cmd_pctype_mapping_update_config,
17412                 (void *)&cmd_pctype_mapping_update_port_id,
17413                 (void *)&cmd_pctype_mapping_update_pctype,
17414                 (void *)&cmd_pctype_mapping_update_mapping,
17415                 (void *)&cmd_pctype_mapping_update_update,
17416                 (void *)&cmd_pctype_mapping_update_pc_type,
17417                 (void *)&cmd_pctype_mapping_update_flow_type,
17418                 NULL,
17419         },
17420 };
17421
17422 /* ptype mapping get */
17423
17424 /* Common result structure for ptype mapping get */
17425 struct cmd_ptype_mapping_get_result {
17426         cmdline_fixed_string_t ptype;
17427         cmdline_fixed_string_t mapping;
17428         cmdline_fixed_string_t get;
17429         portid_t port_id;
17430         uint8_t valid_only;
17431 };
17432
17433 /* Common CLI fields for ptype mapping get */
17434 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17435         TOKEN_STRING_INITIALIZER
17436                 (struct cmd_ptype_mapping_get_result,
17437                  ptype, "ptype");
17438 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17439         TOKEN_STRING_INITIALIZER
17440                 (struct cmd_ptype_mapping_get_result,
17441                  mapping, "mapping");
17442 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17443         TOKEN_STRING_INITIALIZER
17444                 (struct cmd_ptype_mapping_get_result,
17445                  get, "get");
17446 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17447         TOKEN_NUM_INITIALIZER
17448                 (struct cmd_ptype_mapping_get_result,
17449                  port_id, UINT16);
17450 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17451         TOKEN_NUM_INITIALIZER
17452                 (struct cmd_ptype_mapping_get_result,
17453                  valid_only, UINT8);
17454
17455 static void
17456 cmd_ptype_mapping_get_parsed(
17457         void *parsed_result,
17458         __attribute__((unused)) struct cmdline *cl,
17459         __attribute__((unused)) void *data)
17460 {
17461         struct cmd_ptype_mapping_get_result *res = parsed_result;
17462         int ret = -ENOTSUP;
17463 #ifdef RTE_LIBRTE_I40E_PMD
17464         int max_ptype_num = 256;
17465         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17466         uint16_t count;
17467         int i;
17468 #endif
17469
17470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17471                 return;
17472
17473 #ifdef RTE_LIBRTE_I40E_PMD
17474         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17475                                         mapping,
17476                                         max_ptype_num,
17477                                         &count,
17478                                         res->valid_only);
17479 #endif
17480
17481         switch (ret) {
17482         case 0:
17483                 break;
17484         case -ENODEV:
17485                 printf("invalid port_id %d\n", res->port_id);
17486                 break;
17487         case -ENOTSUP:
17488                 printf("function not implemented\n");
17489                 break;
17490         default:
17491                 printf("programming error: (%s)\n", strerror(-ret));
17492         }
17493
17494 #ifdef RTE_LIBRTE_I40E_PMD
17495         if (!ret) {
17496                 for (i = 0; i < count; i++)
17497                         printf("%3d\t0x%08x\n",
17498                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17499         }
17500 #endif
17501 }
17502
17503 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17504         .f = cmd_ptype_mapping_get_parsed,
17505         .data = NULL,
17506         .help_str = "ptype mapping get <port_id> <valid_only>",
17507         .tokens = {
17508                 (void *)&cmd_ptype_mapping_get_ptype,
17509                 (void *)&cmd_ptype_mapping_get_mapping,
17510                 (void *)&cmd_ptype_mapping_get_get,
17511                 (void *)&cmd_ptype_mapping_get_port_id,
17512                 (void *)&cmd_ptype_mapping_get_valid_only,
17513                 NULL,
17514         },
17515 };
17516
17517 /* ptype mapping replace */
17518
17519 /* Common result structure for ptype mapping replace */
17520 struct cmd_ptype_mapping_replace_result {
17521         cmdline_fixed_string_t ptype;
17522         cmdline_fixed_string_t mapping;
17523         cmdline_fixed_string_t replace;
17524         portid_t port_id;
17525         uint32_t target;
17526         uint8_t mask;
17527         uint32_t pkt_type;
17528 };
17529
17530 /* Common CLI fields for ptype mapping replace */
17531 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17532         TOKEN_STRING_INITIALIZER
17533                 (struct cmd_ptype_mapping_replace_result,
17534                  ptype, "ptype");
17535 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17536         TOKEN_STRING_INITIALIZER
17537                 (struct cmd_ptype_mapping_replace_result,
17538                  mapping, "mapping");
17539 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17540         TOKEN_STRING_INITIALIZER
17541                 (struct cmd_ptype_mapping_replace_result,
17542                  replace, "replace");
17543 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17544         TOKEN_NUM_INITIALIZER
17545                 (struct cmd_ptype_mapping_replace_result,
17546                  port_id, UINT16);
17547 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17548         TOKEN_NUM_INITIALIZER
17549                 (struct cmd_ptype_mapping_replace_result,
17550                  target, UINT32);
17551 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17552         TOKEN_NUM_INITIALIZER
17553                 (struct cmd_ptype_mapping_replace_result,
17554                  mask, UINT8);
17555 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17556         TOKEN_NUM_INITIALIZER
17557                 (struct cmd_ptype_mapping_replace_result,
17558                  pkt_type, UINT32);
17559
17560 static void
17561 cmd_ptype_mapping_replace_parsed(
17562         void *parsed_result,
17563         __attribute__((unused)) struct cmdline *cl,
17564         __attribute__((unused)) void *data)
17565 {
17566         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17567         int ret = -ENOTSUP;
17568
17569         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17570                 return;
17571
17572 #ifdef RTE_LIBRTE_I40E_PMD
17573         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17574                                         res->target,
17575                                         res->mask,
17576                                         res->pkt_type);
17577 #endif
17578
17579         switch (ret) {
17580         case 0:
17581                 break;
17582         case -EINVAL:
17583                 printf("invalid ptype 0x%8x or 0x%8x\n",
17584                                 res->target, res->pkt_type);
17585                 break;
17586         case -ENODEV:
17587                 printf("invalid port_id %d\n", res->port_id);
17588                 break;
17589         case -ENOTSUP:
17590                 printf("function not implemented\n");
17591                 break;
17592         default:
17593                 printf("programming error: (%s)\n", strerror(-ret));
17594         }
17595 }
17596
17597 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17598         .f = cmd_ptype_mapping_replace_parsed,
17599         .data = NULL,
17600         .help_str =
17601                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17602         .tokens = {
17603                 (void *)&cmd_ptype_mapping_replace_ptype,
17604                 (void *)&cmd_ptype_mapping_replace_mapping,
17605                 (void *)&cmd_ptype_mapping_replace_replace,
17606                 (void *)&cmd_ptype_mapping_replace_port_id,
17607                 (void *)&cmd_ptype_mapping_replace_target,
17608                 (void *)&cmd_ptype_mapping_replace_mask,
17609                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17610                 NULL,
17611         },
17612 };
17613
17614 /* ptype mapping reset */
17615
17616 /* Common result structure for ptype mapping reset */
17617 struct cmd_ptype_mapping_reset_result {
17618         cmdline_fixed_string_t ptype;
17619         cmdline_fixed_string_t mapping;
17620         cmdline_fixed_string_t reset;
17621         portid_t port_id;
17622 };
17623
17624 /* Common CLI fields for ptype mapping reset*/
17625 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17626         TOKEN_STRING_INITIALIZER
17627                 (struct cmd_ptype_mapping_reset_result,
17628                  ptype, "ptype");
17629 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17630         TOKEN_STRING_INITIALIZER
17631                 (struct cmd_ptype_mapping_reset_result,
17632                  mapping, "mapping");
17633 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17634         TOKEN_STRING_INITIALIZER
17635                 (struct cmd_ptype_mapping_reset_result,
17636                  reset, "reset");
17637 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17638         TOKEN_NUM_INITIALIZER
17639                 (struct cmd_ptype_mapping_reset_result,
17640                  port_id, UINT16);
17641
17642 static void
17643 cmd_ptype_mapping_reset_parsed(
17644         void *parsed_result,
17645         __attribute__((unused)) struct cmdline *cl,
17646         __attribute__((unused)) void *data)
17647 {
17648         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17649         int ret = -ENOTSUP;
17650
17651         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17652                 return;
17653
17654 #ifdef RTE_LIBRTE_I40E_PMD
17655         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17656 #endif
17657
17658         switch (ret) {
17659         case 0:
17660                 break;
17661         case -ENODEV:
17662                 printf("invalid port_id %d\n", res->port_id);
17663                 break;
17664         case -ENOTSUP:
17665                 printf("function not implemented\n");
17666                 break;
17667         default:
17668                 printf("programming error: (%s)\n", strerror(-ret));
17669         }
17670 }
17671
17672 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17673         .f = cmd_ptype_mapping_reset_parsed,
17674         .data = NULL,
17675         .help_str = "ptype mapping reset <port_id>",
17676         .tokens = {
17677                 (void *)&cmd_ptype_mapping_reset_ptype,
17678                 (void *)&cmd_ptype_mapping_reset_mapping,
17679                 (void *)&cmd_ptype_mapping_reset_reset,
17680                 (void *)&cmd_ptype_mapping_reset_port_id,
17681                 NULL,
17682         },
17683 };
17684
17685 /* ptype mapping update */
17686
17687 /* Common result structure for ptype mapping update */
17688 struct cmd_ptype_mapping_update_result {
17689         cmdline_fixed_string_t ptype;
17690         cmdline_fixed_string_t mapping;
17691         cmdline_fixed_string_t reset;
17692         portid_t port_id;
17693         uint8_t hw_ptype;
17694         uint32_t sw_ptype;
17695 };
17696
17697 /* Common CLI fields for ptype mapping update*/
17698 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17699         TOKEN_STRING_INITIALIZER
17700                 (struct cmd_ptype_mapping_update_result,
17701                  ptype, "ptype");
17702 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17703         TOKEN_STRING_INITIALIZER
17704                 (struct cmd_ptype_mapping_update_result,
17705                  mapping, "mapping");
17706 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17707         TOKEN_STRING_INITIALIZER
17708                 (struct cmd_ptype_mapping_update_result,
17709                  reset, "update");
17710 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17711         TOKEN_NUM_INITIALIZER
17712                 (struct cmd_ptype_mapping_update_result,
17713                  port_id, UINT16);
17714 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17715         TOKEN_NUM_INITIALIZER
17716                 (struct cmd_ptype_mapping_update_result,
17717                  hw_ptype, UINT8);
17718 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17719         TOKEN_NUM_INITIALIZER
17720                 (struct cmd_ptype_mapping_update_result,
17721                  sw_ptype, UINT32);
17722
17723 static void
17724 cmd_ptype_mapping_update_parsed(
17725         void *parsed_result,
17726         __attribute__((unused)) struct cmdline *cl,
17727         __attribute__((unused)) void *data)
17728 {
17729         struct cmd_ptype_mapping_update_result *res = parsed_result;
17730         int ret = -ENOTSUP;
17731 #ifdef RTE_LIBRTE_I40E_PMD
17732         struct rte_pmd_i40e_ptype_mapping mapping;
17733 #endif
17734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17735                 return;
17736
17737 #ifdef RTE_LIBRTE_I40E_PMD
17738         mapping.hw_ptype = res->hw_ptype;
17739         mapping.sw_ptype = res->sw_ptype;
17740         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17741                                                 &mapping,
17742                                                 1,
17743                                                 0);
17744 #endif
17745
17746         switch (ret) {
17747         case 0:
17748                 break;
17749         case -EINVAL:
17750                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17751                 break;
17752         case -ENODEV:
17753                 printf("invalid port_id %d\n", res->port_id);
17754                 break;
17755         case -ENOTSUP:
17756                 printf("function not implemented\n");
17757                 break;
17758         default:
17759                 printf("programming error: (%s)\n", strerror(-ret));
17760         }
17761 }
17762
17763 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17764         .f = cmd_ptype_mapping_update_parsed,
17765         .data = NULL,
17766         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17767         .tokens = {
17768                 (void *)&cmd_ptype_mapping_update_ptype,
17769                 (void *)&cmd_ptype_mapping_update_mapping,
17770                 (void *)&cmd_ptype_mapping_update_update,
17771                 (void *)&cmd_ptype_mapping_update_port_id,
17772                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17773                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17774                 NULL,
17775         },
17776 };
17777
17778 /* Common result structure for file commands */
17779 struct cmd_cmdfile_result {
17780         cmdline_fixed_string_t load;
17781         cmdline_fixed_string_t filename;
17782 };
17783
17784 /* Common CLI fields for file commands */
17785 cmdline_parse_token_string_t cmd_load_cmdfile =
17786         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17787 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17788         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17789
17790 static void
17791 cmd_load_from_file_parsed(
17792         void *parsed_result,
17793         __attribute__((unused)) struct cmdline *cl,
17794         __attribute__((unused)) void *data)
17795 {
17796         struct cmd_cmdfile_result *res = parsed_result;
17797
17798         cmdline_read_from_file(res->filename);
17799 }
17800
17801 cmdline_parse_inst_t cmd_load_from_file = {
17802         .f = cmd_load_from_file_parsed,
17803         .data = NULL,
17804         .help_str = "load <filename>",
17805         .tokens = {
17806                 (void *)&cmd_load_cmdfile,
17807                 (void *)&cmd_load_cmdfile_filename,
17808                 NULL,
17809         },
17810 };
17811
17812 /* Get Rx offloads capabilities */
17813 struct cmd_rx_offload_get_capa_result {
17814         cmdline_fixed_string_t show;
17815         cmdline_fixed_string_t port;
17816         portid_t port_id;
17817         cmdline_fixed_string_t rx_offload;
17818         cmdline_fixed_string_t capabilities;
17819 };
17820
17821 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17822         TOKEN_STRING_INITIALIZER
17823                 (struct cmd_rx_offload_get_capa_result,
17824                  show, "show");
17825 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17826         TOKEN_STRING_INITIALIZER
17827                 (struct cmd_rx_offload_get_capa_result,
17828                  port, "port");
17829 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17830         TOKEN_NUM_INITIALIZER
17831                 (struct cmd_rx_offload_get_capa_result,
17832                  port_id, UINT16);
17833 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17834         TOKEN_STRING_INITIALIZER
17835                 (struct cmd_rx_offload_get_capa_result,
17836                  rx_offload, "rx_offload");
17837 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17838         TOKEN_STRING_INITIALIZER
17839                 (struct cmd_rx_offload_get_capa_result,
17840                  capabilities, "capabilities");
17841
17842 static void
17843 print_rx_offloads(uint64_t offloads)
17844 {
17845         uint64_t single_offload;
17846         int begin;
17847         int end;
17848         int bit;
17849
17850         if (offloads == 0)
17851                 return;
17852
17853         begin = __builtin_ctzll(offloads);
17854         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17855
17856         single_offload = 1ULL << begin;
17857         for (bit = begin; bit < end; bit++) {
17858                 if (offloads & single_offload)
17859                         printf(" %s",
17860                                rte_eth_dev_rx_offload_name(single_offload));
17861                 single_offload <<= 1;
17862         }
17863 }
17864
17865 static void
17866 cmd_rx_offload_get_capa_parsed(
17867         void *parsed_result,
17868         __attribute__((unused)) struct cmdline *cl,
17869         __attribute__((unused)) void *data)
17870 {
17871         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17872         struct rte_eth_dev_info dev_info;
17873         portid_t port_id = res->port_id;
17874         uint64_t queue_offloads;
17875         uint64_t port_offloads;
17876
17877         rte_eth_dev_info_get(port_id, &dev_info);
17878         queue_offloads = dev_info.rx_queue_offload_capa;
17879         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17880
17881         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17882         printf("  Per Queue :");
17883         print_rx_offloads(queue_offloads);
17884
17885         printf("\n");
17886         printf("  Per Port  :");
17887         print_rx_offloads(port_offloads);
17888         printf("\n\n");
17889 }
17890
17891 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17892         .f = cmd_rx_offload_get_capa_parsed,
17893         .data = NULL,
17894         .help_str = "show port <port_id> rx_offload capabilities",
17895         .tokens = {
17896                 (void *)&cmd_rx_offload_get_capa_show,
17897                 (void *)&cmd_rx_offload_get_capa_port,
17898                 (void *)&cmd_rx_offload_get_capa_port_id,
17899                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17900                 (void *)&cmd_rx_offload_get_capa_capabilities,
17901                 NULL,
17902         }
17903 };
17904
17905 /* Get Rx offloads configuration */
17906 struct cmd_rx_offload_get_configuration_result {
17907         cmdline_fixed_string_t show;
17908         cmdline_fixed_string_t port;
17909         portid_t port_id;
17910         cmdline_fixed_string_t rx_offload;
17911         cmdline_fixed_string_t configuration;
17912 };
17913
17914 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17915         TOKEN_STRING_INITIALIZER
17916                 (struct cmd_rx_offload_get_configuration_result,
17917                  show, "show");
17918 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17919         TOKEN_STRING_INITIALIZER
17920                 (struct cmd_rx_offload_get_configuration_result,
17921                  port, "port");
17922 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17923         TOKEN_NUM_INITIALIZER
17924                 (struct cmd_rx_offload_get_configuration_result,
17925                  port_id, UINT16);
17926 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17927         TOKEN_STRING_INITIALIZER
17928                 (struct cmd_rx_offload_get_configuration_result,
17929                  rx_offload, "rx_offload");
17930 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17931         TOKEN_STRING_INITIALIZER
17932                 (struct cmd_rx_offload_get_configuration_result,
17933                  configuration, "configuration");
17934
17935 static void
17936 cmd_rx_offload_get_configuration_parsed(
17937         void *parsed_result,
17938         __attribute__((unused)) struct cmdline *cl,
17939         __attribute__((unused)) void *data)
17940 {
17941         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17942         struct rte_eth_dev_info dev_info;
17943         portid_t port_id = res->port_id;
17944         struct rte_port *port = &ports[port_id];
17945         uint64_t port_offloads;
17946         uint64_t queue_offloads;
17947         uint16_t nb_rx_queues;
17948         int q;
17949
17950         printf("Rx Offloading Configuration of port %d :\n", port_id);
17951
17952         port_offloads = port->dev_conf.rxmode.offloads;
17953         printf("  Port :");
17954         print_rx_offloads(port_offloads);
17955         printf("\n");
17956
17957         rte_eth_dev_info_get(port_id, &dev_info);
17958         nb_rx_queues = dev_info.nb_rx_queues;
17959         for (q = 0; q < nb_rx_queues; q++) {
17960                 queue_offloads = port->rx_conf[q].offloads;
17961                 printf("  Queue[%2d] :", q);
17962                 print_rx_offloads(queue_offloads);
17963                 printf("\n");
17964         }
17965         printf("\n");
17966 }
17967
17968 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17969         .f = cmd_rx_offload_get_configuration_parsed,
17970         .data = NULL,
17971         .help_str = "show port <port_id> rx_offload configuration",
17972         .tokens = {
17973                 (void *)&cmd_rx_offload_get_configuration_show,
17974                 (void *)&cmd_rx_offload_get_configuration_port,
17975                 (void *)&cmd_rx_offload_get_configuration_port_id,
17976                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17977                 (void *)&cmd_rx_offload_get_configuration_configuration,
17978                 NULL,
17979         }
17980 };
17981
17982 /* Enable/Disable a per port offloading */
17983 struct cmd_config_per_port_rx_offload_result {
17984         cmdline_fixed_string_t port;
17985         cmdline_fixed_string_t config;
17986         portid_t port_id;
17987         cmdline_fixed_string_t rx_offload;
17988         cmdline_fixed_string_t offload;
17989         cmdline_fixed_string_t on_off;
17990 };
17991
17992 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17993         TOKEN_STRING_INITIALIZER
17994                 (struct cmd_config_per_port_rx_offload_result,
17995                  port, "port");
17996 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17997         TOKEN_STRING_INITIALIZER
17998                 (struct cmd_config_per_port_rx_offload_result,
17999                  config, "config");
18000 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18001         TOKEN_NUM_INITIALIZER
18002                 (struct cmd_config_per_port_rx_offload_result,
18003                  port_id, UINT16);
18004 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18005         TOKEN_STRING_INITIALIZER
18006                 (struct cmd_config_per_port_rx_offload_result,
18007                  rx_offload, "rx_offload");
18008 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18009         TOKEN_STRING_INITIALIZER
18010                 (struct cmd_config_per_port_rx_offload_result,
18011                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18012                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18013                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18014                            "crc_strip#scatter#timestamp#security#keep_crc");
18015 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18016         TOKEN_STRING_INITIALIZER
18017                 (struct cmd_config_per_port_rx_offload_result,
18018                  on_off, "on#off");
18019
18020 static uint64_t
18021 search_rx_offload(const char *name)
18022 {
18023         uint64_t single_offload;
18024         const char *single_name;
18025         int found = 0;
18026         unsigned int bit;
18027
18028         single_offload = 1;
18029         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18030                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18031                 if (!strcasecmp(single_name, name)) {
18032                         found = 1;
18033                         break;
18034                 }
18035                 single_offload <<= 1;
18036         }
18037
18038         if (found)
18039                 return single_offload;
18040
18041         return 0;
18042 }
18043
18044 static void
18045 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18046                                 __attribute__((unused)) struct cmdline *cl,
18047                                 __attribute__((unused)) void *data)
18048 {
18049         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18050         portid_t port_id = res->port_id;
18051         struct rte_eth_dev_info dev_info;
18052         struct rte_port *port = &ports[port_id];
18053         uint64_t single_offload;
18054         uint16_t nb_rx_queues;
18055         int q;
18056
18057         if (port->port_status != RTE_PORT_STOPPED) {
18058                 printf("Error: Can't config offload when Port %d "
18059                        "is not stopped\n", port_id);
18060                 return;
18061         }
18062
18063         single_offload = search_rx_offload(res->offload);
18064         if (single_offload == 0) {
18065                 printf("Unknown offload name: %s\n", res->offload);
18066                 return;
18067         }
18068
18069         rte_eth_dev_info_get(port_id, &dev_info);
18070         nb_rx_queues = dev_info.nb_rx_queues;
18071         if (!strcmp(res->on_off, "on")) {
18072                 port->dev_conf.rxmode.offloads |= single_offload;
18073                 for (q = 0; q < nb_rx_queues; q++)
18074                         port->rx_conf[q].offloads |= single_offload;
18075         } else {
18076                 port->dev_conf.rxmode.offloads &= ~single_offload;
18077                 for (q = 0; q < nb_rx_queues; q++)
18078                         port->rx_conf[q].offloads &= ~single_offload;
18079         }
18080
18081         cmd_reconfig_device_queue(port_id, 1, 1);
18082 }
18083
18084 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18085         .f = cmd_config_per_port_rx_offload_parsed,
18086         .data = NULL,
18087         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18088                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18089                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18090                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18091                     "on|off",
18092         .tokens = {
18093                 (void *)&cmd_config_per_port_rx_offload_result_port,
18094                 (void *)&cmd_config_per_port_rx_offload_result_config,
18095                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18096                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18097                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18098                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18099                 NULL,
18100         }
18101 };
18102
18103 /* Enable/Disable a per queue offloading */
18104 struct cmd_config_per_queue_rx_offload_result {
18105         cmdline_fixed_string_t port;
18106         portid_t port_id;
18107         cmdline_fixed_string_t rxq;
18108         uint16_t queue_id;
18109         cmdline_fixed_string_t rx_offload;
18110         cmdline_fixed_string_t offload;
18111         cmdline_fixed_string_t on_off;
18112 };
18113
18114 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18115         TOKEN_STRING_INITIALIZER
18116                 (struct cmd_config_per_queue_rx_offload_result,
18117                  port, "port");
18118 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18119         TOKEN_NUM_INITIALIZER
18120                 (struct cmd_config_per_queue_rx_offload_result,
18121                  port_id, UINT16);
18122 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18123         TOKEN_STRING_INITIALIZER
18124                 (struct cmd_config_per_queue_rx_offload_result,
18125                  rxq, "rxq");
18126 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18127         TOKEN_NUM_INITIALIZER
18128                 (struct cmd_config_per_queue_rx_offload_result,
18129                  queue_id, UINT16);
18130 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18131         TOKEN_STRING_INITIALIZER
18132                 (struct cmd_config_per_queue_rx_offload_result,
18133                  rx_offload, "rx_offload");
18134 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18135         TOKEN_STRING_INITIALIZER
18136                 (struct cmd_config_per_queue_rx_offload_result,
18137                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18138                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18139                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18140                            "crc_strip#scatter#timestamp#security#keep_crc");
18141 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18142         TOKEN_STRING_INITIALIZER
18143                 (struct cmd_config_per_queue_rx_offload_result,
18144                  on_off, "on#off");
18145
18146 static void
18147 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18148                                 __attribute__((unused)) struct cmdline *cl,
18149                                 __attribute__((unused)) void *data)
18150 {
18151         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18152         struct rte_eth_dev_info dev_info;
18153         portid_t port_id = res->port_id;
18154         uint16_t queue_id = res->queue_id;
18155         struct rte_port *port = &ports[port_id];
18156         uint64_t single_offload;
18157
18158         if (port->port_status != RTE_PORT_STOPPED) {
18159                 printf("Error: Can't config offload when Port %d "
18160                        "is not stopped\n", port_id);
18161                 return;
18162         }
18163
18164         rte_eth_dev_info_get(port_id, &dev_info);
18165         if (queue_id >= dev_info.nb_rx_queues) {
18166                 printf("Error: input queue_id should be 0 ... "
18167                        "%d\n", dev_info.nb_rx_queues - 1);
18168                 return;
18169         }
18170
18171         single_offload = search_rx_offload(res->offload);
18172         if (single_offload == 0) {
18173                 printf("Unknown offload name: %s\n", res->offload);
18174                 return;
18175         }
18176
18177         if (!strcmp(res->on_off, "on"))
18178                 port->rx_conf[queue_id].offloads |= single_offload;
18179         else
18180                 port->rx_conf[queue_id].offloads &= ~single_offload;
18181
18182         cmd_reconfig_device_queue(port_id, 1, 1);
18183 }
18184
18185 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18186         .f = cmd_config_per_queue_rx_offload_parsed,
18187         .data = NULL,
18188         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18189                     "vlan_strip|ipv4_cksum|"
18190                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18191                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18192                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18193                     "on|off",
18194         .tokens = {
18195                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18196                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18197                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18198                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18199                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18200                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18201                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18202                 NULL,
18203         }
18204 };
18205
18206 /* Get Tx offloads capabilities */
18207 struct cmd_tx_offload_get_capa_result {
18208         cmdline_fixed_string_t show;
18209         cmdline_fixed_string_t port;
18210         portid_t port_id;
18211         cmdline_fixed_string_t tx_offload;
18212         cmdline_fixed_string_t capabilities;
18213 };
18214
18215 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18216         TOKEN_STRING_INITIALIZER
18217                 (struct cmd_tx_offload_get_capa_result,
18218                  show, "show");
18219 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18220         TOKEN_STRING_INITIALIZER
18221                 (struct cmd_tx_offload_get_capa_result,
18222                  port, "port");
18223 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18224         TOKEN_NUM_INITIALIZER
18225                 (struct cmd_tx_offload_get_capa_result,
18226                  port_id, UINT16);
18227 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18228         TOKEN_STRING_INITIALIZER
18229                 (struct cmd_tx_offload_get_capa_result,
18230                  tx_offload, "tx_offload");
18231 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18232         TOKEN_STRING_INITIALIZER
18233                 (struct cmd_tx_offload_get_capa_result,
18234                  capabilities, "capabilities");
18235
18236 static void
18237 print_tx_offloads(uint64_t offloads)
18238 {
18239         uint64_t single_offload;
18240         int begin;
18241         int end;
18242         int bit;
18243
18244         if (offloads == 0)
18245                 return;
18246
18247         begin = __builtin_ctzll(offloads);
18248         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18249
18250         single_offload = 1ULL << begin;
18251         for (bit = begin; bit < end; bit++) {
18252                 if (offloads & single_offload)
18253                         printf(" %s",
18254                                rte_eth_dev_tx_offload_name(single_offload));
18255                 single_offload <<= 1;
18256         }
18257 }
18258
18259 static void
18260 cmd_tx_offload_get_capa_parsed(
18261         void *parsed_result,
18262         __attribute__((unused)) struct cmdline *cl,
18263         __attribute__((unused)) void *data)
18264 {
18265         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18266         struct rte_eth_dev_info dev_info;
18267         portid_t port_id = res->port_id;
18268         uint64_t queue_offloads;
18269         uint64_t port_offloads;
18270
18271         rte_eth_dev_info_get(port_id, &dev_info);
18272         queue_offloads = dev_info.tx_queue_offload_capa;
18273         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18274
18275         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18276         printf("  Per Queue :");
18277         print_tx_offloads(queue_offloads);
18278
18279         printf("\n");
18280         printf("  Per Port  :");
18281         print_tx_offloads(port_offloads);
18282         printf("\n\n");
18283 }
18284
18285 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18286         .f = cmd_tx_offload_get_capa_parsed,
18287         .data = NULL,
18288         .help_str = "show port <port_id> tx_offload capabilities",
18289         .tokens = {
18290                 (void *)&cmd_tx_offload_get_capa_show,
18291                 (void *)&cmd_tx_offload_get_capa_port,
18292                 (void *)&cmd_tx_offload_get_capa_port_id,
18293                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18294                 (void *)&cmd_tx_offload_get_capa_capabilities,
18295                 NULL,
18296         }
18297 };
18298
18299 /* Get Tx offloads configuration */
18300 struct cmd_tx_offload_get_configuration_result {
18301         cmdline_fixed_string_t show;
18302         cmdline_fixed_string_t port;
18303         portid_t port_id;
18304         cmdline_fixed_string_t tx_offload;
18305         cmdline_fixed_string_t configuration;
18306 };
18307
18308 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18309         TOKEN_STRING_INITIALIZER
18310                 (struct cmd_tx_offload_get_configuration_result,
18311                  show, "show");
18312 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18313         TOKEN_STRING_INITIALIZER
18314                 (struct cmd_tx_offload_get_configuration_result,
18315                  port, "port");
18316 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18317         TOKEN_NUM_INITIALIZER
18318                 (struct cmd_tx_offload_get_configuration_result,
18319                  port_id, UINT16);
18320 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18321         TOKEN_STRING_INITIALIZER
18322                 (struct cmd_tx_offload_get_configuration_result,
18323                  tx_offload, "tx_offload");
18324 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18325         TOKEN_STRING_INITIALIZER
18326                 (struct cmd_tx_offload_get_configuration_result,
18327                  configuration, "configuration");
18328
18329 static void
18330 cmd_tx_offload_get_configuration_parsed(
18331         void *parsed_result,
18332         __attribute__((unused)) struct cmdline *cl,
18333         __attribute__((unused)) void *data)
18334 {
18335         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18336         struct rte_eth_dev_info dev_info;
18337         portid_t port_id = res->port_id;
18338         struct rte_port *port = &ports[port_id];
18339         uint64_t port_offloads;
18340         uint64_t queue_offloads;
18341         uint16_t nb_tx_queues;
18342         int q;
18343
18344         printf("Tx Offloading Configuration of port %d :\n", port_id);
18345
18346         port_offloads = port->dev_conf.txmode.offloads;
18347         printf("  Port :");
18348         print_tx_offloads(port_offloads);
18349         printf("\n");
18350
18351         rte_eth_dev_info_get(port_id, &dev_info);
18352         nb_tx_queues = dev_info.nb_tx_queues;
18353         for (q = 0; q < nb_tx_queues; q++) {
18354                 queue_offloads = port->tx_conf[q].offloads;
18355                 printf("  Queue[%2d] :", q);
18356                 print_tx_offloads(queue_offloads);
18357                 printf("\n");
18358         }
18359         printf("\n");
18360 }
18361
18362 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18363         .f = cmd_tx_offload_get_configuration_parsed,
18364         .data = NULL,
18365         .help_str = "show port <port_id> tx_offload configuration",
18366         .tokens = {
18367                 (void *)&cmd_tx_offload_get_configuration_show,
18368                 (void *)&cmd_tx_offload_get_configuration_port,
18369                 (void *)&cmd_tx_offload_get_configuration_port_id,
18370                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18371                 (void *)&cmd_tx_offload_get_configuration_configuration,
18372                 NULL,
18373         }
18374 };
18375
18376 /* Enable/Disable a per port offloading */
18377 struct cmd_config_per_port_tx_offload_result {
18378         cmdline_fixed_string_t port;
18379         cmdline_fixed_string_t config;
18380         portid_t port_id;
18381         cmdline_fixed_string_t tx_offload;
18382         cmdline_fixed_string_t offload;
18383         cmdline_fixed_string_t on_off;
18384 };
18385
18386 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18387         TOKEN_STRING_INITIALIZER
18388                 (struct cmd_config_per_port_tx_offload_result,
18389                  port, "port");
18390 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18391         TOKEN_STRING_INITIALIZER
18392                 (struct cmd_config_per_port_tx_offload_result,
18393                  config, "config");
18394 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18395         TOKEN_NUM_INITIALIZER
18396                 (struct cmd_config_per_port_tx_offload_result,
18397                  port_id, UINT16);
18398 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18399         TOKEN_STRING_INITIALIZER
18400                 (struct cmd_config_per_port_tx_offload_result,
18401                  tx_offload, "tx_offload");
18402 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18403         TOKEN_STRING_INITIALIZER
18404                 (struct cmd_config_per_port_tx_offload_result,
18405                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18406                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18407                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18408                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18409                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18410                           "match_metadata");
18411 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18412         TOKEN_STRING_INITIALIZER
18413                 (struct cmd_config_per_port_tx_offload_result,
18414                  on_off, "on#off");
18415
18416 static uint64_t
18417 search_tx_offload(const char *name)
18418 {
18419         uint64_t single_offload;
18420         const char *single_name;
18421         int found = 0;
18422         unsigned int bit;
18423
18424         single_offload = 1;
18425         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18426                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18427                 if (single_name == NULL)
18428                         break;
18429                 if (!strcasecmp(single_name, name)) {
18430                         found = 1;
18431                         break;
18432                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18433                         break;
18434                 single_offload <<= 1;
18435         }
18436
18437         if (found)
18438                 return single_offload;
18439
18440         return 0;
18441 }
18442
18443 static void
18444 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18445                                 __attribute__((unused)) struct cmdline *cl,
18446                                 __attribute__((unused)) void *data)
18447 {
18448         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18449         portid_t port_id = res->port_id;
18450         struct rte_eth_dev_info dev_info;
18451         struct rte_port *port = &ports[port_id];
18452         uint64_t single_offload;
18453         uint16_t nb_tx_queues;
18454         int q;
18455
18456         if (port->port_status != RTE_PORT_STOPPED) {
18457                 printf("Error: Can't config offload when Port %d "
18458                        "is not stopped\n", port_id);
18459                 return;
18460         }
18461
18462         single_offload = search_tx_offload(res->offload);
18463         if (single_offload == 0) {
18464                 printf("Unknown offload name: %s\n", res->offload);
18465                 return;
18466         }
18467
18468         rte_eth_dev_info_get(port_id, &dev_info);
18469         nb_tx_queues = dev_info.nb_tx_queues;
18470         if (!strcmp(res->on_off, "on")) {
18471                 port->dev_conf.txmode.offloads |= single_offload;
18472                 for (q = 0; q < nb_tx_queues; q++)
18473                         port->tx_conf[q].offloads |= single_offload;
18474         } else {
18475                 port->dev_conf.txmode.offloads &= ~single_offload;
18476                 for (q = 0; q < nb_tx_queues; q++)
18477                         port->tx_conf[q].offloads &= ~single_offload;
18478         }
18479
18480         cmd_reconfig_device_queue(port_id, 1, 1);
18481 }
18482
18483 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18484         .f = cmd_config_per_port_tx_offload_parsed,
18485         .data = NULL,
18486         .help_str = "port config <port_id> tx_offload "
18487                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18488                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18489                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18490                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18491                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18492                     "match_metadata on|off",
18493         .tokens = {
18494                 (void *)&cmd_config_per_port_tx_offload_result_port,
18495                 (void *)&cmd_config_per_port_tx_offload_result_config,
18496                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18497                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18498                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18499                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18500                 NULL,
18501         }
18502 };
18503
18504 /* Enable/Disable a per queue offloading */
18505 struct cmd_config_per_queue_tx_offload_result {
18506         cmdline_fixed_string_t port;
18507         portid_t port_id;
18508         cmdline_fixed_string_t txq;
18509         uint16_t queue_id;
18510         cmdline_fixed_string_t tx_offload;
18511         cmdline_fixed_string_t offload;
18512         cmdline_fixed_string_t on_off;
18513 };
18514
18515 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18516         TOKEN_STRING_INITIALIZER
18517                 (struct cmd_config_per_queue_tx_offload_result,
18518                  port, "port");
18519 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18520         TOKEN_NUM_INITIALIZER
18521                 (struct cmd_config_per_queue_tx_offload_result,
18522                  port_id, UINT16);
18523 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18524         TOKEN_STRING_INITIALIZER
18525                 (struct cmd_config_per_queue_tx_offload_result,
18526                  txq, "txq");
18527 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18528         TOKEN_NUM_INITIALIZER
18529                 (struct cmd_config_per_queue_tx_offload_result,
18530                  queue_id, UINT16);
18531 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18532         TOKEN_STRING_INITIALIZER
18533                 (struct cmd_config_per_queue_tx_offload_result,
18534                  tx_offload, "tx_offload");
18535 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18536         TOKEN_STRING_INITIALIZER
18537                 (struct cmd_config_per_queue_tx_offload_result,
18538                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18539                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18540                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18541                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18542                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18543 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18544         TOKEN_STRING_INITIALIZER
18545                 (struct cmd_config_per_queue_tx_offload_result,
18546                  on_off, "on#off");
18547
18548 static void
18549 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18550                                 __attribute__((unused)) struct cmdline *cl,
18551                                 __attribute__((unused)) void *data)
18552 {
18553         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18554         struct rte_eth_dev_info dev_info;
18555         portid_t port_id = res->port_id;
18556         uint16_t queue_id = res->queue_id;
18557         struct rte_port *port = &ports[port_id];
18558         uint64_t single_offload;
18559
18560         if (port->port_status != RTE_PORT_STOPPED) {
18561                 printf("Error: Can't config offload when Port %d "
18562                        "is not stopped\n", port_id);
18563                 return;
18564         }
18565
18566         rte_eth_dev_info_get(port_id, &dev_info);
18567         if (queue_id >= dev_info.nb_tx_queues) {
18568                 printf("Error: input queue_id should be 0 ... "
18569                        "%d\n", dev_info.nb_tx_queues - 1);
18570                 return;
18571         }
18572
18573         single_offload = search_tx_offload(res->offload);
18574         if (single_offload == 0) {
18575                 printf("Unknown offload name: %s\n", res->offload);
18576                 return;
18577         }
18578
18579         if (!strcmp(res->on_off, "on"))
18580                 port->tx_conf[queue_id].offloads |= single_offload;
18581         else
18582                 port->tx_conf[queue_id].offloads &= ~single_offload;
18583
18584         cmd_reconfig_device_queue(port_id, 1, 1);
18585 }
18586
18587 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18588         .f = cmd_config_per_queue_tx_offload_parsed,
18589         .data = NULL,
18590         .help_str = "port <port_id> txq <queue_id> tx_offload "
18591                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18592                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18593                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18594                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18595                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18596                     "on|off",
18597         .tokens = {
18598                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18599                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18600                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18601                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18602                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18603                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18604                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18605                 NULL,
18606         }
18607 };
18608
18609 /* *** configure tx_metadata for specific port *** */
18610 struct cmd_config_tx_metadata_specific_result {
18611         cmdline_fixed_string_t port;
18612         cmdline_fixed_string_t keyword;
18613         uint16_t port_id;
18614         cmdline_fixed_string_t item;
18615         uint32_t value;
18616 };
18617
18618 static void
18619 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18620                                 __attribute__((unused)) struct cmdline *cl,
18621                                 __attribute__((unused)) void *data)
18622 {
18623         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18624
18625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18626                 return;
18627         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18628         /* Add/remove callback to insert valid metadata in every Tx packet. */
18629         if (ports[res->port_id].tx_metadata)
18630                 add_tx_md_callback(res->port_id);
18631         else
18632                 remove_tx_md_callback(res->port_id);
18633 }
18634
18635 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18636         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18637                         port, "port");
18638 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18639         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18640                         keyword, "config");
18641 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18642         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18643                         port_id, UINT16);
18644 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18645         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18646                         item, "tx_metadata");
18647 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18648         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18649                         value, UINT32);
18650
18651 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18652         .f = cmd_config_tx_metadata_specific_parsed,
18653         .data = NULL,
18654         .help_str = "port config <port_id> tx_metadata <value>",
18655         .tokens = {
18656                 (void *)&cmd_config_tx_metadata_specific_port,
18657                 (void *)&cmd_config_tx_metadata_specific_keyword,
18658                 (void *)&cmd_config_tx_metadata_specific_id,
18659                 (void *)&cmd_config_tx_metadata_specific_item,
18660                 (void *)&cmd_config_tx_metadata_specific_value,
18661                 NULL,
18662         },
18663 };
18664
18665 /* *** display tx_metadata per port configuration *** */
18666 struct cmd_show_tx_metadata_result {
18667         cmdline_fixed_string_t cmd_show;
18668         cmdline_fixed_string_t cmd_port;
18669         cmdline_fixed_string_t cmd_keyword;
18670         portid_t cmd_pid;
18671 };
18672
18673 static void
18674 cmd_show_tx_metadata_parsed(void *parsed_result,
18675                 __attribute__((unused)) struct cmdline *cl,
18676                 __attribute__((unused)) void *data)
18677 {
18678         struct cmd_show_tx_metadata_result *res = parsed_result;
18679
18680         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18681                 printf("invalid port id %u\n", res->cmd_pid);
18682                 return;
18683         }
18684         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18685                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18686                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18687         }
18688 }
18689
18690 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18691         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18692                         cmd_show, "show");
18693 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18694         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18695                         cmd_port, "port");
18696 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18697         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18698                         cmd_pid, UINT16);
18699 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18700         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18701                         cmd_keyword, "tx_metadata");
18702
18703 cmdline_parse_inst_t cmd_show_tx_metadata = {
18704         .f = cmd_show_tx_metadata_parsed,
18705         .data = NULL,
18706         .help_str = "show port <port_id> tx_metadata",
18707         .tokens = {
18708                 (void *)&cmd_show_tx_metadata_show,
18709                 (void *)&cmd_show_tx_metadata_port,
18710                 (void *)&cmd_show_tx_metadata_pid,
18711                 (void *)&cmd_show_tx_metadata_keyword,
18712                 NULL,
18713         },
18714 };
18715
18716 /* ******************************************************************************** */
18717
18718 /* list of instructions */
18719 cmdline_parse_ctx_t main_ctx[] = {
18720         (cmdline_parse_inst_t *)&cmd_help_brief,
18721         (cmdline_parse_inst_t *)&cmd_help_long,
18722         (cmdline_parse_inst_t *)&cmd_quit,
18723         (cmdline_parse_inst_t *)&cmd_load_from_file,
18724         (cmdline_parse_inst_t *)&cmd_showport,
18725         (cmdline_parse_inst_t *)&cmd_showqueue,
18726         (cmdline_parse_inst_t *)&cmd_showportall,
18727         (cmdline_parse_inst_t *)&cmd_showcfg,
18728         (cmdline_parse_inst_t *)&cmd_showfwdall,
18729         (cmdline_parse_inst_t *)&cmd_start,
18730         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18731         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18732         (cmdline_parse_inst_t *)&cmd_set_link_up,
18733         (cmdline_parse_inst_t *)&cmd_set_link_down,
18734         (cmdline_parse_inst_t *)&cmd_reset,
18735         (cmdline_parse_inst_t *)&cmd_set_numbers,
18736         (cmdline_parse_inst_t *)&cmd_set_log,
18737         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18738         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18739         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18740         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18741         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18742         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18743         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18744         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18745         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18746         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18747         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18748         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18749         (cmdline_parse_inst_t *)&cmd_set_link_check,
18750         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18751         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18752         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18753         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18754 #ifdef RTE_LIBRTE_PMD_BOND
18755         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18756         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18757         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18758         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18759         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18760         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18761         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18762         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18763         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18764         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18765         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18766 #endif
18767         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18768         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18769         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18770         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18771         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18772         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18773         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18774         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18775         (cmdline_parse_inst_t *)&cmd_csum_set,
18776         (cmdline_parse_inst_t *)&cmd_csum_show,
18777         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18778         (cmdline_parse_inst_t *)&cmd_tso_set,
18779         (cmdline_parse_inst_t *)&cmd_tso_show,
18780         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18781         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18782         (cmdline_parse_inst_t *)&cmd_gro_enable,
18783         (cmdline_parse_inst_t *)&cmd_gro_flush,
18784         (cmdline_parse_inst_t *)&cmd_gro_show,
18785         (cmdline_parse_inst_t *)&cmd_gso_enable,
18786         (cmdline_parse_inst_t *)&cmd_gso_size,
18787         (cmdline_parse_inst_t *)&cmd_gso_show,
18788         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18789         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18790         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18791         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18792         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18793         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18794         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18795         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18796         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18797         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18798         (cmdline_parse_inst_t *)&cmd_config_dcb,
18799         (cmdline_parse_inst_t *)&cmd_read_reg,
18800         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18801         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18802         (cmdline_parse_inst_t *)&cmd_write_reg,
18803         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18804         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18805         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18806         (cmdline_parse_inst_t *)&cmd_stop,
18807         (cmdline_parse_inst_t *)&cmd_mac_addr,
18808         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18809         (cmdline_parse_inst_t *)&cmd_set_qmap,
18810         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18811         (cmdline_parse_inst_t *)&cmd_operate_port,
18812         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18813         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18814         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18815         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18816         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18817         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18818         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18819         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18820         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18821         (cmdline_parse_inst_t *)&cmd_config_mtu,
18822         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18823         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18824         (cmdline_parse_inst_t *)&cmd_config_rss,
18825         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18826         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18827         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18828         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18829         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18830         (cmdline_parse_inst_t *)&cmd_showport_reta,
18831         (cmdline_parse_inst_t *)&cmd_config_burst,
18832         (cmdline_parse_inst_t *)&cmd_config_thresh,
18833         (cmdline_parse_inst_t *)&cmd_config_threshold,
18834         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18835         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18836         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18837         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18838         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18839         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18840         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18841         (cmdline_parse_inst_t *)&cmd_global_config,
18842         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18843         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18844         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18845         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18846         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18847         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18848         (cmdline_parse_inst_t *)&cmd_dump,
18849         (cmdline_parse_inst_t *)&cmd_dump_one,
18850         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18851         (cmdline_parse_inst_t *)&cmd_syn_filter,
18852         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18853         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18854         (cmdline_parse_inst_t *)&cmd_flex_filter,
18855         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18856         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18857         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18858         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18859         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18860         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18861         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18862         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18863         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18864         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18865         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18866         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18867         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18868         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18869         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18870         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18871         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18872         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18873         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18874         (cmdline_parse_inst_t *)&cmd_flow,
18875         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18876         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18877         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18878         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18879         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18880         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18881         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18882         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18883         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18884         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18885         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18886         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18887         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18888         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18889         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18890         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18891         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18892         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18893         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18894         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18895         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18896         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18897         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18898         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18899         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18900         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18901         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18902         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18903         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18904         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18905         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18906         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18907         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18908         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18909         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18910         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18911         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18912         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18913         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18914         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18915         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18916         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18917         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18918         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18919         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18920         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18921         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18922         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18923         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18924 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18925         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18926 #endif
18927         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18928         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18929         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18930         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18931         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18932         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18933         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18934         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18935         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18936         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18937         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18938         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18939         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18940         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18941         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18942         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18943         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18944         (cmdline_parse_inst_t *)&cmd_ddp_add,
18945         (cmdline_parse_inst_t *)&cmd_ddp_del,
18946         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18947         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18948         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18949         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18950         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18951         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18952         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18953         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18954         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18955         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18956
18957         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18958         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18959         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18960         (cmdline_parse_inst_t *)&cmd_queue_region,
18961         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18962         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18963         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18964         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18965         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18966         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18967         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18968         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18969         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18970         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18971         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18972         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18973         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18974         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18975         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18976         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18977         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18978         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18979         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18980         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18981         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18982         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18983         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18984         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18985         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18986         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18987         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18988         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18989         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18990         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18991         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18992         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18993         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18994         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18995         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18996 #ifdef RTE_LIBRTE_BPF
18997         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18998         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18999 #endif
19000         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19001         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19002         NULL,
19003 };
19004
19005 /* read cmdline commands from file */
19006 void
19007 cmdline_read_from_file(const char *filename)
19008 {
19009         struct cmdline *cl;
19010
19011         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19012         if (cl == NULL) {
19013                 printf("Failed to create file based cmdline context: %s\n",
19014                        filename);
19015                 return;
19016         }
19017
19018         cmdline_interact(cl);
19019         cmdline_quit(cl);
19020
19021         cmdline_free(cl);
19022
19023         printf("Read CLI commands from %s\n", filename);
19024 }
19025
19026 /* prompt function, called from main on MASTER lcore */
19027 void
19028 prompt(void)
19029 {
19030         /* initialize non-constant commands */
19031         cmd_set_fwd_mode_init();
19032         cmd_set_fwd_retry_mode_init();
19033
19034         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19035         if (testpmd_cl == NULL)
19036                 return;
19037         cmdline_interact(testpmd_cl);
19038         cmdline_stdin_exit(testpmd_cl);
19039 }
19040
19041 void
19042 prompt_exit(void)
19043 {
19044         if (testpmd_cl != NULL)
19045                 cmdline_quit(testpmd_cl);
19046 }
19047
19048 static void
19049 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19050 {
19051         if (id == (portid_t)RTE_PORT_ALL) {
19052                 portid_t pid;
19053
19054                 RTE_ETH_FOREACH_DEV(pid) {
19055                         /* check if need_reconfig has been set to 1 */
19056                         if (ports[pid].need_reconfig == 0)
19057                                 ports[pid].need_reconfig = dev;
19058                         /* check if need_reconfig_queues has been set to 1 */
19059                         if (ports[pid].need_reconfig_queues == 0)
19060                                 ports[pid].need_reconfig_queues = queue;
19061                 }
19062         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19063                 /* check if need_reconfig has been set to 1 */
19064                 if (ports[id].need_reconfig == 0)
19065                         ports[id].need_reconfig = dev;
19066                 /* check if need_reconfig_queues has been set to 1 */
19067                 if (ports[id].need_reconfig_queues == 0)
19068                         ports[id].need_reconfig_queues = queue;
19069         }
19070 }