01dd45f27ce5a747bc30cfbd57e65627e60b88ef
[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                         "vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
737                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
738                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
739                         "       Configure the VXLAN encapsulation for flows.\n\n"
740
741                         "vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
742                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
743                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
744                         " eth-dst (eth-dst)\n"
745                         "       Configure the VXLAN encapsulation for flows.\n\n"
746
747                         "vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
748                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
749                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
750                         " eth-dst (eth-dst)\n"
751                         "       Configure the VXLAN encapsulation for flows.\n\n"
752
753                         "nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
754                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
755                         " (eth-dst)\n"
756                         "       Configure the NVGRE encapsulation for flows.\n\n"
757
758                         "nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
759                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
760                         " eth-src (eth-src) eth-dst (eth-dst)\n"
761                         "       Configure the NVGRE encapsulation for flows.\n\n"
762
763                         , list_pkt_forwarding_modes()
764                 );
765         }
766
767         if (show_all || !strcmp(res->section, "ports")) {
768
769                 cmdline_printf(
770                         cl,
771                         "\n"
772                         "Port Operations:\n"
773                         "----------------\n\n"
774
775                         "port start (port_id|all)\n"
776                         "    Start all ports or port_id.\n\n"
777
778                         "port stop (port_id|all)\n"
779                         "    Stop all ports or port_id.\n\n"
780
781                         "port close (port_id|all)\n"
782                         "    Close all ports or port_id.\n\n"
783
784                         "port attach (ident)\n"
785                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
786
787                         "port detach (port_id)\n"
788                         "    Detach physical or virtual dev by port_id\n\n"
789
790                         "port config (port_id|all)"
791                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
792                         " duplex (half|full|auto)\n"
793                         "    Set speed and duplex for all ports or port_id\n\n"
794
795                         "port config (port_id|all) loopback (mode)\n"
796                         "    Set loopback mode for all ports or port_id\n\n"
797
798                         "port config all (rxq|txq|rxd|txd) (value)\n"
799                         "    Set number for rxq/txq/rxd/txd.\n\n"
800
801                         "port config all max-pkt-len (value)\n"
802                         "    Set the max packet length.\n\n"
803
804                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
805                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
806                         " (on|off)\n"
807                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
808                         " for ports.\n\n"
809
810                         "port config all rss (all|default|ip|tcp|udp|sctp|"
811                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
812                         "    Set the RSS mode.\n\n"
813
814                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
815                         "    Set the RSS redirection table.\n\n"
816
817                         "port config (port_id) dcb vt (on|off) (traffic_class)"
818                         " pfc (on|off)\n"
819                         "    Set the DCB mode.\n\n"
820
821                         "port config all burst (value)\n"
822                         "    Set the number of packets per burst.\n\n"
823
824                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
825                         " (value)\n"
826                         "    Set the ring prefetch/host/writeback threshold"
827                         " for tx/rx queue.\n\n"
828
829                         "port config all (txfreet|txrst|rxfreet) (value)\n"
830                         "    Set free threshold for rx/tx, or set"
831                         " tx rs bit threshold.\n\n"
832                         "port config mtu X value\n"
833                         "    Set the MTU of port X to a given value\n\n"
834
835                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
836                         "    Set a rx/tx queue's ring size configuration, the new"
837                         " value will take effect after command that (re-)start the port"
838                         " or command that setup the specific queue\n\n"
839
840                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
841                         "    Start/stop a rx/tx queue of port X. Only take effect"
842                         " when port X is started\n\n"
843
844                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
845                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
846                         " take effect when port X is stopped.\n\n"
847
848                         "port (port_id) (rxq|txq) (queue_id) setup\n"
849                         "    Setup a rx/tx queue of port X.\n\n"
850
851                         "port config (port_id|all) l2-tunnel E-tag ether-type"
852                         " (value)\n"
853                         "    Set the value of E-tag ether-type.\n\n"
854
855                         "port config (port_id|all) l2-tunnel E-tag"
856                         " (enable|disable)\n"
857                         "    Enable/disable the E-tag support.\n\n"
858
859                         "port config (port_id) pctype mapping reset\n"
860                         "    Reset flow type to pctype mapping on a port\n\n"
861
862                         "port config (port_id) pctype mapping update"
863                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
864                         "    Update a flow type to pctype mapping item on a port\n\n"
865
866                         "port config (port_id) pctype (pctype_id) hash_inset|"
867                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
868                         " (field_idx)\n"
869                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
870
871                         "port config (port_id) pctype (pctype_id) hash_inset|"
872                         "fdir_inset|fdir_flx_inset clear all"
873                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
874
875                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
876                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
877
878                         "port config <port_id> rx_offload vlan_strip|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
880                         "outer_ipv4_cksum|macsec_strip|header_split|"
881                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
882                         "scatter|timestamp|security|keep_crc on|off\n"
883                         "     Enable or disable a per port Rx offloading"
884                         " on all Rx queues of a port\n\n"
885
886                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
887                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
888                         "outer_ipv4_cksum|macsec_strip|header_split|"
889                         "vlan_filter|vlan_extend|jumbo_frame|crc_strip|"
890                         "scatter|timestamp|security|keep_crc on|off\n"
891                         "    Enable or disable a per queue Rx offloading"
892                         " only on a specific Rx queue\n\n"
893
894                         "port config (port_id) tx_offload vlan_insert|"
895                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
896                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
897                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
898                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
899                         "security|match_metadata on|off\n"
900                         "    Enable or disable a per port Tx offloading"
901                         " on all Tx queues of a port\n\n"
902
903                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
904                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
905                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
906                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
907                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
908                         " on|off\n"
909                         "    Enable or disable a per queue Tx offloading"
910                         " only on a specific Tx queue\n\n"
911
912                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
913                         "    Load an eBPF program as a callback"
914                         " for particular RX/TX queue\n\n"
915
916                         "bpf-unload rx|tx (port) (queue)\n"
917                         "    Unload previously loaded eBPF program"
918                         " for particular RX/TX queue\n\n"
919
920                         "port config (port_id) tx_metadata (value)\n"
921                         "    Set Tx metadata value per port. Testpmd will add this value"
922                         " to any Tx packet sent from this port\n\n"
923                 );
924         }
925
926         if (show_all || !strcmp(res->section, "registers")) {
927
928                 cmdline_printf(
929                         cl,
930                         "\n"
931                         "Registers:\n"
932                         "----------\n\n"
933
934                         "read reg (port_id) (address)\n"
935                         "    Display value of a port register.\n\n"
936
937                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
938                         "    Display a port register bit field.\n\n"
939
940                         "read regbit (port_id) (address) (bit_x)\n"
941                         "    Display a single port register bit.\n\n"
942
943                         "write reg (port_id) (address) (value)\n"
944                         "    Set value of a port register.\n\n"
945
946                         "write regfield (port_id) (address) (bit_x) (bit_y)"
947                         " (value)\n"
948                         "    Set bit field of a port register.\n\n"
949
950                         "write regbit (port_id) (address) (bit_x) (value)\n"
951                         "    Set single bit value of a port register.\n\n"
952                 );
953         }
954         if (show_all || !strcmp(res->section, "filters")) {
955
956                 cmdline_printf(
957                         cl,
958                         "\n"
959                         "filters:\n"
960                         "--------\n\n"
961
962                         "ethertype_filter (port_id) (add|del)"
963                         " (mac_addr|mac_ignr) (mac_address) ethertype"
964                         " (ether_type) (drop|fwd) queue (queue_id)\n"
965                         "    Add/Del an ethertype filter.\n\n"
966
967                         "2tuple_filter (port_id) (add|del)"
968                         " dst_port (dst_port_value) protocol (protocol_value)"
969                         " mask (mask_value) tcp_flags (tcp_flags_value)"
970                         " priority (prio_value) queue (queue_id)\n"
971                         "    Add/Del a 2tuple filter.\n\n"
972
973                         "5tuple_filter (port_id) (add|del)"
974                         " dst_ip (dst_address) src_ip (src_address)"
975                         " dst_port (dst_port_value) src_port (src_port_value)"
976                         " protocol (protocol_value)"
977                         " mask (mask_value) tcp_flags (tcp_flags_value)"
978                         " priority (prio_value) queue (queue_id)\n"
979                         "    Add/Del a 5tuple filter.\n\n"
980
981                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
982                         "    Add/Del syn filter.\n\n"
983
984                         "flex_filter (port_id) (add|del) len (len_value)"
985                         " bytes (bytes_value) mask (mask_value)"
986                         " priority (prio_value) queue (queue_id)\n"
987                         "    Add/Del a flex filter.\n\n"
988
989                         "flow_director_filter (port_id) mode IP (add|del|update)"
990                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
991                         " src (src_ip_address) dst (dst_ip_address)"
992                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
993                         " vlan (vlan_value) flexbytes (flexbytes_value)"
994                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
995                         " fd_id (fd_id_value)\n"
996                         "    Add/Del an IP type flow director filter.\n\n"
997
998                         "flow_director_filter (port_id) mode IP (add|del|update)"
999                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1000                         " src (src_ip_address) (src_port)"
1001                         " dst (dst_ip_address) (dst_port)"
1002                         " tos (tos_value) ttl (ttl_value)"
1003                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1004                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1005                         " fd_id (fd_id_value)\n"
1006                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1007
1008                         "flow_director_filter (port_id) mode IP (add|del|update)"
1009                         " flow (ipv4-sctp|ipv6-sctp)"
1010                         " src (src_ip_address) (src_port)"
1011                         " dst (dst_ip_address) (dst_port)"
1012                         " tag (verification_tag) "
1013                         " tos (tos_value) ttl (ttl_value)"
1014                         " vlan (vlan_value)"
1015                         " flexbytes (flexbytes_value) (drop|fwd)"
1016                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1017                         "    Add/Del a SCTP type flow director filter.\n\n"
1018
1019                         "flow_director_filter (port_id) mode IP (add|del|update)"
1020                         " flow l2_payload ether (ethertype)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a l2 payload type flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1026                         " mac (mac_address) vlan (vlan_value)"
1027                         " flexbytes (flexbytes_value) (drop|fwd)"
1028                         " queue (queue_id) fd_id (fd_id_value)\n"
1029                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1030
1031                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1032                         " mac (mac_address) vlan (vlan_value)"
1033                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1034                         " flexbytes (flexbytes_value) (drop|fwd)"
1035                         " queue (queue_id) fd_id (fd_id_value)\n"
1036                         "    Add/Del a Tunnel flow director filter.\n\n"
1037
1038                         "flow_director_filter (port_id) mode raw (add|del|update)"
1039                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1040                         " fd_id (fd_id_value) packet (packet file name)\n"
1041                         "    Add/Del a raw type flow director filter.\n\n"
1042
1043                         "flush_flow_director (port_id)\n"
1044                         "    Flush all flow director entries of a device.\n\n"
1045
1046                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1047                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1048                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1049                         "    Set flow director IP mask.\n\n"
1050
1051                         "flow_director_mask (port_id) mode MAC-VLAN"
1052                         " vlan (vlan_value)\n"
1053                         "    Set flow director MAC-VLAN mask.\n\n"
1054
1055                         "flow_director_mask (port_id) mode Tunnel"
1056                         " vlan (vlan_value) mac (mac_value)"
1057                         " tunnel-type (tunnel_type_value)"
1058                         " tunnel-id (tunnel_id_value)\n"
1059                         "    Set flow director Tunnel mask.\n\n"
1060
1061                         "flow_director_flex_mask (port_id)"
1062                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1063                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1064                         " (mask)\n"
1065                         "    Configure mask of flex payload.\n\n"
1066
1067                         "flow_director_flex_payload (port_id)"
1068                         " (raw|l2|l3|l4) (config)\n"
1069                         "    Configure flex payload selection.\n\n"
1070
1071                         "get_sym_hash_ena_per_port (port_id)\n"
1072                         "    get symmetric hash enable configuration per port.\n\n"
1073
1074                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1075                         "    set symmetric hash enable configuration per port"
1076                         " to enable or disable.\n\n"
1077
1078                         "get_hash_global_config (port_id)\n"
1079                         "    Get the global configurations of hash filters.\n\n"
1080
1081                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1082                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1083                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1084                         " (enable|disable)\n"
1085                         "    Set the global configurations of hash filters.\n\n"
1086
1087                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1088                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1089                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1090                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1091                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1092                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1093                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1094                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1095                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1096                         "fld-8th|none) (select|add)\n"
1097                         "    Set the input set for hash.\n\n"
1098
1099                         "set_fdir_input_set (port_id) "
1100                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1101                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1102                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1103                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1104                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1105                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1106                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1107                         " (select|add)\n"
1108                         "    Set the input set for FDir.\n\n"
1109
1110                         "flow validate {port_id}"
1111                         " [group {group_id}] [priority {level}]"
1112                         " [ingress] [egress]"
1113                         " pattern {item} [/ {item} [...]] / end"
1114                         " actions {action} [/ {action} [...]] / end\n"
1115                         "    Check whether a flow rule can be created.\n\n"
1116
1117                         "flow create {port_id}"
1118                         " [group {group_id}] [priority {level}]"
1119                         " [ingress] [egress]"
1120                         " pattern {item} [/ {item} [...]] / end"
1121                         " actions {action} [/ {action} [...]] / end\n"
1122                         "    Create a flow rule.\n\n"
1123
1124                         "flow destroy {port_id} rule {rule_id} [...]\n"
1125                         "    Destroy specific flow rules.\n\n"
1126
1127                         "flow flush {port_id}\n"
1128                         "    Destroy all flow rules.\n\n"
1129
1130                         "flow query {port_id} {rule_id} {action}\n"
1131                         "    Query an existing flow rule.\n\n"
1132
1133                         "flow list {port_id} [group {group_id}] [...]\n"
1134                         "    List existing flow rules sorted by priority,"
1135                         " filtered by group identifiers.\n\n"
1136
1137                         "flow isolate {port_id} {boolean}\n"
1138                         "    Restrict ingress traffic to the defined"
1139                         " flow rules\n\n"
1140                 );
1141         }
1142
1143         if (show_all || !strcmp(res->section, "traffic_management")) {
1144                 cmdline_printf(
1145                         cl,
1146                         "\n"
1147                         "Traffic Management:\n"
1148                         "--------------\n"
1149                         "show port tm cap (port_id)\n"
1150                         "       Display the port TM capability.\n\n"
1151
1152                         "show port tm level cap (port_id) (level_id)\n"
1153                         "       Display the port TM hierarchical level capability.\n\n"
1154
1155                         "show port tm node cap (port_id) (node_id)\n"
1156                         "       Display the port TM node capability.\n\n"
1157
1158                         "show port tm node type (port_id) (node_id)\n"
1159                         "       Display the port TM node type.\n\n"
1160
1161                         "show port tm node stats (port_id) (node_id) (clear)\n"
1162                         "       Display the port TM node stats.\n\n"
1163
1164 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1165                         "set port tm hierarchy default (port_id)\n"
1166                         "       Set default traffic Management hierarchy on a port\n\n"
1167 #endif
1168
1169                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1170                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1171                         " (packet_length_adjust)\n"
1172                         "       Add port tm node private shaper profile.\n\n"
1173
1174                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1175                         "       Delete port tm node private shaper profile.\n\n"
1176
1177                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1178                         " (shaper_profile_id)\n"
1179                         "       Add/update port tm node shared shaper.\n\n"
1180
1181                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1182                         "       Delete port tm node shared shaper.\n\n"
1183
1184                         "set port tm node shaper profile (port_id) (node_id)"
1185                         " (shaper_profile_id)\n"
1186                         "       Set port tm node shaper profile.\n\n"
1187
1188                         "add port tm node wred profile (port_id) (wred_profile_id)"
1189                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1190                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1191                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1192                         "       Add port tm node wred profile.\n\n"
1193
1194                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1195                         "       Delete port tm node wred profile.\n\n"
1196
1197                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1198                         " (priority) (weight) (level_id) (shaper_profile_id)"
1199                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1200                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1201                         "       Add port tm nonleaf node.\n\n"
1202
1203                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1204                         " (priority) (weight) (level_id) (shaper_profile_id)"
1205                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1206                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1207                         "       Add port tm leaf node.\n\n"
1208
1209                         "del port tm node (port_id) (node_id)\n"
1210                         "       Delete port tm node.\n\n"
1211
1212                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight)\n"
1214                         "       Set port tm node parent.\n\n"
1215
1216                         "suspend port tm node (port_id) (node_id)"
1217                         "       Suspend tm node.\n\n"
1218
1219                         "resume port tm node (port_id) (node_id)"
1220                         "       Resume tm node.\n\n"
1221
1222                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1223                         "       Commit tm hierarchy.\n\n"
1224
1225                         "set port tm mark ip_ecn (port) (green) (yellow)"
1226                         " (red)\n"
1227                         "    Enables/Disables the traffic management marking"
1228                         " for IP ECN (Explicit Congestion Notification)"
1229                         " packets on a given port\n\n"
1230
1231                         "set port tm mark ip_dscp (port) (green) (yellow)"
1232                         " (red)\n"
1233                         "    Enables/Disables the traffic management marking"
1234                         " on the port for IP dscp packets\n\n"
1235
1236                         "set port tm mark vlan_dei (port) (green) (yellow)"
1237                         " (red)\n"
1238                         "    Enables/Disables the traffic management marking"
1239                         " on the port for VLAN packets with DEI enabled\n\n"
1240                 );
1241         }
1242
1243 }
1244
1245 cmdline_parse_token_string_t cmd_help_long_help =
1246         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1247
1248 cmdline_parse_token_string_t cmd_help_long_section =
1249         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1250                         "all#control#display#config#"
1251                         "ports#registers#filters#traffic_management");
1252
1253 cmdline_parse_inst_t cmd_help_long = {
1254         .f = cmd_help_long_parsed,
1255         .data = NULL,
1256         .help_str = "help all|control|display|config|ports|register|"
1257                 "filters|traffic_management: "
1258                 "Show help",
1259         .tokens = {
1260                 (void *)&cmd_help_long_help,
1261                 (void *)&cmd_help_long_section,
1262                 NULL,
1263         },
1264 };
1265
1266
1267 /* *** start/stop/close all ports *** */
1268 struct cmd_operate_port_result {
1269         cmdline_fixed_string_t keyword;
1270         cmdline_fixed_string_t name;
1271         cmdline_fixed_string_t value;
1272 };
1273
1274 static void cmd_operate_port_parsed(void *parsed_result,
1275                                 __attribute__((unused)) struct cmdline *cl,
1276                                 __attribute__((unused)) void *data)
1277 {
1278         struct cmd_operate_port_result *res = parsed_result;
1279
1280         if (!strcmp(res->name, "start"))
1281                 start_port(RTE_PORT_ALL);
1282         else if (!strcmp(res->name, "stop"))
1283                 stop_port(RTE_PORT_ALL);
1284         else if (!strcmp(res->name, "close"))
1285                 close_port(RTE_PORT_ALL);
1286         else if (!strcmp(res->name, "reset"))
1287                 reset_port(RTE_PORT_ALL);
1288         else
1289                 printf("Unknown parameter\n");
1290 }
1291
1292 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1293         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1294                                                                 "port");
1295 cmdline_parse_token_string_t cmd_operate_port_all_port =
1296         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1297                                                 "start#stop#close#reset");
1298 cmdline_parse_token_string_t cmd_operate_port_all_all =
1299         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1300
1301 cmdline_parse_inst_t cmd_operate_port = {
1302         .f = cmd_operate_port_parsed,
1303         .data = NULL,
1304         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1305         .tokens = {
1306                 (void *)&cmd_operate_port_all_cmd,
1307                 (void *)&cmd_operate_port_all_port,
1308                 (void *)&cmd_operate_port_all_all,
1309                 NULL,
1310         },
1311 };
1312
1313 /* *** start/stop/close specific port *** */
1314 struct cmd_operate_specific_port_result {
1315         cmdline_fixed_string_t keyword;
1316         cmdline_fixed_string_t name;
1317         uint8_t value;
1318 };
1319
1320 static void cmd_operate_specific_port_parsed(void *parsed_result,
1321                         __attribute__((unused)) struct cmdline *cl,
1322                                 __attribute__((unused)) void *data)
1323 {
1324         struct cmd_operate_specific_port_result *res = parsed_result;
1325
1326         if (!strcmp(res->name, "start"))
1327                 start_port(res->value);
1328         else if (!strcmp(res->name, "stop"))
1329                 stop_port(res->value);
1330         else if (!strcmp(res->name, "close"))
1331                 close_port(res->value);
1332         else if (!strcmp(res->name, "reset"))
1333                 reset_port(res->value);
1334         else
1335                 printf("Unknown parameter\n");
1336 }
1337
1338 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1339         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1340                                                         keyword, "port");
1341 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1342         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1343                                                 name, "start#stop#close#reset");
1344 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1345         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1346                                                         value, UINT8);
1347
1348 cmdline_parse_inst_t cmd_operate_specific_port = {
1349         .f = cmd_operate_specific_port_parsed,
1350         .data = NULL,
1351         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1352         .tokens = {
1353                 (void *)&cmd_operate_specific_port_cmd,
1354                 (void *)&cmd_operate_specific_port_port,
1355                 (void *)&cmd_operate_specific_port_id,
1356                 NULL,
1357         },
1358 };
1359
1360 /* *** enable port setup (after attach) via iterator or event *** */
1361 struct cmd_set_port_setup_on_result {
1362         cmdline_fixed_string_t set;
1363         cmdline_fixed_string_t port;
1364         cmdline_fixed_string_t setup;
1365         cmdline_fixed_string_t on;
1366         cmdline_fixed_string_t mode;
1367 };
1368
1369 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1370                                 __attribute__((unused)) struct cmdline *cl,
1371                                 __attribute__((unused)) void *data)
1372 {
1373         struct cmd_set_port_setup_on_result *res = parsed_result;
1374
1375         if (strcmp(res->mode, "event") == 0)
1376                 setup_on_probe_event = true;
1377         else if (strcmp(res->mode, "iterator") == 0)
1378                 setup_on_probe_event = false;
1379         else
1380                 printf("Unknown mode\n");
1381 }
1382
1383 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1384         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1385                         set, "set");
1386 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1387         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1388                         port, "port");
1389 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1390         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1391                         setup, "setup");
1392 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1393         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1394                         on, "on");
1395 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1396         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1397                         mode, "iterator#event");
1398
1399 cmdline_parse_inst_t cmd_set_port_setup_on = {
1400         .f = cmd_set_port_setup_on_parsed,
1401         .data = NULL,
1402         .help_str = "set port setup on iterator|event",
1403         .tokens = {
1404                 (void *)&cmd_set_port_setup_on_set,
1405                 (void *)&cmd_set_port_setup_on_port,
1406                 (void *)&cmd_set_port_setup_on_setup,
1407                 (void *)&cmd_set_port_setup_on_on,
1408                 (void *)&cmd_set_port_setup_on_mode,
1409                 NULL,
1410         },
1411 };
1412
1413 /* *** attach a specified port *** */
1414 struct cmd_operate_attach_port_result {
1415         cmdline_fixed_string_t port;
1416         cmdline_fixed_string_t keyword;
1417         cmdline_fixed_string_t identifier;
1418 };
1419
1420 static void cmd_operate_attach_port_parsed(void *parsed_result,
1421                                 __attribute__((unused)) struct cmdline *cl,
1422                                 __attribute__((unused)) void *data)
1423 {
1424         struct cmd_operate_attach_port_result *res = parsed_result;
1425
1426         if (!strcmp(res->keyword, "attach"))
1427                 attach_port(res->identifier);
1428         else
1429                 printf("Unknown parameter\n");
1430 }
1431
1432 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1433         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1434                         port, "port");
1435 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1436         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1437                         keyword, "attach");
1438 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1439         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1440                         identifier, NULL);
1441
1442 cmdline_parse_inst_t cmd_operate_attach_port = {
1443         .f = cmd_operate_attach_port_parsed,
1444         .data = NULL,
1445         .help_str = "port attach <identifier>: "
1446                 "(identifier: pci address or virtual dev name)",
1447         .tokens = {
1448                 (void *)&cmd_operate_attach_port_port,
1449                 (void *)&cmd_operate_attach_port_keyword,
1450                 (void *)&cmd_operate_attach_port_identifier,
1451                 NULL,
1452         },
1453 };
1454
1455 /* *** detach a specified port *** */
1456 struct cmd_operate_detach_port_result {
1457         cmdline_fixed_string_t port;
1458         cmdline_fixed_string_t keyword;
1459         portid_t port_id;
1460 };
1461
1462 static void cmd_operate_detach_port_parsed(void *parsed_result,
1463                                 __attribute__((unused)) struct cmdline *cl,
1464                                 __attribute__((unused)) void *data)
1465 {
1466         struct cmd_operate_detach_port_result *res = parsed_result;
1467
1468         if (!strcmp(res->keyword, "detach"))
1469                 detach_port_device(res->port_id);
1470         else
1471                 printf("Unknown parameter\n");
1472 }
1473
1474 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1475         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1476                         port, "port");
1477 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1478         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1479                         keyword, "detach");
1480 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1481         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1482                         port_id, UINT16);
1483
1484 cmdline_parse_inst_t cmd_operate_detach_port = {
1485         .f = cmd_operate_detach_port_parsed,
1486         .data = NULL,
1487         .help_str = "port detach <port_id>",
1488         .tokens = {
1489                 (void *)&cmd_operate_detach_port_port,
1490                 (void *)&cmd_operate_detach_port_keyword,
1491                 (void *)&cmd_operate_detach_port_port_id,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure speed for all ports *** */
1497 struct cmd_config_speed_all {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t item1;
1502         cmdline_fixed_string_t item2;
1503         cmdline_fixed_string_t value1;
1504         cmdline_fixed_string_t value2;
1505 };
1506
1507 static int
1508 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1509 {
1510
1511         int duplex;
1512
1513         if (!strcmp(duplexstr, "half")) {
1514                 duplex = ETH_LINK_HALF_DUPLEX;
1515         } else if (!strcmp(duplexstr, "full")) {
1516                 duplex = ETH_LINK_FULL_DUPLEX;
1517         } else if (!strcmp(duplexstr, "auto")) {
1518                 duplex = ETH_LINK_FULL_DUPLEX;
1519         } else {
1520                 printf("Unknown duplex parameter\n");
1521                 return -1;
1522         }
1523
1524         if (!strcmp(speedstr, "10")) {
1525                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1526                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1527         } else if (!strcmp(speedstr, "100")) {
1528                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1529                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1530         } else {
1531                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1532                         printf("Invalid speed/duplex parameters\n");
1533                         return -1;
1534                 }
1535                 if (!strcmp(speedstr, "1000")) {
1536                         *speed = ETH_LINK_SPEED_1G;
1537                 } else if (!strcmp(speedstr, "10000")) {
1538                         *speed = ETH_LINK_SPEED_10G;
1539                 } else if (!strcmp(speedstr, "25000")) {
1540                         *speed = ETH_LINK_SPEED_25G;
1541                 } else if (!strcmp(speedstr, "40000")) {
1542                         *speed = ETH_LINK_SPEED_40G;
1543                 } else if (!strcmp(speedstr, "50000")) {
1544                         *speed = ETH_LINK_SPEED_50G;
1545                 } else if (!strcmp(speedstr, "100000")) {
1546                         *speed = ETH_LINK_SPEED_100G;
1547                 } else if (!strcmp(speedstr, "auto")) {
1548                         *speed = ETH_LINK_SPEED_AUTONEG;
1549                 } else {
1550                         printf("Unknown speed parameter\n");
1551                         return -1;
1552                 }
1553         }
1554
1555         return 0;
1556 }
1557
1558 static void
1559 cmd_config_speed_all_parsed(void *parsed_result,
1560                         __attribute__((unused)) struct cmdline *cl,
1561                         __attribute__((unused)) void *data)
1562 {
1563         struct cmd_config_speed_all *res = parsed_result;
1564         uint32_t link_speed;
1565         portid_t pid;
1566
1567         if (!all_ports_stopped()) {
1568                 printf("Please stop all ports first\n");
1569                 return;
1570         }
1571
1572         if (parse_and_check_speed_duplex(res->value1, res->value2,
1573                         &link_speed) < 0)
1574                 return;
1575
1576         RTE_ETH_FOREACH_DEV(pid) {
1577                 ports[pid].dev_conf.link_speeds = link_speed;
1578         }
1579
1580         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1581 }
1582
1583 cmdline_parse_token_string_t cmd_config_speed_all_port =
1584         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1585 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1586         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1587                                                         "config");
1588 cmdline_parse_token_string_t cmd_config_speed_all_all =
1589         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1590 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1592 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1594                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1595 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1596         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1597 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1599                                                 "half#full#auto");
1600
1601 cmdline_parse_inst_t cmd_config_speed_all = {
1602         .f = cmd_config_speed_all_parsed,
1603         .data = NULL,
1604         .help_str = "port config all speed "
1605                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1606                                                         "half|full|auto",
1607         .tokens = {
1608                 (void *)&cmd_config_speed_all_port,
1609                 (void *)&cmd_config_speed_all_keyword,
1610                 (void *)&cmd_config_speed_all_all,
1611                 (void *)&cmd_config_speed_all_item1,
1612                 (void *)&cmd_config_speed_all_value1,
1613                 (void *)&cmd_config_speed_all_item2,
1614                 (void *)&cmd_config_speed_all_value2,
1615                 NULL,
1616         },
1617 };
1618
1619 /* *** configure speed for specific port *** */
1620 struct cmd_config_speed_specific {
1621         cmdline_fixed_string_t port;
1622         cmdline_fixed_string_t keyword;
1623         portid_t id;
1624         cmdline_fixed_string_t item1;
1625         cmdline_fixed_string_t item2;
1626         cmdline_fixed_string_t value1;
1627         cmdline_fixed_string_t value2;
1628 };
1629
1630 static void
1631 cmd_config_speed_specific_parsed(void *parsed_result,
1632                                 __attribute__((unused)) struct cmdline *cl,
1633                                 __attribute__((unused)) void *data)
1634 {
1635         struct cmd_config_speed_specific *res = parsed_result;
1636         uint32_t link_speed;
1637
1638         if (!all_ports_stopped()) {
1639                 printf("Please stop all ports first\n");
1640                 return;
1641         }
1642
1643         if (port_id_is_invalid(res->id, ENABLED_WARN))
1644                 return;
1645
1646         if (parse_and_check_speed_duplex(res->value1, res->value2,
1647                         &link_speed) < 0)
1648                 return;
1649
1650         ports[res->id].dev_conf.link_speeds = link_speed;
1651
1652         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1653 }
1654
1655
1656 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1657         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1658                                                                 "port");
1659 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1661                                                                 "config");
1662 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1663         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1664 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1666                                                                 "speed");
1667 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1669                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1670 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1672                                                                 "duplex");
1673 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1675                                                         "half#full#auto");
1676
1677 cmdline_parse_inst_t cmd_config_speed_specific = {
1678         .f = cmd_config_speed_specific_parsed,
1679         .data = NULL,
1680         .help_str = "port config <port_id> speed "
1681                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1682                                                         "half|full|auto",
1683         .tokens = {
1684                 (void *)&cmd_config_speed_specific_port,
1685                 (void *)&cmd_config_speed_specific_keyword,
1686                 (void *)&cmd_config_speed_specific_id,
1687                 (void *)&cmd_config_speed_specific_item1,
1688                 (void *)&cmd_config_speed_specific_value1,
1689                 (void *)&cmd_config_speed_specific_item2,
1690                 (void *)&cmd_config_speed_specific_value2,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure loopback for all ports *** */
1696 struct cmd_config_loopback_all {
1697         cmdline_fixed_string_t port;
1698         cmdline_fixed_string_t keyword;
1699         cmdline_fixed_string_t all;
1700         cmdline_fixed_string_t item;
1701         uint32_t mode;
1702 };
1703
1704 static void
1705 cmd_config_loopback_all_parsed(void *parsed_result,
1706                         __attribute__((unused)) struct cmdline *cl,
1707                         __attribute__((unused)) void *data)
1708 {
1709         struct cmd_config_loopback_all *res = parsed_result;
1710         portid_t pid;
1711
1712         if (!all_ports_stopped()) {
1713                 printf("Please stop all ports first\n");
1714                 return;
1715         }
1716
1717         RTE_ETH_FOREACH_DEV(pid) {
1718                 ports[pid].dev_conf.lpbk_mode = res->mode;
1719         }
1720
1721         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1722 }
1723
1724 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1726 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1727         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1728                                                         "config");
1729 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1730         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1731 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1733                                                         "loopback");
1734 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1735         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1736
1737 cmdline_parse_inst_t cmd_config_loopback_all = {
1738         .f = cmd_config_loopback_all_parsed,
1739         .data = NULL,
1740         .help_str = "port config all loopback <mode>",
1741         .tokens = {
1742                 (void *)&cmd_config_loopback_all_port,
1743                 (void *)&cmd_config_loopback_all_keyword,
1744                 (void *)&cmd_config_loopback_all_all,
1745                 (void *)&cmd_config_loopback_all_item,
1746                 (void *)&cmd_config_loopback_all_mode,
1747                 NULL,
1748         },
1749 };
1750
1751 /* *** configure loopback for specific port *** */
1752 struct cmd_config_loopback_specific {
1753         cmdline_fixed_string_t port;
1754         cmdline_fixed_string_t keyword;
1755         uint16_t port_id;
1756         cmdline_fixed_string_t item;
1757         uint32_t mode;
1758 };
1759
1760 static void
1761 cmd_config_loopback_specific_parsed(void *parsed_result,
1762                                 __attribute__((unused)) struct cmdline *cl,
1763                                 __attribute__((unused)) void *data)
1764 {
1765         struct cmd_config_loopback_specific *res = parsed_result;
1766
1767         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1768                 return;
1769
1770         if (!port_is_stopped(res->port_id)) {
1771                 printf("Please stop port %u first\n", res->port_id);
1772                 return;
1773         }
1774
1775         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1776
1777         cmd_reconfig_device_queue(res->port_id, 1, 1);
1778 }
1779
1780
1781 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1783                                                                 "port");
1784 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1786                                                                 "config");
1787 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1788         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1789                                                                 UINT16);
1790 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1792                                                                 "loopback");
1793 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1794         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1795                               UINT32);
1796
1797 cmdline_parse_inst_t cmd_config_loopback_specific = {
1798         .f = cmd_config_loopback_specific_parsed,
1799         .data = NULL,
1800         .help_str = "port config <port_id> loopback <mode>",
1801         .tokens = {
1802                 (void *)&cmd_config_loopback_specific_port,
1803                 (void *)&cmd_config_loopback_specific_keyword,
1804                 (void *)&cmd_config_loopback_specific_id,
1805                 (void *)&cmd_config_loopback_specific_item,
1806                 (void *)&cmd_config_loopback_specific_mode,
1807                 NULL,
1808         },
1809 };
1810
1811 /* *** configure txq/rxq, txd/rxd *** */
1812 struct cmd_config_rx_tx {
1813         cmdline_fixed_string_t port;
1814         cmdline_fixed_string_t keyword;
1815         cmdline_fixed_string_t all;
1816         cmdline_fixed_string_t name;
1817         uint16_t value;
1818 };
1819
1820 static void
1821 cmd_config_rx_tx_parsed(void *parsed_result,
1822                         __attribute__((unused)) struct cmdline *cl,
1823                         __attribute__((unused)) void *data)
1824 {
1825         struct cmd_config_rx_tx *res = parsed_result;
1826
1827         if (!all_ports_stopped()) {
1828                 printf("Please stop all ports first\n");
1829                 return;
1830         }
1831         if (!strcmp(res->name, "rxq")) {
1832                 if (!res->value && !nb_txq) {
1833                         printf("Warning: Either rx or tx queues should be non zero\n");
1834                         return;
1835                 }
1836                 if (check_nb_rxq(res->value) != 0)
1837                         return;
1838                 nb_rxq = res->value;
1839         }
1840         else if (!strcmp(res->name, "txq")) {
1841                 if (!res->value && !nb_rxq) {
1842                         printf("Warning: Either rx or tx queues should be non zero\n");
1843                         return;
1844                 }
1845                 if (check_nb_txq(res->value) != 0)
1846                         return;
1847                 nb_txq = res->value;
1848         }
1849         else if (!strcmp(res->name, "rxd")) {
1850                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1851                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1852                                         res->value, RTE_TEST_RX_DESC_MAX);
1853                         return;
1854                 }
1855                 nb_rxd = res->value;
1856         } else if (!strcmp(res->name, "txd")) {
1857                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1858                         printf("txd %d invalid - must be > 0 && <= %d\n",
1859                                         res->value, RTE_TEST_TX_DESC_MAX);
1860                         return;
1861                 }
1862                 nb_txd = res->value;
1863         } else {
1864                 printf("Unknown parameter\n");
1865                 return;
1866         }
1867
1868         fwd_config_setup();
1869
1870         init_port_config();
1871
1872         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1873 }
1874
1875 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1876         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1877 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1879 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1881 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1882         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1883                                                 "rxq#txq#rxd#txd");
1884 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1885         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1886
1887 cmdline_parse_inst_t cmd_config_rx_tx = {
1888         .f = cmd_config_rx_tx_parsed,
1889         .data = NULL,
1890         .help_str = "port config all rxq|txq|rxd|txd <value>",
1891         .tokens = {
1892                 (void *)&cmd_config_rx_tx_port,
1893                 (void *)&cmd_config_rx_tx_keyword,
1894                 (void *)&cmd_config_rx_tx_all,
1895                 (void *)&cmd_config_rx_tx_name,
1896                 (void *)&cmd_config_rx_tx_value,
1897                 NULL,
1898         },
1899 };
1900
1901 /* *** config max packet length *** */
1902 struct cmd_config_max_pkt_len_result {
1903         cmdline_fixed_string_t port;
1904         cmdline_fixed_string_t keyword;
1905         cmdline_fixed_string_t all;
1906         cmdline_fixed_string_t name;
1907         uint32_t value;
1908 };
1909
1910 static void
1911 cmd_config_max_pkt_len_parsed(void *parsed_result,
1912                                 __attribute__((unused)) struct cmdline *cl,
1913                                 __attribute__((unused)) void *data)
1914 {
1915         struct cmd_config_max_pkt_len_result *res = parsed_result;
1916         portid_t pid;
1917
1918         if (!all_ports_stopped()) {
1919                 printf("Please stop all ports first\n");
1920                 return;
1921         }
1922
1923         RTE_ETH_FOREACH_DEV(pid) {
1924                 struct rte_port *port = &ports[pid];
1925                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1926
1927                 if (!strcmp(res->name, "max-pkt-len")) {
1928                         if (res->value < RTE_ETHER_MIN_LEN) {
1929                                 printf("max-pkt-len can not be less than %d\n",
1930                                                 RTE_ETHER_MIN_LEN);
1931                                 return;
1932                         }
1933                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1934                                 return;
1935
1936                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1937                         if (res->value > RTE_ETHER_MAX_LEN)
1938                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1939                         else
1940                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1941                         port->dev_conf.rxmode.offloads = rx_offloads;
1942                 } else {
1943                         printf("Unknown parameter\n");
1944                         return;
1945                 }
1946         }
1947
1948         init_port_config();
1949
1950         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1951 }
1952
1953 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1954         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1955                                                                 "port");
1956 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1958                                                                 "config");
1959 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1960         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1961                                                                 "all");
1962 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1964                                                                 "max-pkt-len");
1965 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1966         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1967                                                                 UINT32);
1968
1969 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1970         .f = cmd_config_max_pkt_len_parsed,
1971         .data = NULL,
1972         .help_str = "port config all max-pkt-len <value>",
1973         .tokens = {
1974                 (void *)&cmd_config_max_pkt_len_port,
1975                 (void *)&cmd_config_max_pkt_len_keyword,
1976                 (void *)&cmd_config_max_pkt_len_all,
1977                 (void *)&cmd_config_max_pkt_len_name,
1978                 (void *)&cmd_config_max_pkt_len_value,
1979                 NULL,
1980         },
1981 };
1982
1983 /* *** configure port MTU *** */
1984 struct cmd_config_mtu_result {
1985         cmdline_fixed_string_t port;
1986         cmdline_fixed_string_t keyword;
1987         cmdline_fixed_string_t mtu;
1988         portid_t port_id;
1989         uint16_t value;
1990 };
1991
1992 static void
1993 cmd_config_mtu_parsed(void *parsed_result,
1994                       __attribute__((unused)) struct cmdline *cl,
1995                       __attribute__((unused)) void *data)
1996 {
1997         struct cmd_config_mtu_result *res = parsed_result;
1998
1999         if (res->value < RTE_ETHER_MIN_LEN) {
2000                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2001                 return;
2002         }
2003         port_mtu_set(res->port_id, res->value);
2004 }
2005
2006 cmdline_parse_token_string_t cmd_config_mtu_port =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2008                                  "port");
2009 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2011                                  "config");
2012 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2013         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2014                                  "mtu");
2015 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2016         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2017 cmdline_parse_token_num_t cmd_config_mtu_value =
2018         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2019
2020 cmdline_parse_inst_t cmd_config_mtu = {
2021         .f = cmd_config_mtu_parsed,
2022         .data = NULL,
2023         .help_str = "port config mtu <port_id> <value>",
2024         .tokens = {
2025                 (void *)&cmd_config_mtu_port,
2026                 (void *)&cmd_config_mtu_keyword,
2027                 (void *)&cmd_config_mtu_mtu,
2028                 (void *)&cmd_config_mtu_port_id,
2029                 (void *)&cmd_config_mtu_value,
2030                 NULL,
2031         },
2032 };
2033
2034 /* *** configure rx mode *** */
2035 struct cmd_config_rx_mode_flag {
2036         cmdline_fixed_string_t port;
2037         cmdline_fixed_string_t keyword;
2038         cmdline_fixed_string_t all;
2039         cmdline_fixed_string_t name;
2040         cmdline_fixed_string_t value;
2041 };
2042
2043 static void
2044 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2045                                 __attribute__((unused)) struct cmdline *cl,
2046                                 __attribute__((unused)) void *data)
2047 {
2048         struct cmd_config_rx_mode_flag *res = parsed_result;
2049         portid_t pid;
2050         int k;
2051
2052         if (!all_ports_stopped()) {
2053                 printf("Please stop all ports first\n");
2054                 return;
2055         }
2056
2057         RTE_ETH_FOREACH_DEV(pid) {
2058                 struct rte_port *port;
2059                 uint64_t rx_offloads;
2060
2061                 port = &ports[pid];
2062                 rx_offloads = port->dev_conf.rxmode.offloads;
2063                 if (!strcmp(res->name, "crc-strip")) {
2064                         if (!strcmp(res->value, "on")) {
2065                                 rx_offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
2066                         } else if (!strcmp(res->value, "off")) {
2067                                 rx_offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
2068                         } else {
2069                                 printf("Unknown parameter\n");
2070                                 return;
2071                         }
2072                 } else if (!strcmp(res->name, "scatter")) {
2073                         if (!strcmp(res->value, "on")) {
2074                                 rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
2075                         } else if (!strcmp(res->value, "off")) {
2076                                 rx_offloads &= ~DEV_RX_OFFLOAD_SCATTER;
2077                         } else {
2078                                 printf("Unknown parameter\n");
2079                                 return;
2080                         }
2081                 } else if (!strcmp(res->name, "rx-cksum")) {
2082                         if (!strcmp(res->value, "on"))
2083                                 rx_offloads |= DEV_RX_OFFLOAD_CHECKSUM;
2084                         else if (!strcmp(res->value, "off"))
2085                                 rx_offloads &= ~DEV_RX_OFFLOAD_CHECKSUM;
2086                         else {
2087                                 printf("Unknown parameter\n");
2088                                 return;
2089                         }
2090                 } else if (!strcmp(res->name, "rx-timestamp")) {
2091                         if (!strcmp(res->value, "on"))
2092                                 rx_offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
2093                         else if (!strcmp(res->value, "off"))
2094                                 rx_offloads &= ~DEV_RX_OFFLOAD_TIMESTAMP;
2095                         else {
2096                                 printf("Unknown parameter\n");
2097                                 return;
2098                         }
2099                 } else if (!strcmp(res->name, "hw-vlan")) {
2100                         if (!strcmp(res->value, "on")) {
2101                                 rx_offloads |= (DEV_RX_OFFLOAD_VLAN_FILTER |
2102                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2103                         } else if (!strcmp(res->value, "off")) {
2104                                 rx_offloads &= ~(DEV_RX_OFFLOAD_VLAN_FILTER |
2105                                                 DEV_RX_OFFLOAD_VLAN_STRIP);
2106                         } else {
2107                                 printf("Unknown parameter\n");
2108                                 return;
2109                         }
2110                 } else if (!strcmp(res->name, "hw-vlan-filter")) {
2111                         if (!strcmp(res->value, "on"))
2112                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2113                         else if (!strcmp(res->value, "off"))
2114                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER;
2115                         else {
2116                                 printf("Unknown parameter\n");
2117                                 return;
2118                         }
2119                 } else if (!strcmp(res->name, "hw-vlan-strip")) {
2120                         if (!strcmp(res->value, "on"))
2121                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
2122                         else if (!strcmp(res->value, "off"))
2123                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
2124                         else {
2125                                 printf("Unknown parameter\n");
2126                                 return;
2127                         }
2128                 } else if (!strcmp(res->name, "hw-vlan-extend")) {
2129                         if (!strcmp(res->value, "on"))
2130                                 rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND;
2131                         else if (!strcmp(res->value, "off"))
2132                                 rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND;
2133                         else {
2134                                 printf("Unknown parameter\n");
2135                                 return;
2136                         }
2137                 } else if (!strcmp(res->name, "drop-en")) {
2138                         if (!strcmp(res->value, "on"))
2139                                 rx_drop_en = 1;
2140                         else if (!strcmp(res->value, "off"))
2141                                 rx_drop_en = 0;
2142                         else {
2143                                 printf("Unknown parameter\n");
2144                                 return;
2145                         }
2146                 } else {
2147                         printf("Unknown parameter\n");
2148                         return;
2149                 }
2150                 port->dev_conf.rxmode.offloads = rx_offloads;
2151                 /* Apply Rx offloads configuration */
2152                 for (k = 0; k < port->dev_info.max_rx_queues; k++)
2153                         port->rx_conf[k].offloads =
2154                                 port->dev_conf.rxmode.offloads;
2155         }
2156
2157         init_port_config();
2158
2159         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2160 }
2161
2162 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2163         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2164 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2165         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2166                                                                 "config");
2167 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2168         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2169 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2171                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
2172                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
2173 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2174         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2175                                                         "on#off");
2176
2177 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2178         .f = cmd_config_rx_mode_flag_parsed,
2179         .data = NULL,
2180         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
2181                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
2182         .tokens = {
2183                 (void *)&cmd_config_rx_mode_flag_port,
2184                 (void *)&cmd_config_rx_mode_flag_keyword,
2185                 (void *)&cmd_config_rx_mode_flag_all,
2186                 (void *)&cmd_config_rx_mode_flag_name,
2187                 (void *)&cmd_config_rx_mode_flag_value,
2188                 NULL,
2189         },
2190 };
2191
2192 /* *** configure rss *** */
2193 struct cmd_config_rss {
2194         cmdline_fixed_string_t port;
2195         cmdline_fixed_string_t keyword;
2196         cmdline_fixed_string_t all;
2197         cmdline_fixed_string_t name;
2198         cmdline_fixed_string_t value;
2199 };
2200
2201 static void
2202 cmd_config_rss_parsed(void *parsed_result,
2203                         __attribute__((unused)) struct cmdline *cl,
2204                         __attribute__((unused)) void *data)
2205 {
2206         struct cmd_config_rss *res = parsed_result;
2207         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2208         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2209         int use_default = 0;
2210         int all_updated = 1;
2211         int diag;
2212         uint16_t i;
2213
2214         if (!strcmp(res->value, "all"))
2215                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2216                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2217                                         ETH_RSS_L2_PAYLOAD;
2218         else if (!strcmp(res->value, "ip"))
2219                 rss_conf.rss_hf = ETH_RSS_IP;
2220         else if (!strcmp(res->value, "udp"))
2221                 rss_conf.rss_hf = ETH_RSS_UDP;
2222         else if (!strcmp(res->value, "tcp"))
2223                 rss_conf.rss_hf = ETH_RSS_TCP;
2224         else if (!strcmp(res->value, "sctp"))
2225                 rss_conf.rss_hf = ETH_RSS_SCTP;
2226         else if (!strcmp(res->value, "ether"))
2227                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2228         else if (!strcmp(res->value, "port"))
2229                 rss_conf.rss_hf = ETH_RSS_PORT;
2230         else if (!strcmp(res->value, "vxlan"))
2231                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2232         else if (!strcmp(res->value, "geneve"))
2233                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2234         else if (!strcmp(res->value, "nvgre"))
2235                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2236         else if (!strcmp(res->value, "none"))
2237                 rss_conf.rss_hf = 0;
2238         else if (!strcmp(res->value, "default"))
2239                 use_default = 1;
2240         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2241                                                 atoi(res->value) < 64)
2242                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2243         else {
2244                 printf("Unknown parameter\n");
2245                 return;
2246         }
2247         rss_conf.rss_key = NULL;
2248         /* Update global configuration for RSS types. */
2249         RTE_ETH_FOREACH_DEV(i) {
2250                 struct rte_eth_rss_conf local_rss_conf;
2251
2252                 rte_eth_dev_info_get(i, &dev_info);
2253                 if (use_default)
2254                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2255
2256                 local_rss_conf = rss_conf;
2257                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2258                         dev_info.flow_type_rss_offloads;
2259                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2260                         printf("Port %u modified RSS hash function based on hardware support,"
2261                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2262                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2263                 }
2264                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2265                 if (diag < 0) {
2266                         all_updated = 0;
2267                         printf("Configuration of RSS hash at ethernet port %d "
2268                                 "failed with error (%d): %s.\n",
2269                                 i, -diag, strerror(-diag));
2270                 }
2271         }
2272         if (all_updated && !use_default)
2273                 rss_hf = rss_conf.rss_hf;
2274 }
2275
2276 cmdline_parse_token_string_t cmd_config_rss_port =
2277         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2278 cmdline_parse_token_string_t cmd_config_rss_keyword =
2279         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2280 cmdline_parse_token_string_t cmd_config_rss_all =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2282 cmdline_parse_token_string_t cmd_config_rss_name =
2283         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2284 cmdline_parse_token_string_t cmd_config_rss_value =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2286
2287 cmdline_parse_inst_t cmd_config_rss = {
2288         .f = cmd_config_rss_parsed,
2289         .data = NULL,
2290         .help_str = "port config all rss "
2291                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2292         .tokens = {
2293                 (void *)&cmd_config_rss_port,
2294                 (void *)&cmd_config_rss_keyword,
2295                 (void *)&cmd_config_rss_all,
2296                 (void *)&cmd_config_rss_name,
2297                 (void *)&cmd_config_rss_value,
2298                 NULL,
2299         },
2300 };
2301
2302 /* *** configure rss hash key *** */
2303 struct cmd_config_rss_hash_key {
2304         cmdline_fixed_string_t port;
2305         cmdline_fixed_string_t config;
2306         portid_t port_id;
2307         cmdline_fixed_string_t rss_hash_key;
2308         cmdline_fixed_string_t rss_type;
2309         cmdline_fixed_string_t key;
2310 };
2311
2312 static uint8_t
2313 hexa_digit_to_value(char hexa_digit)
2314 {
2315         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2316                 return (uint8_t) (hexa_digit - '0');
2317         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2318                 return (uint8_t) ((hexa_digit - 'a') + 10);
2319         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2320                 return (uint8_t) ((hexa_digit - 'A') + 10);
2321         /* Invalid hexa digit */
2322         return 0xFF;
2323 }
2324
2325 static uint8_t
2326 parse_and_check_key_hexa_digit(char *key, int idx)
2327 {
2328         uint8_t hexa_v;
2329
2330         hexa_v = hexa_digit_to_value(key[idx]);
2331         if (hexa_v == 0xFF)
2332                 printf("invalid key: character %c at position %d is not a "
2333                        "valid hexa digit\n", key[idx], idx);
2334         return hexa_v;
2335 }
2336
2337 static void
2338 cmd_config_rss_hash_key_parsed(void *parsed_result,
2339                                __attribute__((unused)) struct cmdline *cl,
2340                                __attribute__((unused)) void *data)
2341 {
2342         struct cmd_config_rss_hash_key *res = parsed_result;
2343         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2344         uint8_t xdgt0;
2345         uint8_t xdgt1;
2346         int i;
2347         struct rte_eth_dev_info dev_info;
2348         uint8_t hash_key_size;
2349         uint32_t key_len;
2350
2351         memset(&dev_info, 0, sizeof(dev_info));
2352         rte_eth_dev_info_get(res->port_id, &dev_info);
2353         if (dev_info.hash_key_size > 0 &&
2354                         dev_info.hash_key_size <= sizeof(hash_key))
2355                 hash_key_size = dev_info.hash_key_size;
2356         else {
2357                 printf("dev_info did not provide a valid hash key size\n");
2358                 return;
2359         }
2360         /* Check the length of the RSS hash key */
2361         key_len = strlen(res->key);
2362         if (key_len != (hash_key_size * 2)) {
2363                 printf("key length: %d invalid - key must be a string of %d"
2364                            " hexa-decimal numbers\n",
2365                            (int) key_len, hash_key_size * 2);
2366                 return;
2367         }
2368         /* Translate RSS hash key into binary representation */
2369         for (i = 0; i < hash_key_size; i++) {
2370                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2371                 if (xdgt0 == 0xFF)
2372                         return;
2373                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2374                 if (xdgt1 == 0xFF)
2375                         return;
2376                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2377         }
2378         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2379                         hash_key_size);
2380 }
2381
2382 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2383         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2384 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2386                                  "config");
2387 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2388         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2389 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2391                                  rss_hash_key, "rss-hash-key");
2392 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2393         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2394                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2395                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2396                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2397                                  "ipv6-tcp-ex#ipv6-udp-ex");
2398 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2400
2401 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2402         .f = cmd_config_rss_hash_key_parsed,
2403         .data = NULL,
2404         .help_str = "port config <port_id> rss-hash-key "
2405                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2406                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2407                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2408                 "<string of hex digits (variable length, NIC dependent)>",
2409         .tokens = {
2410                 (void *)&cmd_config_rss_hash_key_port,
2411                 (void *)&cmd_config_rss_hash_key_config,
2412                 (void *)&cmd_config_rss_hash_key_port_id,
2413                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2414                 (void *)&cmd_config_rss_hash_key_rss_type,
2415                 (void *)&cmd_config_rss_hash_key_value,
2416                 NULL,
2417         },
2418 };
2419
2420 /* *** configure port rxq/txq ring size *** */
2421 struct cmd_config_rxtx_ring_size {
2422         cmdline_fixed_string_t port;
2423         cmdline_fixed_string_t config;
2424         portid_t portid;
2425         cmdline_fixed_string_t rxtxq;
2426         uint16_t qid;
2427         cmdline_fixed_string_t rsize;
2428         uint16_t size;
2429 };
2430
2431 static void
2432 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2433                                  __attribute__((unused)) struct cmdline *cl,
2434                                  __attribute__((unused)) void *data)
2435 {
2436         struct cmd_config_rxtx_ring_size *res = parsed_result;
2437         struct rte_port *port;
2438         uint8_t isrx;
2439
2440         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2441                 return;
2442
2443         if (res->portid == (portid_t)RTE_PORT_ALL) {
2444                 printf("Invalid port id\n");
2445                 return;
2446         }
2447
2448         port = &ports[res->portid];
2449
2450         if (!strcmp(res->rxtxq, "rxq"))
2451                 isrx = 1;
2452         else if (!strcmp(res->rxtxq, "txq"))
2453                 isrx = 0;
2454         else {
2455                 printf("Unknown parameter\n");
2456                 return;
2457         }
2458
2459         if (isrx && rx_queue_id_is_invalid(res->qid))
2460                 return;
2461         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2462                 return;
2463
2464         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2465                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2466                        rx_free_thresh);
2467                 return;
2468         }
2469
2470         if (isrx)
2471                 port->nb_rx_desc[res->qid] = res->size;
2472         else
2473                 port->nb_tx_desc[res->qid] = res->size;
2474
2475         cmd_reconfig_device_queue(res->portid, 0, 1);
2476 }
2477
2478 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2479         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2480                                  port, "port");
2481 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2482         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2483                                  config, "config");
2484 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2485         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2486                                  portid, UINT16);
2487 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2488         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2489                                  rxtxq, "rxq#txq");
2490 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2491         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2492                               qid, UINT16);
2493 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2494         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2495                                  rsize, "ring_size");
2496 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2497         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2498                               size, UINT16);
2499
2500 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2501         .f = cmd_config_rxtx_ring_size_parsed,
2502         .data = NULL,
2503         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2504         .tokens = {
2505                 (void *)&cmd_config_rxtx_ring_size_port,
2506                 (void *)&cmd_config_rxtx_ring_size_config,
2507                 (void *)&cmd_config_rxtx_ring_size_portid,
2508                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2509                 (void *)&cmd_config_rxtx_ring_size_qid,
2510                 (void *)&cmd_config_rxtx_ring_size_rsize,
2511                 (void *)&cmd_config_rxtx_ring_size_size,
2512                 NULL,
2513         },
2514 };
2515
2516 /* *** configure port rxq/txq start/stop *** */
2517 struct cmd_config_rxtx_queue {
2518         cmdline_fixed_string_t port;
2519         portid_t portid;
2520         cmdline_fixed_string_t rxtxq;
2521         uint16_t qid;
2522         cmdline_fixed_string_t opname;
2523 };
2524
2525 static void
2526 cmd_config_rxtx_queue_parsed(void *parsed_result,
2527                         __attribute__((unused)) struct cmdline *cl,
2528                         __attribute__((unused)) void *data)
2529 {
2530         struct cmd_config_rxtx_queue *res = parsed_result;
2531         uint8_t isrx;
2532         uint8_t isstart;
2533         int ret = 0;
2534
2535         if (test_done == 0) {
2536                 printf("Please stop forwarding first\n");
2537                 return;
2538         }
2539
2540         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2541                 return;
2542
2543         if (port_is_started(res->portid) != 1) {
2544                 printf("Please start port %u first\n", res->portid);
2545                 return;
2546         }
2547
2548         if (!strcmp(res->rxtxq, "rxq"))
2549                 isrx = 1;
2550         else if (!strcmp(res->rxtxq, "txq"))
2551                 isrx = 0;
2552         else {
2553                 printf("Unknown parameter\n");
2554                 return;
2555         }
2556
2557         if (isrx && rx_queue_id_is_invalid(res->qid))
2558                 return;
2559         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2560                 return;
2561
2562         if (!strcmp(res->opname, "start"))
2563                 isstart = 1;
2564         else if (!strcmp(res->opname, "stop"))
2565                 isstart = 0;
2566         else {
2567                 printf("Unknown parameter\n");
2568                 return;
2569         }
2570
2571         if (isstart && isrx)
2572                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2573         else if (!isstart && isrx)
2574                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2575         else if (isstart && !isrx)
2576                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2577         else
2578                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2579
2580         if (ret == -ENOTSUP)
2581                 printf("Function not supported in PMD driver\n");
2582 }
2583
2584 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2585         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2586 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2587         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2588 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2589         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2590 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2591         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2592 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2593         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2594                                                 "start#stop");
2595
2596 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2597         .f = cmd_config_rxtx_queue_parsed,
2598         .data = NULL,
2599         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2600         .tokens = {
2601                 (void *)&cmd_config_rxtx_queue_port,
2602                 (void *)&cmd_config_rxtx_queue_portid,
2603                 (void *)&cmd_config_rxtx_queue_rxtxq,
2604                 (void *)&cmd_config_rxtx_queue_qid,
2605                 (void *)&cmd_config_rxtx_queue_opname,
2606                 NULL,
2607         },
2608 };
2609
2610 /* *** configure port rxq/txq deferred start on/off *** */
2611 struct cmd_config_deferred_start_rxtx_queue {
2612         cmdline_fixed_string_t port;
2613         portid_t port_id;
2614         cmdline_fixed_string_t rxtxq;
2615         uint16_t qid;
2616         cmdline_fixed_string_t opname;
2617         cmdline_fixed_string_t state;
2618 };
2619
2620 static void
2621 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2622                         __attribute__((unused)) struct cmdline *cl,
2623                         __attribute__((unused)) void *data)
2624 {
2625         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2626         struct rte_port *port;
2627         uint8_t isrx;
2628         uint8_t ison;
2629         uint8_t needreconfig = 0;
2630
2631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2632                 return;
2633
2634         if (port_is_started(res->port_id) != 0) {
2635                 printf("Please stop port %u first\n", res->port_id);
2636                 return;
2637         }
2638
2639         port = &ports[res->port_id];
2640
2641         isrx = !strcmp(res->rxtxq, "rxq");
2642
2643         if (isrx && rx_queue_id_is_invalid(res->qid))
2644                 return;
2645         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2646                 return;
2647
2648         ison = !strcmp(res->state, "on");
2649
2650         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2651                 port->rx_conf[res->qid].rx_deferred_start = ison;
2652                 needreconfig = 1;
2653         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2654                 port->tx_conf[res->qid].tx_deferred_start = ison;
2655                 needreconfig = 1;
2656         }
2657
2658         if (needreconfig)
2659                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2660 }
2661
2662 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2663         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2664                                                 port, "port");
2665 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2666         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2667                                                 port_id, UINT16);
2668 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2669         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2670                                                 rxtxq, "rxq#txq");
2671 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2672         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2673                                                 qid, UINT16);
2674 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2675         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2676                                                 opname, "deferred_start");
2677 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2678         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2679                                                 state, "on#off");
2680
2681 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2682         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2683         .data = NULL,
2684         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2685         .tokens = {
2686                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2687                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2688                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2689                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2690                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2691                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2692                 NULL,
2693         },
2694 };
2695
2696 /* *** configure port rxq/txq setup *** */
2697 struct cmd_setup_rxtx_queue {
2698         cmdline_fixed_string_t port;
2699         portid_t portid;
2700         cmdline_fixed_string_t rxtxq;
2701         uint16_t qid;
2702         cmdline_fixed_string_t setup;
2703 };
2704
2705 /* Common CLI fields for queue setup */
2706 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2707         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2708 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2709         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2710 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2711         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2712 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2713         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2714 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2715         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2716
2717 static void
2718 cmd_setup_rxtx_queue_parsed(
2719         void *parsed_result,
2720         __attribute__((unused)) struct cmdline *cl,
2721         __attribute__((unused)) void *data)
2722 {
2723         struct cmd_setup_rxtx_queue *res = parsed_result;
2724         struct rte_port *port;
2725         struct rte_mempool *mp;
2726         unsigned int socket_id;
2727         uint8_t isrx = 0;
2728         int ret;
2729
2730         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2731                 return;
2732
2733         if (res->portid == (portid_t)RTE_PORT_ALL) {
2734                 printf("Invalid port id\n");
2735                 return;
2736         }
2737
2738         if (!strcmp(res->rxtxq, "rxq"))
2739                 isrx = 1;
2740         else if (!strcmp(res->rxtxq, "txq"))
2741                 isrx = 0;
2742         else {
2743                 printf("Unknown parameter\n");
2744                 return;
2745         }
2746
2747         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2748                 printf("Invalid rx queue\n");
2749                 return;
2750         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2751                 printf("Invalid tx queue\n");
2752                 return;
2753         }
2754
2755         port = &ports[res->portid];
2756         if (isrx) {
2757                 socket_id = rxring_numa[res->portid];
2758                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2759                         socket_id = port->socket_id;
2760
2761                 mp = mbuf_pool_find(socket_id);
2762                 if (mp == NULL) {
2763                         printf("Failed to setup RX queue: "
2764                                 "No mempool allocation"
2765                                 " on the socket %d\n",
2766                                 rxring_numa[res->portid]);
2767                         return;
2768                 }
2769                 ret = rte_eth_rx_queue_setup(res->portid,
2770                                              res->qid,
2771                                              port->nb_rx_desc[res->qid],
2772                                              socket_id,
2773                                              &port->rx_conf[res->qid],
2774                                              mp);
2775                 if (ret)
2776                         printf("Failed to setup RX queue\n");
2777         } else {
2778                 socket_id = txring_numa[res->portid];
2779                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2780                         socket_id = port->socket_id;
2781
2782                 ret = rte_eth_tx_queue_setup(res->portid,
2783                                              res->qid,
2784                                              port->nb_tx_desc[res->qid],
2785                                              socket_id,
2786                                              &port->tx_conf[res->qid]);
2787                 if (ret)
2788                         printf("Failed to setup TX queue\n");
2789         }
2790 }
2791
2792 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2793         .f = cmd_setup_rxtx_queue_parsed,
2794         .data = NULL,
2795         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2796         .tokens = {
2797                 (void *)&cmd_setup_rxtx_queue_port,
2798                 (void *)&cmd_setup_rxtx_queue_portid,
2799                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2800                 (void *)&cmd_setup_rxtx_queue_qid,
2801                 (void *)&cmd_setup_rxtx_queue_setup,
2802                 NULL,
2803         },
2804 };
2805
2806
2807 /* *** Configure RSS RETA *** */
2808 struct cmd_config_rss_reta {
2809         cmdline_fixed_string_t port;
2810         cmdline_fixed_string_t keyword;
2811         portid_t port_id;
2812         cmdline_fixed_string_t name;
2813         cmdline_fixed_string_t list_name;
2814         cmdline_fixed_string_t list_of_items;
2815 };
2816
2817 static int
2818 parse_reta_config(const char *str,
2819                   struct rte_eth_rss_reta_entry64 *reta_conf,
2820                   uint16_t nb_entries)
2821 {
2822         int i;
2823         unsigned size;
2824         uint16_t hash_index, idx, shift;
2825         uint16_t nb_queue;
2826         char s[256];
2827         const char *p, *p0 = str;
2828         char *end;
2829         enum fieldnames {
2830                 FLD_HASH_INDEX = 0,
2831                 FLD_QUEUE,
2832                 _NUM_FLD
2833         };
2834         unsigned long int_fld[_NUM_FLD];
2835         char *str_fld[_NUM_FLD];
2836
2837         while ((p = strchr(p0,'(')) != NULL) {
2838                 ++p;
2839                 if((p0 = strchr(p,')')) == NULL)
2840                         return -1;
2841
2842                 size = p0 - p;
2843                 if(size >= sizeof(s))
2844                         return -1;
2845
2846                 snprintf(s, sizeof(s), "%.*s", size, p);
2847                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2848                         return -1;
2849                 for (i = 0; i < _NUM_FLD; i++) {
2850                         errno = 0;
2851                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2852                         if (errno != 0 || end == str_fld[i] ||
2853                                         int_fld[i] > 65535)
2854                                 return -1;
2855                 }
2856
2857                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2858                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2859
2860                 if (hash_index >= nb_entries) {
2861                         printf("Invalid RETA hash index=%d\n", hash_index);
2862                         return -1;
2863                 }
2864
2865                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2866                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2867                 reta_conf[idx].mask |= (1ULL << shift);
2868                 reta_conf[idx].reta[shift] = nb_queue;
2869         }
2870
2871         return 0;
2872 }
2873
2874 static void
2875 cmd_set_rss_reta_parsed(void *parsed_result,
2876                         __attribute__((unused)) struct cmdline *cl,
2877                         __attribute__((unused)) void *data)
2878 {
2879         int ret;
2880         struct rte_eth_dev_info dev_info;
2881         struct rte_eth_rss_reta_entry64 reta_conf[8];
2882         struct cmd_config_rss_reta *res = parsed_result;
2883
2884         memset(&dev_info, 0, sizeof(dev_info));
2885         rte_eth_dev_info_get(res->port_id, &dev_info);
2886         if (dev_info.reta_size == 0) {
2887                 printf("Redirection table size is 0 which is "
2888                                         "invalid for RSS\n");
2889                 return;
2890         } else
2891                 printf("The reta size of port %d is %u\n",
2892                         res->port_id, dev_info.reta_size);
2893         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2894                 printf("Currently do not support more than %u entries of "
2895                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2896                 return;
2897         }
2898
2899         memset(reta_conf, 0, sizeof(reta_conf));
2900         if (!strcmp(res->list_name, "reta")) {
2901                 if (parse_reta_config(res->list_of_items, reta_conf,
2902                                                 dev_info.reta_size)) {
2903                         printf("Invalid RSS Redirection Table "
2904                                         "config entered\n");
2905                         return;
2906                 }
2907                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2908                                 reta_conf, dev_info.reta_size);
2909                 if (ret != 0)
2910                         printf("Bad redirection table parameter, "
2911                                         "return code = %d \n", ret);
2912         }
2913 }
2914
2915 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2916         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2917 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2918         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2919 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2920         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2921 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2922         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2923 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2924         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2925 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2926         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2927                                  NULL);
2928 cmdline_parse_inst_t cmd_config_rss_reta = {
2929         .f = cmd_set_rss_reta_parsed,
2930         .data = NULL,
2931         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2932         .tokens = {
2933                 (void *)&cmd_config_rss_reta_port,
2934                 (void *)&cmd_config_rss_reta_keyword,
2935                 (void *)&cmd_config_rss_reta_port_id,
2936                 (void *)&cmd_config_rss_reta_name,
2937                 (void *)&cmd_config_rss_reta_list_name,
2938                 (void *)&cmd_config_rss_reta_list_of_items,
2939                 NULL,
2940         },
2941 };
2942
2943 /* *** SHOW PORT RETA INFO *** */
2944 struct cmd_showport_reta {
2945         cmdline_fixed_string_t show;
2946         cmdline_fixed_string_t port;
2947         portid_t port_id;
2948         cmdline_fixed_string_t rss;
2949         cmdline_fixed_string_t reta;
2950         uint16_t size;
2951         cmdline_fixed_string_t list_of_items;
2952 };
2953
2954 static int
2955 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2956                            uint16_t nb_entries,
2957                            char *str)
2958 {
2959         uint32_t size;
2960         const char *p, *p0 = str;
2961         char s[256];
2962         char *end;
2963         char *str_fld[8];
2964         uint16_t i;
2965         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2966                         RTE_RETA_GROUP_SIZE;
2967         int ret;
2968
2969         p = strchr(p0, '(');
2970         if (p == NULL)
2971                 return -1;
2972         p++;
2973         p0 = strchr(p, ')');
2974         if (p0 == NULL)
2975                 return -1;
2976         size = p0 - p;
2977         if (size >= sizeof(s)) {
2978                 printf("The string size exceeds the internal buffer size\n");
2979                 return -1;
2980         }
2981         snprintf(s, sizeof(s), "%.*s", size, p);
2982         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2983         if (ret <= 0 || ret != num) {
2984                 printf("The bits of masks do not match the number of "
2985                                         "reta entries: %u\n", num);
2986                 return -1;
2987         }
2988         for (i = 0; i < ret; i++)
2989                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2990
2991         return 0;
2992 }
2993
2994 static void
2995 cmd_showport_reta_parsed(void *parsed_result,
2996                          __attribute__((unused)) struct cmdline *cl,
2997                          __attribute__((unused)) void *data)
2998 {
2999         struct cmd_showport_reta *res = parsed_result;
3000         struct rte_eth_rss_reta_entry64 reta_conf[8];
3001         struct rte_eth_dev_info dev_info;
3002         uint16_t max_reta_size;
3003
3004         memset(&dev_info, 0, sizeof(dev_info));
3005         rte_eth_dev_info_get(res->port_id, &dev_info);
3006         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3007         if (res->size == 0 || res->size > max_reta_size) {
3008                 printf("Invalid redirection table size: %u (1-%u)\n",
3009                         res->size, max_reta_size);
3010                 return;
3011         }
3012
3013         memset(reta_conf, 0, sizeof(reta_conf));
3014         if (showport_parse_reta_config(reta_conf, res->size,
3015                                 res->list_of_items) < 0) {
3016                 printf("Invalid string: %s for reta masks\n",
3017                                         res->list_of_items);
3018                 return;
3019         }
3020         port_rss_reta_info(res->port_id, reta_conf, res->size);
3021 }
3022
3023 cmdline_parse_token_string_t cmd_showport_reta_show =
3024         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3025 cmdline_parse_token_string_t cmd_showport_reta_port =
3026         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3027 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3028         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3029 cmdline_parse_token_string_t cmd_showport_reta_rss =
3030         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3031 cmdline_parse_token_string_t cmd_showport_reta_reta =
3032         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3033 cmdline_parse_token_num_t cmd_showport_reta_size =
3034         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3035 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3036         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3037                                         list_of_items, NULL);
3038
3039 cmdline_parse_inst_t cmd_showport_reta = {
3040         .f = cmd_showport_reta_parsed,
3041         .data = NULL,
3042         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3043         .tokens = {
3044                 (void *)&cmd_showport_reta_show,
3045                 (void *)&cmd_showport_reta_port,
3046                 (void *)&cmd_showport_reta_port_id,
3047                 (void *)&cmd_showport_reta_rss,
3048                 (void *)&cmd_showport_reta_reta,
3049                 (void *)&cmd_showport_reta_size,
3050                 (void *)&cmd_showport_reta_list_of_items,
3051                 NULL,
3052         },
3053 };
3054
3055 /* *** Show RSS hash configuration *** */
3056 struct cmd_showport_rss_hash {
3057         cmdline_fixed_string_t show;
3058         cmdline_fixed_string_t port;
3059         portid_t port_id;
3060         cmdline_fixed_string_t rss_hash;
3061         cmdline_fixed_string_t rss_type;
3062         cmdline_fixed_string_t key; /* optional argument */
3063 };
3064
3065 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3066                                 __attribute__((unused)) struct cmdline *cl,
3067                                 void *show_rss_key)
3068 {
3069         struct cmd_showport_rss_hash *res = parsed_result;
3070
3071         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3072 }
3073
3074 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3075         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3076 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3077         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3078 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3079         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3080 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3081         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3082                                  "rss-hash");
3083 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3084         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3085
3086 cmdline_parse_inst_t cmd_showport_rss_hash = {
3087         .f = cmd_showport_rss_hash_parsed,
3088         .data = NULL,
3089         .help_str = "show port <port_id> rss-hash",
3090         .tokens = {
3091                 (void *)&cmd_showport_rss_hash_show,
3092                 (void *)&cmd_showport_rss_hash_port,
3093                 (void *)&cmd_showport_rss_hash_port_id,
3094                 (void *)&cmd_showport_rss_hash_rss_hash,
3095                 NULL,
3096         },
3097 };
3098
3099 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3100         .f = cmd_showport_rss_hash_parsed,
3101         .data = (void *)1,
3102         .help_str = "show port <port_id> rss-hash key",
3103         .tokens = {
3104                 (void *)&cmd_showport_rss_hash_show,
3105                 (void *)&cmd_showport_rss_hash_port,
3106                 (void *)&cmd_showport_rss_hash_port_id,
3107                 (void *)&cmd_showport_rss_hash_rss_hash,
3108                 (void *)&cmd_showport_rss_hash_rss_key,
3109                 NULL,
3110         },
3111 };
3112
3113 /* *** Configure DCB *** */
3114 struct cmd_config_dcb {
3115         cmdline_fixed_string_t port;
3116         cmdline_fixed_string_t config;
3117         portid_t port_id;
3118         cmdline_fixed_string_t dcb;
3119         cmdline_fixed_string_t vt;
3120         cmdline_fixed_string_t vt_en;
3121         uint8_t num_tcs;
3122         cmdline_fixed_string_t pfc;
3123         cmdline_fixed_string_t pfc_en;
3124 };
3125
3126 static void
3127 cmd_config_dcb_parsed(void *parsed_result,
3128                         __attribute__((unused)) struct cmdline *cl,
3129                         __attribute__((unused)) void *data)
3130 {
3131         struct cmd_config_dcb *res = parsed_result;
3132         portid_t port_id = res->port_id;
3133         struct rte_port *port;
3134         uint8_t pfc_en;
3135         int ret;
3136
3137         port = &ports[port_id];
3138         /** Check if the port is not started **/
3139         if (port->port_status != RTE_PORT_STOPPED) {
3140                 printf("Please stop port %d first\n", port_id);
3141                 return;
3142         }
3143
3144         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3145                 printf("The invalid number of traffic class,"
3146                         " only 4 or 8 allowed.\n");
3147                 return;
3148         }
3149
3150         if (nb_fwd_lcores < res->num_tcs) {
3151                 printf("nb_cores shouldn't be less than number of TCs.\n");
3152                 return;
3153         }
3154         if (!strncmp(res->pfc_en, "on", 2))
3155                 pfc_en = 1;
3156         else
3157                 pfc_en = 0;
3158
3159         /* DCB in VT mode */
3160         if (!strncmp(res->vt_en, "on", 2))
3161                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3162                                 (enum rte_eth_nb_tcs)res->num_tcs,
3163                                 pfc_en);
3164         else
3165                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3166                                 (enum rte_eth_nb_tcs)res->num_tcs,
3167                                 pfc_en);
3168
3169
3170         if (ret != 0) {
3171                 printf("Cannot initialize network ports.\n");
3172                 return;
3173         }
3174
3175         cmd_reconfig_device_queue(port_id, 1, 1);
3176 }
3177
3178 cmdline_parse_token_string_t cmd_config_dcb_port =
3179         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3180 cmdline_parse_token_string_t cmd_config_dcb_config =
3181         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3182 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3183         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3184 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3185         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3186 cmdline_parse_token_string_t cmd_config_dcb_vt =
3187         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3188 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3189         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3190 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3191         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3192 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3193         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3194 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3195         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3196
3197 cmdline_parse_inst_t cmd_config_dcb = {
3198         .f = cmd_config_dcb_parsed,
3199         .data = NULL,
3200         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3201         .tokens = {
3202                 (void *)&cmd_config_dcb_port,
3203                 (void *)&cmd_config_dcb_config,
3204                 (void *)&cmd_config_dcb_port_id,
3205                 (void *)&cmd_config_dcb_dcb,
3206                 (void *)&cmd_config_dcb_vt,
3207                 (void *)&cmd_config_dcb_vt_en,
3208                 (void *)&cmd_config_dcb_num_tcs,
3209                 (void *)&cmd_config_dcb_pfc,
3210                 (void *)&cmd_config_dcb_pfc_en,
3211                 NULL,
3212         },
3213 };
3214
3215 /* *** configure number of packets per burst *** */
3216 struct cmd_config_burst {
3217         cmdline_fixed_string_t port;
3218         cmdline_fixed_string_t keyword;
3219         cmdline_fixed_string_t all;
3220         cmdline_fixed_string_t name;
3221         uint16_t value;
3222 };
3223
3224 static void
3225 cmd_config_burst_parsed(void *parsed_result,
3226                         __attribute__((unused)) struct cmdline *cl,
3227                         __attribute__((unused)) void *data)
3228 {
3229         struct cmd_config_burst *res = parsed_result;
3230         struct rte_eth_dev_info dev_info;
3231         uint16_t rec_nb_pkts;
3232
3233         if (!all_ports_stopped()) {
3234                 printf("Please stop all ports first\n");
3235                 return;
3236         }
3237
3238         if (!strcmp(res->name, "burst")) {
3239                 if (res->value == 0) {
3240                         /* If user gives a value of zero, query the PMD for
3241                          * its recommended Rx burst size. Testpmd uses a single
3242                          * size for all ports, so assume all ports are the same
3243                          * NIC model and use the values from Port 0.
3244                          */
3245                         rte_eth_dev_info_get(0, &dev_info);
3246                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3247
3248                         if (rec_nb_pkts == 0) {
3249                                 printf("PMD does not recommend a burst size.\n"
3250                                         "User provided value must be between"
3251                                         " 1 and %d\n", MAX_PKT_BURST);
3252                                 return;
3253                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3254                                 printf("PMD recommended burst size of %d"
3255                                         " exceeds maximum value of %d\n",
3256                                         rec_nb_pkts, MAX_PKT_BURST);
3257                                 return;
3258                         }
3259                         printf("Using PMD-provided burst value of %d\n",
3260                                 rec_nb_pkts);
3261                         nb_pkt_per_burst = rec_nb_pkts;
3262                 } else if (res->value > MAX_PKT_BURST) {
3263                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3264                         return;
3265                 } else
3266                         nb_pkt_per_burst = res->value;
3267         } else {
3268                 printf("Unknown parameter\n");
3269                 return;
3270         }
3271
3272         init_port_config();
3273
3274         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3275 }
3276
3277 cmdline_parse_token_string_t cmd_config_burst_port =
3278         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3279 cmdline_parse_token_string_t cmd_config_burst_keyword =
3280         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3281 cmdline_parse_token_string_t cmd_config_burst_all =
3282         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3283 cmdline_parse_token_string_t cmd_config_burst_name =
3284         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3285 cmdline_parse_token_num_t cmd_config_burst_value =
3286         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3287
3288 cmdline_parse_inst_t cmd_config_burst = {
3289         .f = cmd_config_burst_parsed,
3290         .data = NULL,
3291         .help_str = "port config all burst <value>",
3292         .tokens = {
3293                 (void *)&cmd_config_burst_port,
3294                 (void *)&cmd_config_burst_keyword,
3295                 (void *)&cmd_config_burst_all,
3296                 (void *)&cmd_config_burst_name,
3297                 (void *)&cmd_config_burst_value,
3298                 NULL,
3299         },
3300 };
3301
3302 /* *** configure rx/tx queues *** */
3303 struct cmd_config_thresh {
3304         cmdline_fixed_string_t port;
3305         cmdline_fixed_string_t keyword;
3306         cmdline_fixed_string_t all;
3307         cmdline_fixed_string_t name;
3308         uint8_t value;
3309 };
3310
3311 static void
3312 cmd_config_thresh_parsed(void *parsed_result,
3313                         __attribute__((unused)) struct cmdline *cl,
3314                         __attribute__((unused)) void *data)
3315 {
3316         struct cmd_config_thresh *res = parsed_result;
3317
3318         if (!all_ports_stopped()) {
3319                 printf("Please stop all ports first\n");
3320                 return;
3321         }
3322
3323         if (!strcmp(res->name, "txpt"))
3324                 tx_pthresh = res->value;
3325         else if(!strcmp(res->name, "txht"))
3326                 tx_hthresh = res->value;
3327         else if(!strcmp(res->name, "txwt"))
3328                 tx_wthresh = res->value;
3329         else if(!strcmp(res->name, "rxpt"))
3330                 rx_pthresh = res->value;
3331         else if(!strcmp(res->name, "rxht"))
3332                 rx_hthresh = res->value;
3333         else if(!strcmp(res->name, "rxwt"))
3334                 rx_wthresh = res->value;
3335         else {
3336                 printf("Unknown parameter\n");
3337                 return;
3338         }
3339
3340         init_port_config();
3341
3342         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3343 }
3344
3345 cmdline_parse_token_string_t cmd_config_thresh_port =
3346         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3347 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3348         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3349 cmdline_parse_token_string_t cmd_config_thresh_all =
3350         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3351 cmdline_parse_token_string_t cmd_config_thresh_name =
3352         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3353                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3354 cmdline_parse_token_num_t cmd_config_thresh_value =
3355         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3356
3357 cmdline_parse_inst_t cmd_config_thresh = {
3358         .f = cmd_config_thresh_parsed,
3359         .data = NULL,
3360         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3361         .tokens = {
3362                 (void *)&cmd_config_thresh_port,
3363                 (void *)&cmd_config_thresh_keyword,
3364                 (void *)&cmd_config_thresh_all,
3365                 (void *)&cmd_config_thresh_name,
3366                 (void *)&cmd_config_thresh_value,
3367                 NULL,
3368         },
3369 };
3370
3371 /* *** configure free/rs threshold *** */
3372 struct cmd_config_threshold {
3373         cmdline_fixed_string_t port;
3374         cmdline_fixed_string_t keyword;
3375         cmdline_fixed_string_t all;
3376         cmdline_fixed_string_t name;
3377         uint16_t value;
3378 };
3379
3380 static void
3381 cmd_config_threshold_parsed(void *parsed_result,
3382                         __attribute__((unused)) struct cmdline *cl,
3383                         __attribute__((unused)) void *data)
3384 {
3385         struct cmd_config_threshold *res = parsed_result;
3386
3387         if (!all_ports_stopped()) {
3388                 printf("Please stop all ports first\n");
3389                 return;
3390         }
3391
3392         if (!strcmp(res->name, "txfreet"))
3393                 tx_free_thresh = res->value;
3394         else if (!strcmp(res->name, "txrst"))
3395                 tx_rs_thresh = res->value;
3396         else if (!strcmp(res->name, "rxfreet"))
3397                 rx_free_thresh = res->value;
3398         else {
3399                 printf("Unknown parameter\n");
3400                 return;
3401         }
3402
3403         init_port_config();
3404
3405         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3406 }
3407
3408 cmdline_parse_token_string_t cmd_config_threshold_port =
3409         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3410 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3411         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3412                                                                 "config");
3413 cmdline_parse_token_string_t cmd_config_threshold_all =
3414         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3415 cmdline_parse_token_string_t cmd_config_threshold_name =
3416         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3417                                                 "txfreet#txrst#rxfreet");
3418 cmdline_parse_token_num_t cmd_config_threshold_value =
3419         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3420
3421 cmdline_parse_inst_t cmd_config_threshold = {
3422         .f = cmd_config_threshold_parsed,
3423         .data = NULL,
3424         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3425         .tokens = {
3426                 (void *)&cmd_config_threshold_port,
3427                 (void *)&cmd_config_threshold_keyword,
3428                 (void *)&cmd_config_threshold_all,
3429                 (void *)&cmd_config_threshold_name,
3430                 (void *)&cmd_config_threshold_value,
3431                 NULL,
3432         },
3433 };
3434
3435 /* *** stop *** */
3436 struct cmd_stop_result {
3437         cmdline_fixed_string_t stop;
3438 };
3439
3440 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3441                             __attribute__((unused)) struct cmdline *cl,
3442                             __attribute__((unused)) void *data)
3443 {
3444         stop_packet_forwarding();
3445 }
3446
3447 cmdline_parse_token_string_t cmd_stop_stop =
3448         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3449
3450 cmdline_parse_inst_t cmd_stop = {
3451         .f = cmd_stop_parsed,
3452         .data = NULL,
3453         .help_str = "stop: Stop packet forwarding",
3454         .tokens = {
3455                 (void *)&cmd_stop_stop,
3456                 NULL,
3457         },
3458 };
3459
3460 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3461
3462 unsigned int
3463 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3464                 unsigned int *parsed_items, int check_unique_values)
3465 {
3466         unsigned int nb_item;
3467         unsigned int value;
3468         unsigned int i;
3469         unsigned int j;
3470         int value_ok;
3471         char c;
3472
3473         /*
3474          * First parse all items in the list and store their value.
3475          */
3476         value = 0;
3477         nb_item = 0;
3478         value_ok = 0;
3479         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3480                 c = str[i];
3481                 if ((c >= '0') && (c <= '9')) {
3482                         value = (unsigned int) (value * 10 + (c - '0'));
3483                         value_ok = 1;
3484                         continue;
3485                 }
3486                 if (c != ',') {
3487                         printf("character %c is not a decimal digit\n", c);
3488                         return 0;
3489                 }
3490                 if (! value_ok) {
3491                         printf("No valid value before comma\n");
3492                         return 0;
3493                 }
3494                 if (nb_item < max_items) {
3495                         parsed_items[nb_item] = value;
3496                         value_ok = 0;
3497                         value = 0;
3498                 }
3499                 nb_item++;
3500         }
3501         if (nb_item >= max_items) {
3502                 printf("Number of %s = %u > %u (maximum items)\n",
3503                        item_name, nb_item + 1, max_items);
3504                 return 0;
3505         }
3506         parsed_items[nb_item++] = value;
3507         if (! check_unique_values)
3508                 return nb_item;
3509
3510         /*
3511          * Then, check that all values in the list are differents.
3512          * No optimization here...
3513          */
3514         for (i = 0; i < nb_item; i++) {
3515                 for (j = i + 1; j < nb_item; j++) {
3516                         if (parsed_items[j] == parsed_items[i]) {
3517                                 printf("duplicated %s %u at index %u and %u\n",
3518                                        item_name, parsed_items[i], i, j);
3519                                 return 0;
3520                         }
3521                 }
3522         }
3523         return nb_item;
3524 }
3525
3526 struct cmd_set_list_result {
3527         cmdline_fixed_string_t cmd_keyword;
3528         cmdline_fixed_string_t list_name;
3529         cmdline_fixed_string_t list_of_items;
3530 };
3531
3532 static void cmd_set_list_parsed(void *parsed_result,
3533                                 __attribute__((unused)) struct cmdline *cl,
3534                                 __attribute__((unused)) void *data)
3535 {
3536         struct cmd_set_list_result *res;
3537         union {
3538                 unsigned int lcorelist[RTE_MAX_LCORE];
3539                 unsigned int portlist[RTE_MAX_ETHPORTS];
3540         } parsed_items;
3541         unsigned int nb_item;
3542
3543         if (test_done == 0) {
3544                 printf("Please stop forwarding first\n");
3545                 return;
3546         }
3547
3548         res = parsed_result;
3549         if (!strcmp(res->list_name, "corelist")) {
3550                 nb_item = parse_item_list(res->list_of_items, "core",
3551                                           RTE_MAX_LCORE,
3552                                           parsed_items.lcorelist, 1);
3553                 if (nb_item > 0) {
3554                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3555                         fwd_config_setup();
3556                 }
3557                 return;
3558         }
3559         if (!strcmp(res->list_name, "portlist")) {
3560                 nb_item = parse_item_list(res->list_of_items, "port",
3561                                           RTE_MAX_ETHPORTS,
3562                                           parsed_items.portlist, 1);
3563                 if (nb_item > 0) {
3564                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3565                         fwd_config_setup();
3566                 }
3567         }
3568 }
3569
3570 cmdline_parse_token_string_t cmd_set_list_keyword =
3571         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3572                                  "set");
3573 cmdline_parse_token_string_t cmd_set_list_name =
3574         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3575                                  "corelist#portlist");
3576 cmdline_parse_token_string_t cmd_set_list_of_items =
3577         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3578                                  NULL);
3579
3580 cmdline_parse_inst_t cmd_set_fwd_list = {
3581         .f = cmd_set_list_parsed,
3582         .data = NULL,
3583         .help_str = "set corelist|portlist <list0[,list1]*>",
3584         .tokens = {
3585                 (void *)&cmd_set_list_keyword,
3586                 (void *)&cmd_set_list_name,
3587                 (void *)&cmd_set_list_of_items,
3588                 NULL,
3589         },
3590 };
3591
3592 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3593
3594 struct cmd_setmask_result {
3595         cmdline_fixed_string_t set;
3596         cmdline_fixed_string_t mask;
3597         uint64_t hexavalue;
3598 };
3599
3600 static void cmd_set_mask_parsed(void *parsed_result,
3601                                 __attribute__((unused)) struct cmdline *cl,
3602                                 __attribute__((unused)) void *data)
3603 {
3604         struct cmd_setmask_result *res = parsed_result;
3605
3606         if (test_done == 0) {
3607                 printf("Please stop forwarding first\n");
3608                 return;
3609         }
3610         if (!strcmp(res->mask, "coremask")) {
3611                 set_fwd_lcores_mask(res->hexavalue);
3612                 fwd_config_setup();
3613         } else if (!strcmp(res->mask, "portmask")) {
3614                 set_fwd_ports_mask(res->hexavalue);
3615                 fwd_config_setup();
3616         }
3617 }
3618
3619 cmdline_parse_token_string_t cmd_setmask_set =
3620         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3621 cmdline_parse_token_string_t cmd_setmask_mask =
3622         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3623                                  "coremask#portmask");
3624 cmdline_parse_token_num_t cmd_setmask_value =
3625         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3626
3627 cmdline_parse_inst_t cmd_set_fwd_mask = {
3628         .f = cmd_set_mask_parsed,
3629         .data = NULL,
3630         .help_str = "set coremask|portmask <hexadecimal value>",
3631         .tokens = {
3632                 (void *)&cmd_setmask_set,
3633                 (void *)&cmd_setmask_mask,
3634                 (void *)&cmd_setmask_value,
3635                 NULL,
3636         },
3637 };
3638
3639 /*
3640  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3641  */
3642 struct cmd_set_result {
3643         cmdline_fixed_string_t set;
3644         cmdline_fixed_string_t what;
3645         uint16_t value;
3646 };
3647
3648 static void cmd_set_parsed(void *parsed_result,
3649                            __attribute__((unused)) struct cmdline *cl,
3650                            __attribute__((unused)) void *data)
3651 {
3652         struct cmd_set_result *res = parsed_result;
3653         if (!strcmp(res->what, "nbport")) {
3654                 set_fwd_ports_number(res->value);
3655                 fwd_config_setup();
3656         } else if (!strcmp(res->what, "nbcore")) {
3657                 set_fwd_lcores_number(res->value);
3658                 fwd_config_setup();
3659         } else if (!strcmp(res->what, "burst"))
3660                 set_nb_pkt_per_burst(res->value);
3661         else if (!strcmp(res->what, "verbose"))
3662                 set_verbose_level(res->value);
3663 }
3664
3665 cmdline_parse_token_string_t cmd_set_set =
3666         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3667 cmdline_parse_token_string_t cmd_set_what =
3668         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3669                                  "nbport#nbcore#burst#verbose");
3670 cmdline_parse_token_num_t cmd_set_value =
3671         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3672
3673 cmdline_parse_inst_t cmd_set_numbers = {
3674         .f = cmd_set_parsed,
3675         .data = NULL,
3676         .help_str = "set nbport|nbcore|burst|verbose <value>",
3677         .tokens = {
3678                 (void *)&cmd_set_set,
3679                 (void *)&cmd_set_what,
3680                 (void *)&cmd_set_value,
3681                 NULL,
3682         },
3683 };
3684
3685 /* *** SET LOG LEVEL CONFIGURATION *** */
3686
3687 struct cmd_set_log_result {
3688         cmdline_fixed_string_t set;
3689         cmdline_fixed_string_t log;
3690         cmdline_fixed_string_t type;
3691         uint32_t level;
3692 };
3693
3694 static void
3695 cmd_set_log_parsed(void *parsed_result,
3696                    __attribute__((unused)) struct cmdline *cl,
3697                    __attribute__((unused)) void *data)
3698 {
3699         struct cmd_set_log_result *res;
3700         int ret;
3701
3702         res = parsed_result;
3703         if (!strcmp(res->type, "global"))
3704                 rte_log_set_global_level(res->level);
3705         else {
3706                 ret = rte_log_set_level_regexp(res->type, res->level);
3707                 if (ret < 0)
3708                         printf("Unable to set log level\n");
3709         }
3710 }
3711
3712 cmdline_parse_token_string_t cmd_set_log_set =
3713         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3714 cmdline_parse_token_string_t cmd_set_log_log =
3715         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3716 cmdline_parse_token_string_t cmd_set_log_type =
3717         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3718 cmdline_parse_token_num_t cmd_set_log_level =
3719         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3720
3721 cmdline_parse_inst_t cmd_set_log = {
3722         .f = cmd_set_log_parsed,
3723         .data = NULL,
3724         .help_str = "set log global|<type> <level>",
3725         .tokens = {
3726                 (void *)&cmd_set_log_set,
3727                 (void *)&cmd_set_log_log,
3728                 (void *)&cmd_set_log_type,
3729                 (void *)&cmd_set_log_level,
3730                 NULL,
3731         },
3732 };
3733
3734 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3735
3736 struct cmd_set_txpkts_result {
3737         cmdline_fixed_string_t cmd_keyword;
3738         cmdline_fixed_string_t txpkts;
3739         cmdline_fixed_string_t seg_lengths;
3740 };
3741
3742 static void
3743 cmd_set_txpkts_parsed(void *parsed_result,
3744                       __attribute__((unused)) struct cmdline *cl,
3745                       __attribute__((unused)) void *data)
3746 {
3747         struct cmd_set_txpkts_result *res;
3748         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3749         unsigned int nb_segs;
3750
3751         res = parsed_result;
3752         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3753                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3754         if (nb_segs > 0)
3755                 set_tx_pkt_segments(seg_lengths, nb_segs);
3756 }
3757
3758 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3760                                  cmd_keyword, "set");
3761 cmdline_parse_token_string_t cmd_set_txpkts_name =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3763                                  txpkts, "txpkts");
3764 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3765         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3766                                  seg_lengths, NULL);
3767
3768 cmdline_parse_inst_t cmd_set_txpkts = {
3769         .f = cmd_set_txpkts_parsed,
3770         .data = NULL,
3771         .help_str = "set txpkts <len0[,len1]*>",
3772         .tokens = {
3773                 (void *)&cmd_set_txpkts_keyword,
3774                 (void *)&cmd_set_txpkts_name,
3775                 (void *)&cmd_set_txpkts_lengths,
3776                 NULL,
3777         },
3778 };
3779
3780 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3781
3782 struct cmd_set_txsplit_result {
3783         cmdline_fixed_string_t cmd_keyword;
3784         cmdline_fixed_string_t txsplit;
3785         cmdline_fixed_string_t mode;
3786 };
3787
3788 static void
3789 cmd_set_txsplit_parsed(void *parsed_result,
3790                       __attribute__((unused)) struct cmdline *cl,
3791                       __attribute__((unused)) void *data)
3792 {
3793         struct cmd_set_txsplit_result *res;
3794
3795         res = parsed_result;
3796         set_tx_pkt_split(res->mode);
3797 }
3798
3799 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3800         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3801                                  cmd_keyword, "set");
3802 cmdline_parse_token_string_t cmd_set_txsplit_name =
3803         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3804                                  txsplit, "txsplit");
3805 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3806         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3807                                  mode, NULL);
3808
3809 cmdline_parse_inst_t cmd_set_txsplit = {
3810         .f = cmd_set_txsplit_parsed,
3811         .data = NULL,
3812         .help_str = "set txsplit on|off|rand",
3813         .tokens = {
3814                 (void *)&cmd_set_txsplit_keyword,
3815                 (void *)&cmd_set_txsplit_name,
3816                 (void *)&cmd_set_txsplit_mode,
3817                 NULL,
3818         },
3819 };
3820
3821 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3822 struct cmd_rx_vlan_filter_all_result {
3823         cmdline_fixed_string_t rx_vlan;
3824         cmdline_fixed_string_t what;
3825         cmdline_fixed_string_t all;
3826         portid_t port_id;
3827 };
3828
3829 static void
3830 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3831                               __attribute__((unused)) struct cmdline *cl,
3832                               __attribute__((unused)) void *data)
3833 {
3834         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3835
3836         if (!strcmp(res->what, "add"))
3837                 rx_vlan_all_filter_set(res->port_id, 1);
3838         else
3839                 rx_vlan_all_filter_set(res->port_id, 0);
3840 }
3841
3842 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3843         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3844                                  rx_vlan, "rx_vlan");
3845 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3846         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3847                                  what, "add#rm");
3848 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3849         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3850                                  all, "all");
3851 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3852         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3853                               port_id, UINT16);
3854
3855 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3856         .f = cmd_rx_vlan_filter_all_parsed,
3857         .data = NULL,
3858         .help_str = "rx_vlan add|rm all <port_id>: "
3859                 "Add/Remove all identifiers to/from the set of VLAN "
3860                 "identifiers filtered by a port",
3861         .tokens = {
3862                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3863                 (void *)&cmd_rx_vlan_filter_all_what,
3864                 (void *)&cmd_rx_vlan_filter_all_all,
3865                 (void *)&cmd_rx_vlan_filter_all_portid,
3866                 NULL,
3867         },
3868 };
3869
3870 /* *** VLAN OFFLOAD SET ON A PORT *** */
3871 struct cmd_vlan_offload_result {
3872         cmdline_fixed_string_t vlan;
3873         cmdline_fixed_string_t set;
3874         cmdline_fixed_string_t vlan_type;
3875         cmdline_fixed_string_t what;
3876         cmdline_fixed_string_t on;
3877         cmdline_fixed_string_t port_id;
3878 };
3879
3880 static void
3881 cmd_vlan_offload_parsed(void *parsed_result,
3882                           __attribute__((unused)) struct cmdline *cl,
3883                           __attribute__((unused)) void *data)
3884 {
3885         int on;
3886         struct cmd_vlan_offload_result *res = parsed_result;
3887         char *str;
3888         int i, len = 0;
3889         portid_t port_id = 0;
3890         unsigned int tmp;
3891
3892         str = res->port_id;
3893         len = strnlen(str, STR_TOKEN_SIZE);
3894         i = 0;
3895         /* Get port_id first */
3896         while(i < len){
3897                 if(str[i] == ',')
3898                         break;
3899
3900                 i++;
3901         }
3902         str[i]='\0';
3903         tmp = strtoul(str, NULL, 0);
3904         /* If port_id greater that what portid_t can represent, return */
3905         if(tmp >= RTE_MAX_ETHPORTS)
3906                 return;
3907         port_id = (portid_t)tmp;
3908
3909         if (!strcmp(res->on, "on"))
3910                 on = 1;
3911         else
3912                 on = 0;
3913
3914         if (!strcmp(res->what, "strip"))
3915                 rx_vlan_strip_set(port_id,  on);
3916         else if(!strcmp(res->what, "stripq")){
3917                 uint16_t queue_id = 0;
3918
3919                 /* No queue_id, return */
3920                 if(i + 1 >= len) {
3921                         printf("must specify (port,queue_id)\n");
3922                         return;
3923                 }
3924                 tmp = strtoul(str + i + 1, NULL, 0);
3925                 /* If queue_id greater that what 16-bits can represent, return */
3926                 if(tmp > 0xffff)
3927                         return;
3928
3929                 queue_id = (uint16_t)tmp;
3930                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3931         }
3932         else if (!strcmp(res->what, "filter"))
3933                 rx_vlan_filter_set(port_id, on);
3934         else
3935                 vlan_extend_set(port_id, on);
3936
3937         return;
3938 }
3939
3940 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3941         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3942                                  vlan, "vlan");
3943 cmdline_parse_token_string_t cmd_vlan_offload_set =
3944         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3945                                  set, "set");
3946 cmdline_parse_token_string_t cmd_vlan_offload_what =
3947         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3948                                  what, "strip#filter#qinq#stripq");
3949 cmdline_parse_token_string_t cmd_vlan_offload_on =
3950         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3951                               on, "on#off");
3952 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3953         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3954                               port_id, NULL);
3955
3956 cmdline_parse_inst_t cmd_vlan_offload = {
3957         .f = cmd_vlan_offload_parsed,
3958         .data = NULL,
3959         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3960                 "<port_id[,queue_id]>: "
3961                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3962         .tokens = {
3963                 (void *)&cmd_vlan_offload_vlan,
3964                 (void *)&cmd_vlan_offload_set,
3965                 (void *)&cmd_vlan_offload_what,
3966                 (void *)&cmd_vlan_offload_on,
3967                 (void *)&cmd_vlan_offload_portid,
3968                 NULL,
3969         },
3970 };
3971
3972 /* *** VLAN TPID SET ON A PORT *** */
3973 struct cmd_vlan_tpid_result {
3974         cmdline_fixed_string_t vlan;
3975         cmdline_fixed_string_t set;
3976         cmdline_fixed_string_t vlan_type;
3977         cmdline_fixed_string_t what;
3978         uint16_t tp_id;
3979         portid_t port_id;
3980 };
3981
3982 static void
3983 cmd_vlan_tpid_parsed(void *parsed_result,
3984                           __attribute__((unused)) struct cmdline *cl,
3985                           __attribute__((unused)) void *data)
3986 {
3987         struct cmd_vlan_tpid_result *res = parsed_result;
3988         enum rte_vlan_type vlan_type;
3989
3990         if (!strcmp(res->vlan_type, "inner"))
3991                 vlan_type = ETH_VLAN_TYPE_INNER;
3992         else if (!strcmp(res->vlan_type, "outer"))
3993                 vlan_type = ETH_VLAN_TYPE_OUTER;
3994         else {
3995                 printf("Unknown vlan type\n");
3996                 return;
3997         }
3998         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3999 }
4000
4001 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4002         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4003                                  vlan, "vlan");
4004 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4005         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4006                                  set, "set");
4007 cmdline_parse_token_string_t cmd_vlan_type =
4008         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4009                                  vlan_type, "inner#outer");
4010 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4011         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4012                                  what, "tpid");
4013 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4014         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4015                               tp_id, UINT16);
4016 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4017         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4018                               port_id, UINT16);
4019
4020 cmdline_parse_inst_t cmd_vlan_tpid = {
4021         .f = cmd_vlan_tpid_parsed,
4022         .data = NULL,
4023         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4024                 "Set the VLAN Ether type",
4025         .tokens = {
4026                 (void *)&cmd_vlan_tpid_vlan,
4027                 (void *)&cmd_vlan_tpid_set,
4028                 (void *)&cmd_vlan_type,
4029                 (void *)&cmd_vlan_tpid_what,
4030                 (void *)&cmd_vlan_tpid_tpid,
4031                 (void *)&cmd_vlan_tpid_portid,
4032                 NULL,
4033         },
4034 };
4035
4036 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4037 struct cmd_rx_vlan_filter_result {
4038         cmdline_fixed_string_t rx_vlan;
4039         cmdline_fixed_string_t what;
4040         uint16_t vlan_id;
4041         portid_t port_id;
4042 };
4043
4044 static void
4045 cmd_rx_vlan_filter_parsed(void *parsed_result,
4046                           __attribute__((unused)) struct cmdline *cl,
4047                           __attribute__((unused)) void *data)
4048 {
4049         struct cmd_rx_vlan_filter_result *res = parsed_result;
4050
4051         if (!strcmp(res->what, "add"))
4052                 rx_vft_set(res->port_id, res->vlan_id, 1);
4053         else
4054                 rx_vft_set(res->port_id, res->vlan_id, 0);
4055 }
4056
4057 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4058         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4059                                  rx_vlan, "rx_vlan");
4060 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4061         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4062                                  what, "add#rm");
4063 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4064         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4065                               vlan_id, UINT16);
4066 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4067         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4068                               port_id, UINT16);
4069
4070 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4071         .f = cmd_rx_vlan_filter_parsed,
4072         .data = NULL,
4073         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4074                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4075                 "identifiers filtered by a port",
4076         .tokens = {
4077                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4078                 (void *)&cmd_rx_vlan_filter_what,
4079                 (void *)&cmd_rx_vlan_filter_vlanid,
4080                 (void *)&cmd_rx_vlan_filter_portid,
4081                 NULL,
4082         },
4083 };
4084
4085 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4086 struct cmd_tx_vlan_set_result {
4087         cmdline_fixed_string_t tx_vlan;
4088         cmdline_fixed_string_t set;
4089         portid_t port_id;
4090         uint16_t vlan_id;
4091 };
4092
4093 static void
4094 cmd_tx_vlan_set_parsed(void *parsed_result,
4095                        __attribute__((unused)) struct cmdline *cl,
4096                        __attribute__((unused)) void *data)
4097 {
4098         struct cmd_tx_vlan_set_result *res = parsed_result;
4099
4100         if (!port_is_stopped(res->port_id)) {
4101                 printf("Please stop port %d first\n", res->port_id);
4102                 return;
4103         }
4104
4105         tx_vlan_set(res->port_id, res->vlan_id);
4106
4107         cmd_reconfig_device_queue(res->port_id, 1, 1);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4111         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4112                                  tx_vlan, "tx_vlan");
4113 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4115                                  set, "set");
4116 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4117         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4118                               port_id, UINT16);
4119 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4120         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4121                               vlan_id, UINT16);
4122
4123 cmdline_parse_inst_t cmd_tx_vlan_set = {
4124         .f = cmd_tx_vlan_set_parsed,
4125         .data = NULL,
4126         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4127                 "Enable hardware insertion of a single VLAN header "
4128                 "with a given TAG Identifier in packets sent on a port",
4129         .tokens = {
4130                 (void *)&cmd_tx_vlan_set_tx_vlan,
4131                 (void *)&cmd_tx_vlan_set_set,
4132                 (void *)&cmd_tx_vlan_set_portid,
4133                 (void *)&cmd_tx_vlan_set_vlanid,
4134                 NULL,
4135         },
4136 };
4137
4138 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4139 struct cmd_tx_vlan_set_qinq_result {
4140         cmdline_fixed_string_t tx_vlan;
4141         cmdline_fixed_string_t set;
4142         portid_t port_id;
4143         uint16_t vlan_id;
4144         uint16_t vlan_id_outer;
4145 };
4146
4147 static void
4148 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4149                             __attribute__((unused)) struct cmdline *cl,
4150                             __attribute__((unused)) void *data)
4151 {
4152         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4153
4154         if (!port_is_stopped(res->port_id)) {
4155                 printf("Please stop port %d first\n", res->port_id);
4156                 return;
4157         }
4158
4159         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4160
4161         cmd_reconfig_device_queue(res->port_id, 1, 1);
4162 }
4163
4164 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4165         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4166                 tx_vlan, "tx_vlan");
4167 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4168         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4169                 set, "set");
4170 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4171         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4172                 port_id, UINT16);
4173 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4174         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4175                 vlan_id, UINT16);
4176 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4177         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4178                 vlan_id_outer, UINT16);
4179
4180 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4181         .f = cmd_tx_vlan_set_qinq_parsed,
4182         .data = NULL,
4183         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4184                 "Enable hardware insertion of double VLAN header "
4185                 "with given TAG Identifiers in packets sent on a port",
4186         .tokens = {
4187                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4188                 (void *)&cmd_tx_vlan_set_qinq_set,
4189                 (void *)&cmd_tx_vlan_set_qinq_portid,
4190                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4191                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4192                 NULL,
4193         },
4194 };
4195
4196 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4197 struct cmd_tx_vlan_set_pvid_result {
4198         cmdline_fixed_string_t tx_vlan;
4199         cmdline_fixed_string_t set;
4200         cmdline_fixed_string_t pvid;
4201         portid_t port_id;
4202         uint16_t vlan_id;
4203         cmdline_fixed_string_t mode;
4204 };
4205
4206 static void
4207 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4208                             __attribute__((unused)) struct cmdline *cl,
4209                             __attribute__((unused)) void *data)
4210 {
4211         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4212
4213         if (strcmp(res->mode, "on") == 0)
4214                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4215         else
4216                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4217 }
4218
4219 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4220         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4221                                  tx_vlan, "tx_vlan");
4222 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4223         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4224                                  set, "set");
4225 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4226         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4227                                  pvid, "pvid");
4228 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4229         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4230                              port_id, UINT16);
4231 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4232         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4233                               vlan_id, UINT16);
4234 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4235         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4236                                  mode, "on#off");
4237
4238 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4239         .f = cmd_tx_vlan_set_pvid_parsed,
4240         .data = NULL,
4241         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4242         .tokens = {
4243                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4244                 (void *)&cmd_tx_vlan_set_pvid_set,
4245                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4246                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4247                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4248                 (void *)&cmd_tx_vlan_set_pvid_mode,
4249                 NULL,
4250         },
4251 };
4252
4253 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4254 struct cmd_tx_vlan_reset_result {
4255         cmdline_fixed_string_t tx_vlan;
4256         cmdline_fixed_string_t reset;
4257         portid_t port_id;
4258 };
4259
4260 static void
4261 cmd_tx_vlan_reset_parsed(void *parsed_result,
4262                          __attribute__((unused)) struct cmdline *cl,
4263                          __attribute__((unused)) void *data)
4264 {
4265         struct cmd_tx_vlan_reset_result *res = parsed_result;
4266
4267         if (!port_is_stopped(res->port_id)) {
4268                 printf("Please stop port %d first\n", res->port_id);
4269                 return;
4270         }
4271
4272         tx_vlan_reset(res->port_id);
4273
4274         cmd_reconfig_device_queue(res->port_id, 1, 1);
4275 }
4276
4277 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4278         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4279                                  tx_vlan, "tx_vlan");
4280 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4281         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4282                                  reset, "reset");
4283 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4284         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4285                               port_id, UINT16);
4286
4287 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4288         .f = cmd_tx_vlan_reset_parsed,
4289         .data = NULL,
4290         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4291                 "VLAN header in packets sent on a port",
4292         .tokens = {
4293                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4294                 (void *)&cmd_tx_vlan_reset_reset,
4295                 (void *)&cmd_tx_vlan_reset_portid,
4296                 NULL,
4297         },
4298 };
4299
4300
4301 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4302 struct cmd_csum_result {
4303         cmdline_fixed_string_t csum;
4304         cmdline_fixed_string_t mode;
4305         cmdline_fixed_string_t proto;
4306         cmdline_fixed_string_t hwsw;
4307         portid_t port_id;
4308 };
4309
4310 static void
4311 csum_show(int port_id)
4312 {
4313         struct rte_eth_dev_info dev_info;
4314         uint64_t tx_offloads;
4315
4316         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4317         printf("Parse tunnel is %s\n",
4318                 (ports[port_id].parse_tunnel) ? "on" : "off");
4319         printf("IP checksum offload is %s\n",
4320                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4321         printf("UDP checksum offload is %s\n",
4322                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4323         printf("TCP checksum offload is %s\n",
4324                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4325         printf("SCTP checksum offload is %s\n",
4326                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4327         printf("Outer-Ip checksum offload is %s\n",
4328                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4329         printf("Outer-Udp checksum offload is %s\n",
4330                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4331
4332         /* display warnings if configuration is not supported by the NIC */
4333         rte_eth_dev_info_get(port_id, &dev_info);
4334         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4335                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4336                 printf("Warning: hardware IP checksum enabled but not "
4337                         "supported by port %d\n", port_id);
4338         }
4339         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4340                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4341                 printf("Warning: hardware UDP checksum enabled but not "
4342                         "supported by port %d\n", port_id);
4343         }
4344         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4345                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4346                 printf("Warning: hardware TCP checksum enabled but not "
4347                         "supported by port %d\n", port_id);
4348         }
4349         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4350                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4351                 printf("Warning: hardware SCTP checksum enabled but not "
4352                         "supported by port %d\n", port_id);
4353         }
4354         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4355                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4356                 printf("Warning: hardware outer IP checksum enabled but not "
4357                         "supported by port %d\n", port_id);
4358         }
4359         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4360                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4361                         == 0) {
4362                 printf("Warning: hardware outer UDP checksum enabled but not "
4363                         "supported by port %d\n", port_id);
4364         }
4365 }
4366
4367 static void
4368 cmd_config_queue_tx_offloads(struct rte_port *port)
4369 {
4370         int k;
4371
4372         /* Apply queue tx offloads configuration */
4373         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4374                 port->tx_conf[k].offloads =
4375                         port->dev_conf.txmode.offloads;
4376 }
4377
4378 static void
4379 cmd_csum_parsed(void *parsed_result,
4380                        __attribute__((unused)) struct cmdline *cl,
4381                        __attribute__((unused)) void *data)
4382 {
4383         struct cmd_csum_result *res = parsed_result;
4384         int hw = 0;
4385         uint64_t csum_offloads = 0;
4386         struct rte_eth_dev_info dev_info;
4387
4388         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4389                 printf("invalid port %d\n", res->port_id);
4390                 return;
4391         }
4392         if (!port_is_stopped(res->port_id)) {
4393                 printf("Please stop port %d first\n", res->port_id);
4394                 return;
4395         }
4396
4397         rte_eth_dev_info_get(res->port_id, &dev_info);
4398         if (!strcmp(res->mode, "set")) {
4399
4400                 if (!strcmp(res->hwsw, "hw"))
4401                         hw = 1;
4402
4403                 if (!strcmp(res->proto, "ip")) {
4404                         if (hw == 0 || (dev_info.tx_offload_capa &
4405                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4406                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4407                         } else {
4408                                 printf("IP checksum offload is not supported "
4409                                        "by port %u\n", res->port_id);
4410                         }
4411                 } else if (!strcmp(res->proto, "udp")) {
4412                         if (hw == 0 || (dev_info.tx_offload_capa &
4413                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4414                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4415                         } else {
4416                                 printf("UDP checksum offload is not supported "
4417                                        "by port %u\n", res->port_id);
4418                         }
4419                 } else if (!strcmp(res->proto, "tcp")) {
4420                         if (hw == 0 || (dev_info.tx_offload_capa &
4421                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4422                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4423                         } else {
4424                                 printf("TCP checksum offload is not supported "
4425                                        "by port %u\n", res->port_id);
4426                         }
4427                 } else if (!strcmp(res->proto, "sctp")) {
4428                         if (hw == 0 || (dev_info.tx_offload_capa &
4429                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4430                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4431                         } else {
4432                                 printf("SCTP checksum offload is not supported "
4433                                        "by port %u\n", res->port_id);
4434                         }
4435                 } else if (!strcmp(res->proto, "outer-ip")) {
4436                         if (hw == 0 || (dev_info.tx_offload_capa &
4437                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4438                                 csum_offloads |=
4439                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4440                         } else {
4441                                 printf("Outer IP checksum offload is not "
4442                                        "supported by port %u\n", res->port_id);
4443                         }
4444                 } else if (!strcmp(res->proto, "outer-udp")) {
4445                         if (hw == 0 || (dev_info.tx_offload_capa &
4446                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4447                                 csum_offloads |=
4448                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4449                         } else {
4450                                 printf("Outer UDP checksum offload is not "
4451                                        "supported by port %u\n", res->port_id);
4452                         }
4453                 }
4454
4455                 if (hw) {
4456                         ports[res->port_id].dev_conf.txmode.offloads |=
4457                                                         csum_offloads;
4458                 } else {
4459                         ports[res->port_id].dev_conf.txmode.offloads &=
4460                                                         (~csum_offloads);
4461                 }
4462                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4463         }
4464         csum_show(res->port_id);
4465
4466         cmd_reconfig_device_queue(res->port_id, 1, 1);
4467 }
4468
4469 cmdline_parse_token_string_t cmd_csum_csum =
4470         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4471                                 csum, "csum");
4472 cmdline_parse_token_string_t cmd_csum_mode =
4473         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4474                                 mode, "set");
4475 cmdline_parse_token_string_t cmd_csum_proto =
4476         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4477                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4478 cmdline_parse_token_string_t cmd_csum_hwsw =
4479         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4480                                 hwsw, "hw#sw");
4481 cmdline_parse_token_num_t cmd_csum_portid =
4482         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4483                                 port_id, UINT16);
4484
4485 cmdline_parse_inst_t cmd_csum_set = {
4486         .f = cmd_csum_parsed,
4487         .data = NULL,
4488         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4489                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4490                 "using csum forward engine",
4491         .tokens = {
4492                 (void *)&cmd_csum_csum,
4493                 (void *)&cmd_csum_mode,
4494                 (void *)&cmd_csum_proto,
4495                 (void *)&cmd_csum_hwsw,
4496                 (void *)&cmd_csum_portid,
4497                 NULL,
4498         },
4499 };
4500
4501 cmdline_parse_token_string_t cmd_csum_mode_show =
4502         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4503                                 mode, "show");
4504
4505 cmdline_parse_inst_t cmd_csum_show = {
4506         .f = cmd_csum_parsed,
4507         .data = NULL,
4508         .help_str = "csum show <port_id>: Show checksum offload configuration",
4509         .tokens = {
4510                 (void *)&cmd_csum_csum,
4511                 (void *)&cmd_csum_mode_show,
4512                 (void *)&cmd_csum_portid,
4513                 NULL,
4514         },
4515 };
4516
4517 /* Enable/disable tunnel parsing */
4518 struct cmd_csum_tunnel_result {
4519         cmdline_fixed_string_t csum;
4520         cmdline_fixed_string_t parse;
4521         cmdline_fixed_string_t onoff;
4522         portid_t port_id;
4523 };
4524
4525 static void
4526 cmd_csum_tunnel_parsed(void *parsed_result,
4527                        __attribute__((unused)) struct cmdline *cl,
4528                        __attribute__((unused)) void *data)
4529 {
4530         struct cmd_csum_tunnel_result *res = parsed_result;
4531
4532         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4533                 return;
4534
4535         if (!strcmp(res->onoff, "on"))
4536                 ports[res->port_id].parse_tunnel = 1;
4537         else
4538                 ports[res->port_id].parse_tunnel = 0;
4539
4540         csum_show(res->port_id);
4541 }
4542
4543 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4544         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4545                                 csum, "csum");
4546 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4547         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4548                                 parse, "parse-tunnel");
4549 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4550         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4551                                 onoff, "on#off");
4552 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4553         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4554                                 port_id, UINT16);
4555
4556 cmdline_parse_inst_t cmd_csum_tunnel = {
4557         .f = cmd_csum_tunnel_parsed,
4558         .data = NULL,
4559         .help_str = "csum parse-tunnel on|off <port_id>: "
4560                 "Enable/Disable parsing of tunnels for csum engine",
4561         .tokens = {
4562                 (void *)&cmd_csum_tunnel_csum,
4563                 (void *)&cmd_csum_tunnel_parse,
4564                 (void *)&cmd_csum_tunnel_onoff,
4565                 (void *)&cmd_csum_tunnel_portid,
4566                 NULL,
4567         },
4568 };
4569
4570 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4571 struct cmd_tso_set_result {
4572         cmdline_fixed_string_t tso;
4573         cmdline_fixed_string_t mode;
4574         uint16_t tso_segsz;
4575         portid_t port_id;
4576 };
4577
4578 static void
4579 cmd_tso_set_parsed(void *parsed_result,
4580                        __attribute__((unused)) struct cmdline *cl,
4581                        __attribute__((unused)) void *data)
4582 {
4583         struct cmd_tso_set_result *res = parsed_result;
4584         struct rte_eth_dev_info dev_info;
4585
4586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4587                 return;
4588         if (!port_is_stopped(res->port_id)) {
4589                 printf("Please stop port %d first\n", res->port_id);
4590                 return;
4591         }
4592
4593         if (!strcmp(res->mode, "set"))
4594                 ports[res->port_id].tso_segsz = res->tso_segsz;
4595
4596         rte_eth_dev_info_get(res->port_id, &dev_info);
4597         if ((ports[res->port_id].tso_segsz != 0) &&
4598                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4599                 printf("Error: TSO is not supported by port %d\n",
4600                        res->port_id);
4601                 return;
4602         }
4603
4604         if (ports[res->port_id].tso_segsz == 0) {
4605                 ports[res->port_id].dev_conf.txmode.offloads &=
4606                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4607                 printf("TSO for non-tunneled packets is disabled\n");
4608         } else {
4609                 ports[res->port_id].dev_conf.txmode.offloads |=
4610                                                 DEV_TX_OFFLOAD_TCP_TSO;
4611                 printf("TSO segment size for non-tunneled packets is %d\n",
4612                         ports[res->port_id].tso_segsz);
4613         }
4614         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4615
4616         /* display warnings if configuration is not supported by the NIC */
4617         rte_eth_dev_info_get(res->port_id, &dev_info);
4618         if ((ports[res->port_id].tso_segsz != 0) &&
4619                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4620                 printf("Warning: TSO enabled but not "
4621                         "supported by port %d\n", res->port_id);
4622         }
4623
4624         cmd_reconfig_device_queue(res->port_id, 1, 1);
4625 }
4626
4627 cmdline_parse_token_string_t cmd_tso_set_tso =
4628         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4629                                 tso, "tso");
4630 cmdline_parse_token_string_t cmd_tso_set_mode =
4631         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4632                                 mode, "set");
4633 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4634         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4635                                 tso_segsz, UINT16);
4636 cmdline_parse_token_num_t cmd_tso_set_portid =
4637         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4638                                 port_id, UINT16);
4639
4640 cmdline_parse_inst_t cmd_tso_set = {
4641         .f = cmd_tso_set_parsed,
4642         .data = NULL,
4643         .help_str = "tso set <tso_segsz> <port_id>: "
4644                 "Set TSO segment size of non-tunneled packets for csum engine "
4645                 "(0 to disable)",
4646         .tokens = {
4647                 (void *)&cmd_tso_set_tso,
4648                 (void *)&cmd_tso_set_mode,
4649                 (void *)&cmd_tso_set_tso_segsz,
4650                 (void *)&cmd_tso_set_portid,
4651                 NULL,
4652         },
4653 };
4654
4655 cmdline_parse_token_string_t cmd_tso_show_mode =
4656         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4657                                 mode, "show");
4658
4659
4660 cmdline_parse_inst_t cmd_tso_show = {
4661         .f = cmd_tso_set_parsed,
4662         .data = NULL,
4663         .help_str = "tso show <port_id>: "
4664                 "Show TSO segment size of non-tunneled packets for csum engine",
4665         .tokens = {
4666                 (void *)&cmd_tso_set_tso,
4667                 (void *)&cmd_tso_show_mode,
4668                 (void *)&cmd_tso_set_portid,
4669                 NULL,
4670         },
4671 };
4672
4673 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4674 struct cmd_tunnel_tso_set_result {
4675         cmdline_fixed_string_t tso;
4676         cmdline_fixed_string_t mode;
4677         uint16_t tso_segsz;
4678         portid_t port_id;
4679 };
4680
4681 static struct rte_eth_dev_info
4682 check_tunnel_tso_nic_support(portid_t port_id)
4683 {
4684         struct rte_eth_dev_info dev_info;
4685
4686         rte_eth_dev_info_get(port_id, &dev_info);
4687         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4688                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4689                        "not enabled for port %d\n", port_id);
4690         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4691                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4692                        "not enabled for port %d\n", port_id);
4693         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4694                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4695                        "not enabled for port %d\n", port_id);
4696         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4697                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4698                        "not enabled for port %d\n", port_id);
4699         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4700                 printf("Warning: IP TUNNEL TSO not supported therefore "
4701                        "not enabled for port %d\n", port_id);
4702         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4703                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4704                        "not enabled for port %d\n", port_id);
4705         return dev_info;
4706 }
4707
4708 static void
4709 cmd_tunnel_tso_set_parsed(void *parsed_result,
4710                           __attribute__((unused)) struct cmdline *cl,
4711                           __attribute__((unused)) void *data)
4712 {
4713         struct cmd_tunnel_tso_set_result *res = parsed_result;
4714         struct rte_eth_dev_info dev_info;
4715
4716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4717                 return;
4718         if (!port_is_stopped(res->port_id)) {
4719                 printf("Please stop port %d first\n", res->port_id);
4720                 return;
4721         }
4722
4723         if (!strcmp(res->mode, "set"))
4724                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4725
4726         dev_info = check_tunnel_tso_nic_support(res->port_id);
4727         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4728                 ports[res->port_id].dev_conf.txmode.offloads &=
4729                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4730                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4731                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4732                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4733                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4734                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4735                 printf("TSO for tunneled packets is disabled\n");
4736         } else {
4737                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4738                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4739                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4740                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4741                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4742                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4743
4744                 ports[res->port_id].dev_conf.txmode.offloads |=
4745                         (tso_offloads & dev_info.tx_offload_capa);
4746                 printf("TSO segment size for tunneled packets is %d\n",
4747                         ports[res->port_id].tunnel_tso_segsz);
4748
4749                 /* Below conditions are needed to make it work:
4750                  * (1) tunnel TSO is supported by the NIC;
4751                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4752                  * are recognized;
4753                  * (3) for tunneled pkts with outer L3 of IPv4,
4754                  * "csum set outer-ip" must be set to hw, because after tso,
4755                  * total_len of outer IP header is changed, and the checksum
4756                  * of outer IP header calculated by sw should be wrong; that
4757                  * is not necessary for IPv6 tunneled pkts because there's no
4758                  * checksum in IP header anymore.
4759                  */
4760
4761                 if (!ports[res->port_id].parse_tunnel)
4762                         printf("Warning: csum parse_tunnel must be set "
4763                                 "so that tunneled packets are recognized\n");
4764                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4765                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4766                         printf("Warning: csum set outer-ip must be set to hw "
4767                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4768         }
4769
4770         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4771         cmd_reconfig_device_queue(res->port_id, 1, 1);
4772 }
4773
4774 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4775         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4776                                 tso, "tunnel_tso");
4777 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4778         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4779                                 mode, "set");
4780 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4781         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4782                                 tso_segsz, UINT16);
4783 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4784         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4785                                 port_id, UINT16);
4786
4787 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4788         .f = cmd_tunnel_tso_set_parsed,
4789         .data = NULL,
4790         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4791                 "Set TSO segment size of tunneled packets for csum engine "
4792                 "(0 to disable)",
4793         .tokens = {
4794                 (void *)&cmd_tunnel_tso_set_tso,
4795                 (void *)&cmd_tunnel_tso_set_mode,
4796                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4797                 (void *)&cmd_tunnel_tso_set_portid,
4798                 NULL,
4799         },
4800 };
4801
4802 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4803         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4804                                 mode, "show");
4805
4806
4807 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4808         .f = cmd_tunnel_tso_set_parsed,
4809         .data = NULL,
4810         .help_str = "tunnel_tso show <port_id> "
4811                 "Show TSO segment size of tunneled packets for csum engine",
4812         .tokens = {
4813                 (void *)&cmd_tunnel_tso_set_tso,
4814                 (void *)&cmd_tunnel_tso_show_mode,
4815                 (void *)&cmd_tunnel_tso_set_portid,
4816                 NULL,
4817         },
4818 };
4819
4820 /* *** SET GRO FOR A PORT *** */
4821 struct cmd_gro_enable_result {
4822         cmdline_fixed_string_t cmd_set;
4823         cmdline_fixed_string_t cmd_port;
4824         cmdline_fixed_string_t cmd_keyword;
4825         cmdline_fixed_string_t cmd_onoff;
4826         portid_t cmd_pid;
4827 };
4828
4829 static void
4830 cmd_gro_enable_parsed(void *parsed_result,
4831                 __attribute__((unused)) struct cmdline *cl,
4832                 __attribute__((unused)) void *data)
4833 {
4834         struct cmd_gro_enable_result *res;
4835
4836         res = parsed_result;
4837         if (!strcmp(res->cmd_keyword, "gro"))
4838                 setup_gro(res->cmd_onoff, res->cmd_pid);
4839 }
4840
4841 cmdline_parse_token_string_t cmd_gro_enable_set =
4842         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4843                         cmd_set, "set");
4844 cmdline_parse_token_string_t cmd_gro_enable_port =
4845         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4846                         cmd_keyword, "port");
4847 cmdline_parse_token_num_t cmd_gro_enable_pid =
4848         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4849                         cmd_pid, UINT16);
4850 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4851         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4852                         cmd_keyword, "gro");
4853 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4854         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4855                         cmd_onoff, "on#off");
4856
4857 cmdline_parse_inst_t cmd_gro_enable = {
4858         .f = cmd_gro_enable_parsed,
4859         .data = NULL,
4860         .help_str = "set port <port_id> gro on|off",
4861         .tokens = {
4862                 (void *)&cmd_gro_enable_set,
4863                 (void *)&cmd_gro_enable_port,
4864                 (void *)&cmd_gro_enable_pid,
4865                 (void *)&cmd_gro_enable_keyword,
4866                 (void *)&cmd_gro_enable_onoff,
4867                 NULL,
4868         },
4869 };
4870
4871 /* *** DISPLAY GRO CONFIGURATION *** */
4872 struct cmd_gro_show_result {
4873         cmdline_fixed_string_t cmd_show;
4874         cmdline_fixed_string_t cmd_port;
4875         cmdline_fixed_string_t cmd_keyword;
4876         portid_t cmd_pid;
4877 };
4878
4879 static void
4880 cmd_gro_show_parsed(void *parsed_result,
4881                 __attribute__((unused)) struct cmdline *cl,
4882                 __attribute__((unused)) void *data)
4883 {
4884         struct cmd_gro_show_result *res;
4885
4886         res = parsed_result;
4887         if (!strcmp(res->cmd_keyword, "gro"))
4888                 show_gro(res->cmd_pid);
4889 }
4890
4891 cmdline_parse_token_string_t cmd_gro_show_show =
4892         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4893                         cmd_show, "show");
4894 cmdline_parse_token_string_t cmd_gro_show_port =
4895         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4896                         cmd_port, "port");
4897 cmdline_parse_token_num_t cmd_gro_show_pid =
4898         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4899                         cmd_pid, UINT16);
4900 cmdline_parse_token_string_t cmd_gro_show_keyword =
4901         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4902                         cmd_keyword, "gro");
4903
4904 cmdline_parse_inst_t cmd_gro_show = {
4905         .f = cmd_gro_show_parsed,
4906         .data = NULL,
4907         .help_str = "show port <port_id> gro",
4908         .tokens = {
4909                 (void *)&cmd_gro_show_show,
4910                 (void *)&cmd_gro_show_port,
4911                 (void *)&cmd_gro_show_pid,
4912                 (void *)&cmd_gro_show_keyword,
4913                 NULL,
4914         },
4915 };
4916
4917 /* *** SET FLUSH CYCLES FOR GRO *** */
4918 struct cmd_gro_flush_result {
4919         cmdline_fixed_string_t cmd_set;
4920         cmdline_fixed_string_t cmd_keyword;
4921         cmdline_fixed_string_t cmd_flush;
4922         uint8_t cmd_cycles;
4923 };
4924
4925 static void
4926 cmd_gro_flush_parsed(void *parsed_result,
4927                 __attribute__((unused)) struct cmdline *cl,
4928                 __attribute__((unused)) void *data)
4929 {
4930         struct cmd_gro_flush_result *res;
4931
4932         res = parsed_result;
4933         if ((!strcmp(res->cmd_keyword, "gro")) &&
4934                         (!strcmp(res->cmd_flush, "flush")))
4935                 setup_gro_flush_cycles(res->cmd_cycles);
4936 }
4937
4938 cmdline_parse_token_string_t cmd_gro_flush_set =
4939         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4940                         cmd_set, "set");
4941 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4942         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4943                         cmd_keyword, "gro");
4944 cmdline_parse_token_string_t cmd_gro_flush_flush =
4945         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4946                         cmd_flush, "flush");
4947 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4948         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4949                         cmd_cycles, UINT8);
4950
4951 cmdline_parse_inst_t cmd_gro_flush = {
4952         .f = cmd_gro_flush_parsed,
4953         .data = NULL,
4954         .help_str = "set gro flush <cycles>",
4955         .tokens = {
4956                 (void *)&cmd_gro_flush_set,
4957                 (void *)&cmd_gro_flush_keyword,
4958                 (void *)&cmd_gro_flush_flush,
4959                 (void *)&cmd_gro_flush_cycles,
4960                 NULL,
4961         },
4962 };
4963
4964 /* *** ENABLE/DISABLE GSO *** */
4965 struct cmd_gso_enable_result {
4966         cmdline_fixed_string_t cmd_set;
4967         cmdline_fixed_string_t cmd_port;
4968         cmdline_fixed_string_t cmd_keyword;
4969         cmdline_fixed_string_t cmd_mode;
4970         portid_t cmd_pid;
4971 };
4972
4973 static void
4974 cmd_gso_enable_parsed(void *parsed_result,
4975                 __attribute__((unused)) struct cmdline *cl,
4976                 __attribute__((unused)) void *data)
4977 {
4978         struct cmd_gso_enable_result *res;
4979
4980         res = parsed_result;
4981         if (!strcmp(res->cmd_keyword, "gso"))
4982                 setup_gso(res->cmd_mode, res->cmd_pid);
4983 }
4984
4985 cmdline_parse_token_string_t cmd_gso_enable_set =
4986         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4987                         cmd_set, "set");
4988 cmdline_parse_token_string_t cmd_gso_enable_port =
4989         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4990                         cmd_port, "port");
4991 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4992         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4993                         cmd_keyword, "gso");
4994 cmdline_parse_token_string_t cmd_gso_enable_mode =
4995         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4996                         cmd_mode, "on#off");
4997 cmdline_parse_token_num_t cmd_gso_enable_pid =
4998         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4999                         cmd_pid, UINT16);
5000
5001 cmdline_parse_inst_t cmd_gso_enable = {
5002         .f = cmd_gso_enable_parsed,
5003         .data = NULL,
5004         .help_str = "set port <port_id> gso on|off",
5005         .tokens = {
5006                 (void *)&cmd_gso_enable_set,
5007                 (void *)&cmd_gso_enable_port,
5008                 (void *)&cmd_gso_enable_pid,
5009                 (void *)&cmd_gso_enable_keyword,
5010                 (void *)&cmd_gso_enable_mode,
5011                 NULL,
5012         },
5013 };
5014
5015 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5016 struct cmd_gso_size_result {
5017         cmdline_fixed_string_t cmd_set;
5018         cmdline_fixed_string_t cmd_keyword;
5019         cmdline_fixed_string_t cmd_segsz;
5020         uint16_t cmd_size;
5021 };
5022
5023 static void
5024 cmd_gso_size_parsed(void *parsed_result,
5025                        __attribute__((unused)) struct cmdline *cl,
5026                        __attribute__((unused)) void *data)
5027 {
5028         struct cmd_gso_size_result *res = parsed_result;
5029
5030         if (test_done == 0) {
5031                 printf("Before setting GSO segsz, please first"
5032                                 " stop fowarding\n");
5033                 return;
5034         }
5035
5036         if (!strcmp(res->cmd_keyword, "gso") &&
5037                         !strcmp(res->cmd_segsz, "segsz")) {
5038                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5039                         printf("gso_size should be larger than %zu."
5040                                         " Please input a legal value\n",
5041                                         RTE_GSO_SEG_SIZE_MIN);
5042                 else
5043                         gso_max_segment_size = res->cmd_size;
5044         }
5045 }
5046
5047 cmdline_parse_token_string_t cmd_gso_size_set =
5048         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5049                                 cmd_set, "set");
5050 cmdline_parse_token_string_t cmd_gso_size_keyword =
5051         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5052                                 cmd_keyword, "gso");
5053 cmdline_parse_token_string_t cmd_gso_size_segsz =
5054         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5055                                 cmd_segsz, "segsz");
5056 cmdline_parse_token_num_t cmd_gso_size_size =
5057         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5058                                 cmd_size, UINT16);
5059
5060 cmdline_parse_inst_t cmd_gso_size = {
5061         .f = cmd_gso_size_parsed,
5062         .data = NULL,
5063         .help_str = "set gso segsz <length>",
5064         .tokens = {
5065                 (void *)&cmd_gso_size_set,
5066                 (void *)&cmd_gso_size_keyword,
5067                 (void *)&cmd_gso_size_segsz,
5068                 (void *)&cmd_gso_size_size,
5069                 NULL,
5070         },
5071 };
5072
5073 /* *** SHOW GSO CONFIGURATION *** */
5074 struct cmd_gso_show_result {
5075         cmdline_fixed_string_t cmd_show;
5076         cmdline_fixed_string_t cmd_port;
5077         cmdline_fixed_string_t cmd_keyword;
5078         portid_t cmd_pid;
5079 };
5080
5081 static void
5082 cmd_gso_show_parsed(void *parsed_result,
5083                        __attribute__((unused)) struct cmdline *cl,
5084                        __attribute__((unused)) void *data)
5085 {
5086         struct cmd_gso_show_result *res = parsed_result;
5087
5088         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5089                 printf("invalid port id %u\n", res->cmd_pid);
5090                 return;
5091         }
5092         if (!strcmp(res->cmd_keyword, "gso")) {
5093                 if (gso_ports[res->cmd_pid].enable) {
5094                         printf("Max GSO'd packet size: %uB\n"
5095                                         "Supported GSO types: TCP/IPv4, "
5096                                         "UDP/IPv4, VxLAN with inner "
5097                                         "TCP/IPv4 packet, GRE with inner "
5098                                         "TCP/IPv4 packet\n",
5099                                         gso_max_segment_size);
5100                 } else
5101                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5102         }
5103 }
5104
5105 cmdline_parse_token_string_t cmd_gso_show_show =
5106 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5107                 cmd_show, "show");
5108 cmdline_parse_token_string_t cmd_gso_show_port =
5109 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5110                 cmd_port, "port");
5111 cmdline_parse_token_string_t cmd_gso_show_keyword =
5112         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5113                                 cmd_keyword, "gso");
5114 cmdline_parse_token_num_t cmd_gso_show_pid =
5115         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5116                                 cmd_pid, UINT16);
5117
5118 cmdline_parse_inst_t cmd_gso_show = {
5119         .f = cmd_gso_show_parsed,
5120         .data = NULL,
5121         .help_str = "show port <port_id> gso",
5122         .tokens = {
5123                 (void *)&cmd_gso_show_show,
5124                 (void *)&cmd_gso_show_port,
5125                 (void *)&cmd_gso_show_pid,
5126                 (void *)&cmd_gso_show_keyword,
5127                 NULL,
5128         },
5129 };
5130
5131 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5132 struct cmd_set_flush_rx {
5133         cmdline_fixed_string_t set;
5134         cmdline_fixed_string_t flush_rx;
5135         cmdline_fixed_string_t mode;
5136 };
5137
5138 static void
5139 cmd_set_flush_rx_parsed(void *parsed_result,
5140                 __attribute__((unused)) struct cmdline *cl,
5141                 __attribute__((unused)) void *data)
5142 {
5143         struct cmd_set_flush_rx *res = parsed_result;
5144         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5145 }
5146
5147 cmdline_parse_token_string_t cmd_setflushrx_set =
5148         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5149                         set, "set");
5150 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5151         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5152                         flush_rx, "flush_rx");
5153 cmdline_parse_token_string_t cmd_setflushrx_mode =
5154         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5155                         mode, "on#off");
5156
5157
5158 cmdline_parse_inst_t cmd_set_flush_rx = {
5159         .f = cmd_set_flush_rx_parsed,
5160         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5161         .data = NULL,
5162         .tokens = {
5163                 (void *)&cmd_setflushrx_set,
5164                 (void *)&cmd_setflushrx_flush_rx,
5165                 (void *)&cmd_setflushrx_mode,
5166                 NULL,
5167         },
5168 };
5169
5170 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5171 struct cmd_set_link_check {
5172         cmdline_fixed_string_t set;
5173         cmdline_fixed_string_t link_check;
5174         cmdline_fixed_string_t mode;
5175 };
5176
5177 static void
5178 cmd_set_link_check_parsed(void *parsed_result,
5179                 __attribute__((unused)) struct cmdline *cl,
5180                 __attribute__((unused)) void *data)
5181 {
5182         struct cmd_set_link_check *res = parsed_result;
5183         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5184 }
5185
5186 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5187         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5188                         set, "set");
5189 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5190         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5191                         link_check, "link_check");
5192 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5193         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5194                         mode, "on#off");
5195
5196
5197 cmdline_parse_inst_t cmd_set_link_check = {
5198         .f = cmd_set_link_check_parsed,
5199         .help_str = "set link_check on|off: Enable/Disable link status check "
5200                     "when starting/stopping a port",
5201         .data = NULL,
5202         .tokens = {
5203                 (void *)&cmd_setlinkcheck_set,
5204                 (void *)&cmd_setlinkcheck_link_check,
5205                 (void *)&cmd_setlinkcheck_mode,
5206                 NULL,
5207         },
5208 };
5209
5210 /* *** SET NIC BYPASS MODE *** */
5211 struct cmd_set_bypass_mode_result {
5212         cmdline_fixed_string_t set;
5213         cmdline_fixed_string_t bypass;
5214         cmdline_fixed_string_t mode;
5215         cmdline_fixed_string_t value;
5216         portid_t port_id;
5217 };
5218
5219 static void
5220 cmd_set_bypass_mode_parsed(void *parsed_result,
5221                 __attribute__((unused)) struct cmdline *cl,
5222                 __attribute__((unused)) void *data)
5223 {
5224         struct cmd_set_bypass_mode_result *res = parsed_result;
5225         portid_t port_id = res->port_id;
5226         int32_t rc = -EINVAL;
5227
5228 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5229         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5230
5231         if (!strcmp(res->value, "bypass"))
5232                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5233         else if (!strcmp(res->value, "isolate"))
5234                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5235         else
5236                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5237
5238         /* Set the bypass mode for the relevant port. */
5239         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5240 #endif
5241         if (rc != 0)
5242                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5243 }
5244
5245 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5246         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5247                         set, "set");
5248 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5249         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5250                         bypass, "bypass");
5251 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5252         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5253                         mode, "mode");
5254 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5255         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5256                         value, "normal#bypass#isolate");
5257 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5258         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5259                                 port_id, UINT16);
5260
5261 cmdline_parse_inst_t cmd_set_bypass_mode = {
5262         .f = cmd_set_bypass_mode_parsed,
5263         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5264                     "Set the NIC bypass mode for port_id",
5265         .data = NULL,
5266         .tokens = {
5267                 (void *)&cmd_setbypass_mode_set,
5268                 (void *)&cmd_setbypass_mode_bypass,
5269                 (void *)&cmd_setbypass_mode_mode,
5270                 (void *)&cmd_setbypass_mode_value,
5271                 (void *)&cmd_setbypass_mode_port,
5272                 NULL,
5273         },
5274 };
5275
5276 /* *** SET NIC BYPASS EVENT *** */
5277 struct cmd_set_bypass_event_result {
5278         cmdline_fixed_string_t set;
5279         cmdline_fixed_string_t bypass;
5280         cmdline_fixed_string_t event;
5281         cmdline_fixed_string_t event_value;
5282         cmdline_fixed_string_t mode;
5283         cmdline_fixed_string_t mode_value;
5284         portid_t port_id;
5285 };
5286
5287 static void
5288 cmd_set_bypass_event_parsed(void *parsed_result,
5289                 __attribute__((unused)) struct cmdline *cl,
5290                 __attribute__((unused)) void *data)
5291 {
5292         int32_t rc = -EINVAL;
5293         struct cmd_set_bypass_event_result *res = parsed_result;
5294         portid_t port_id = res->port_id;
5295
5296 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5297         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5298         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5299
5300         if (!strcmp(res->event_value, "timeout"))
5301                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5302         else if (!strcmp(res->event_value, "os_on"))
5303                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5304         else if (!strcmp(res->event_value, "os_off"))
5305                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5306         else if (!strcmp(res->event_value, "power_on"))
5307                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5308         else if (!strcmp(res->event_value, "power_off"))
5309                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5310         else
5311                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5312
5313         if (!strcmp(res->mode_value, "bypass"))
5314                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5315         else if (!strcmp(res->mode_value, "isolate"))
5316                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5317         else
5318                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5319
5320         /* Set the watchdog timeout. */
5321         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5322
5323                 rc = -EINVAL;
5324                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5325                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5326                                                            bypass_timeout);
5327                 }
5328                 if (rc != 0) {
5329                         printf("Failed to set timeout value %u "
5330                         "for port %d, errto code: %d.\n",
5331                         bypass_timeout, port_id, rc);
5332                 }
5333         }
5334
5335         /* Set the bypass event to transition to bypass mode. */
5336         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5337                                               bypass_mode);
5338 #endif
5339
5340         if (rc != 0)
5341                 printf("\t Failed to set bypass event for port = %d.\n",
5342                        port_id);
5343 }
5344
5345 cmdline_parse_token_string_t cmd_setbypass_event_set =
5346         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5347                         set, "set");
5348 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5349         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5350                         bypass, "bypass");
5351 cmdline_parse_token_string_t cmd_setbypass_event_event =
5352         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5353                         event, "event");
5354 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5355         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5356                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5357 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5358         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5359                         mode, "mode");
5360 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5361         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5362                         mode_value, "normal#bypass#isolate");
5363 cmdline_parse_token_num_t cmd_setbypass_event_port =
5364         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5365                                 port_id, UINT16);
5366
5367 cmdline_parse_inst_t cmd_set_bypass_event = {
5368         .f = cmd_set_bypass_event_parsed,
5369         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5370                 "power_off mode normal|bypass|isolate <port_id>: "
5371                 "Set the NIC bypass event mode for port_id",
5372         .data = NULL,
5373         .tokens = {
5374                 (void *)&cmd_setbypass_event_set,
5375                 (void *)&cmd_setbypass_event_bypass,
5376                 (void *)&cmd_setbypass_event_event,
5377                 (void *)&cmd_setbypass_event_event_value,
5378                 (void *)&cmd_setbypass_event_mode,
5379                 (void *)&cmd_setbypass_event_mode_value,
5380                 (void *)&cmd_setbypass_event_port,
5381                 NULL,
5382         },
5383 };
5384
5385
5386 /* *** SET NIC BYPASS TIMEOUT *** */
5387 struct cmd_set_bypass_timeout_result {
5388         cmdline_fixed_string_t set;
5389         cmdline_fixed_string_t bypass;
5390         cmdline_fixed_string_t timeout;
5391         cmdline_fixed_string_t value;
5392 };
5393
5394 static void
5395 cmd_set_bypass_timeout_parsed(void *parsed_result,
5396                 __attribute__((unused)) struct cmdline *cl,
5397                 __attribute__((unused)) void *data)
5398 {
5399         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5400
5401 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5402         if (!strcmp(res->value, "1.5"))
5403                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5404         else if (!strcmp(res->value, "2"))
5405                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5406         else if (!strcmp(res->value, "3"))
5407                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5408         else if (!strcmp(res->value, "4"))
5409                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5410         else if (!strcmp(res->value, "8"))
5411                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5412         else if (!strcmp(res->value, "16"))
5413                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5414         else if (!strcmp(res->value, "32"))
5415                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5416         else
5417                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5418 #endif
5419 }
5420
5421 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5422         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5423                         set, "set");
5424 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5425         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5426                         bypass, "bypass");
5427 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5428         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5429                         timeout, "timeout");
5430 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5431         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5432                         value, "0#1.5#2#3#4#8#16#32");
5433
5434 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5435         .f = cmd_set_bypass_timeout_parsed,
5436         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5437                 "Set the NIC bypass watchdog timeout in seconds",
5438         .data = NULL,
5439         .tokens = {
5440                 (void *)&cmd_setbypass_timeout_set,
5441                 (void *)&cmd_setbypass_timeout_bypass,
5442                 (void *)&cmd_setbypass_timeout_timeout,
5443                 (void *)&cmd_setbypass_timeout_value,
5444                 NULL,
5445         },
5446 };
5447
5448 /* *** SHOW NIC BYPASS MODE *** */
5449 struct cmd_show_bypass_config_result {
5450         cmdline_fixed_string_t show;
5451         cmdline_fixed_string_t bypass;
5452         cmdline_fixed_string_t config;
5453         portid_t port_id;
5454 };
5455
5456 static void
5457 cmd_show_bypass_config_parsed(void *parsed_result,
5458                 __attribute__((unused)) struct cmdline *cl,
5459                 __attribute__((unused)) void *data)
5460 {
5461         struct cmd_show_bypass_config_result *res = parsed_result;
5462         portid_t port_id = res->port_id;
5463         int rc = -EINVAL;
5464 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5465         uint32_t event_mode;
5466         uint32_t bypass_mode;
5467         uint32_t timeout = bypass_timeout;
5468         int i;
5469
5470         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5471                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5472         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5473                 {"UNKNOWN", "normal", "bypass", "isolate"};
5474         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5475                 "NONE",
5476                 "OS/board on",
5477                 "power supply on",
5478                 "OS/board off",
5479                 "power supply off",
5480                 "timeout"};
5481         int num_events = (sizeof events) / (sizeof events[0]);
5482
5483         /* Display the bypass mode.*/
5484         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5485                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5486                 return;
5487         }
5488         else {
5489                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5490                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5491
5492                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5493         }
5494
5495         /* Display the bypass timeout.*/
5496         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5497                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5498
5499         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5500
5501         /* Display the bypass events and associated modes. */
5502         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
5503
5504                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5505                         printf("\tFailed to get bypass mode for event = %s\n",
5506                                 events[i]);
5507                 } else {
5508                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5509                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5510
5511                         printf("\tbypass event: %-16s = %s\n", events[i],
5512                                 modes[event_mode]);
5513                 }
5514         }
5515 #endif
5516         if (rc != 0)
5517                 printf("\tFailed to get bypass configuration for port = %d\n",
5518                        port_id);
5519 }
5520
5521 cmdline_parse_token_string_t cmd_showbypass_config_show =
5522         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5523                         show, "show");
5524 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5525         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5526                         bypass, "bypass");
5527 cmdline_parse_token_string_t cmd_showbypass_config_config =
5528         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5529                         config, "config");
5530 cmdline_parse_token_num_t cmd_showbypass_config_port =
5531         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5532                                 port_id, UINT16);
5533
5534 cmdline_parse_inst_t cmd_show_bypass_config = {
5535         .f = cmd_show_bypass_config_parsed,
5536         .help_str = "show bypass config <port_id>: "
5537                     "Show the NIC bypass config for port_id",
5538         .data = NULL,
5539         .tokens = {
5540                 (void *)&cmd_showbypass_config_show,
5541                 (void *)&cmd_showbypass_config_bypass,
5542                 (void *)&cmd_showbypass_config_config,
5543                 (void *)&cmd_showbypass_config_port,
5544                 NULL,
5545         },
5546 };
5547
5548 #ifdef RTE_LIBRTE_PMD_BOND
5549 /* *** SET BONDING MODE *** */
5550 struct cmd_set_bonding_mode_result {
5551         cmdline_fixed_string_t set;
5552         cmdline_fixed_string_t bonding;
5553         cmdline_fixed_string_t mode;
5554         uint8_t value;
5555         portid_t port_id;
5556 };
5557
5558 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5559                 __attribute__((unused))  struct cmdline *cl,
5560                 __attribute__((unused)) void *data)
5561 {
5562         struct cmd_set_bonding_mode_result *res = parsed_result;
5563         portid_t port_id = res->port_id;
5564
5565         /* Set the bonding mode for the relevant port. */
5566         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5567                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5568 }
5569
5570 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5571 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5572                 set, "set");
5573 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5574 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5575                 bonding, "bonding");
5576 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5577 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5578                 mode, "mode");
5579 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5580 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5581                 value, UINT8);
5582 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5583 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5584                 port_id, UINT16);
5585
5586 cmdline_parse_inst_t cmd_set_bonding_mode = {
5587                 .f = cmd_set_bonding_mode_parsed,
5588                 .help_str = "set bonding mode <mode_value> <port_id>: "
5589                         "Set the bonding mode for port_id",
5590                 .data = NULL,
5591                 .tokens = {
5592                                 (void *) &cmd_setbonding_mode_set,
5593                                 (void *) &cmd_setbonding_mode_bonding,
5594                                 (void *) &cmd_setbonding_mode_mode,
5595                                 (void *) &cmd_setbonding_mode_value,
5596                                 (void *) &cmd_setbonding_mode_port,
5597                                 NULL
5598                 }
5599 };
5600
5601 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5602 struct cmd_set_bonding_lacp_dedicated_queues_result {
5603         cmdline_fixed_string_t set;
5604         cmdline_fixed_string_t bonding;
5605         cmdline_fixed_string_t lacp;
5606         cmdline_fixed_string_t dedicated_queues;
5607         portid_t port_id;
5608         cmdline_fixed_string_t mode;
5609 };
5610
5611 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5612                 __attribute__((unused))  struct cmdline *cl,
5613                 __attribute__((unused)) void *data)
5614 {
5615         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5616         portid_t port_id = res->port_id;
5617         struct rte_port *port;
5618
5619         port = &ports[port_id];
5620
5621         /** Check if the port is not started **/
5622         if (port->port_status != RTE_PORT_STOPPED) {
5623                 printf("Please stop port %d first\n", port_id);
5624                 return;
5625         }
5626
5627         if (!strcmp(res->mode, "enable")) {
5628                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5629                         printf("Dedicate queues for LACP control packets"
5630                                         " enabled\n");
5631                 else
5632                         printf("Enabling dedicate queues for LACP control "
5633                                         "packets on port %d failed\n", port_id);
5634         } else if (!strcmp(res->mode, "disable")) {
5635                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5636                         printf("Dedicated queues for LACP control packets "
5637                                         "disabled\n");
5638                 else
5639                         printf("Disabling dedicated queues for LACP control "
5640                                         "traffic on port %d failed\n", port_id);
5641         }
5642 }
5643
5644 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5645 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5646                 set, "set");
5647 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5648 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5649                 bonding, "bonding");
5650 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5651 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5652                 lacp, "lacp");
5653 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5654 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5655                 dedicated_queues, "dedicated_queues");
5656 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5657 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5658                 port_id, UINT16);
5659 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5660 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5661                 mode, "enable#disable");
5662
5663 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5664                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5665                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5666                         "enable|disable: "
5667                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5668                 .data = NULL,
5669                 .tokens = {
5670                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5671                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5672                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5673                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5674                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5675                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5676                         NULL
5677                 }
5678 };
5679
5680 /* *** SET BALANCE XMIT POLICY *** */
5681 struct cmd_set_bonding_balance_xmit_policy_result {
5682         cmdline_fixed_string_t set;
5683         cmdline_fixed_string_t bonding;
5684         cmdline_fixed_string_t balance_xmit_policy;
5685         portid_t port_id;
5686         cmdline_fixed_string_t policy;
5687 };
5688
5689 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5690                 __attribute__((unused))  struct cmdline *cl,
5691                 __attribute__((unused)) void *data)
5692 {
5693         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5694         portid_t port_id = res->port_id;
5695         uint8_t policy;
5696
5697         if (!strcmp(res->policy, "l2")) {
5698                 policy = BALANCE_XMIT_POLICY_LAYER2;
5699         } else if (!strcmp(res->policy, "l23")) {
5700                 policy = BALANCE_XMIT_POLICY_LAYER23;
5701         } else if (!strcmp(res->policy, "l34")) {
5702                 policy = BALANCE_XMIT_POLICY_LAYER34;
5703         } else {
5704                 printf("\t Invalid xmit policy selection");
5705                 return;
5706         }
5707
5708         /* Set the bonding mode for the relevant port. */
5709         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5710                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5711                                 port_id);
5712         }
5713 }
5714
5715 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5716 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5717                 set, "set");
5718 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5719 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5720                 bonding, "bonding");
5721 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5722 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5723                 balance_xmit_policy, "balance_xmit_policy");
5724 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5725 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5726                 port_id, UINT16);
5727 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5728 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5729                 policy, "l2#l23#l34");
5730
5731 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5732                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5733                 .help_str = "set bonding balance_xmit_policy <port_id> "
5734                         "l2|l23|l34: "
5735                         "Set the bonding balance_xmit_policy for port_id",
5736                 .data = NULL,
5737                 .tokens = {
5738                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5739                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5740                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5741                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5742                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5743                                 NULL
5744                 }
5745 };
5746
5747 /* *** SHOW NIC BONDING CONFIGURATION *** */
5748 struct cmd_show_bonding_config_result {
5749         cmdline_fixed_string_t show;
5750         cmdline_fixed_string_t bonding;
5751         cmdline_fixed_string_t config;
5752         portid_t port_id;
5753 };
5754
5755 static void cmd_show_bonding_config_parsed(void *parsed_result,
5756                 __attribute__((unused))  struct cmdline *cl,
5757                 __attribute__((unused)) void *data)
5758 {
5759         struct cmd_show_bonding_config_result *res = parsed_result;
5760         int bonding_mode, agg_mode;
5761         portid_t slaves[RTE_MAX_ETHPORTS];
5762         int num_slaves, num_active_slaves;
5763         int primary_id;
5764         int i;
5765         portid_t port_id = res->port_id;
5766
5767         /* Display the bonding mode.*/
5768         bonding_mode = rte_eth_bond_mode_get(port_id);
5769         if (bonding_mode < 0) {
5770                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5771                 return;
5772         } else
5773                 printf("\tBonding mode: %d\n", bonding_mode);
5774
5775         if (bonding_mode == BONDING_MODE_BALANCE) {
5776                 int balance_xmit_policy;
5777
5778                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5779                 if (balance_xmit_policy < 0) {
5780                         printf("\tFailed to get balance xmit policy for port = %d\n",
5781                                         port_id);
5782                         return;
5783                 } else {
5784                         printf("\tBalance Xmit Policy: ");
5785
5786                         switch (balance_xmit_policy) {
5787                         case BALANCE_XMIT_POLICY_LAYER2:
5788                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5789                                 break;
5790                         case BALANCE_XMIT_POLICY_LAYER23:
5791                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5792                                 break;
5793                         case BALANCE_XMIT_POLICY_LAYER34:
5794                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5795                                 break;
5796                         }
5797                         printf("\n");
5798                 }
5799         }
5800
5801         if (bonding_mode == BONDING_MODE_8023AD) {
5802                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5803                 printf("\tIEEE802.3AD Aggregator Mode: ");
5804                 switch (agg_mode) {
5805                 case AGG_BANDWIDTH:
5806                         printf("bandwidth");
5807                         break;
5808                 case AGG_STABLE:
5809                         printf("stable");
5810                         break;
5811                 case AGG_COUNT:
5812                         printf("count");
5813                         break;
5814                 }
5815                 printf("\n");
5816         }
5817
5818         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5819
5820         if (num_slaves < 0) {
5821                 printf("\tFailed to get slave list for port = %d\n", port_id);
5822                 return;
5823         }
5824         if (num_slaves > 0) {
5825                 printf("\tSlaves (%d): [", num_slaves);
5826                 for (i = 0; i < num_slaves - 1; i++)
5827                         printf("%d ", slaves[i]);
5828
5829                 printf("%d]\n", slaves[num_slaves - 1]);
5830         } else {
5831                 printf("\tSlaves: []\n");
5832
5833         }
5834
5835         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5836                         RTE_MAX_ETHPORTS);
5837
5838         if (num_active_slaves < 0) {
5839                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5840                 return;
5841         }
5842         if (num_active_slaves > 0) {
5843                 printf("\tActive Slaves (%d): [", num_active_slaves);
5844                 for (i = 0; i < num_active_slaves - 1; i++)
5845                         printf("%d ", slaves[i]);
5846
5847                 printf("%d]\n", slaves[num_active_slaves - 1]);
5848
5849         } else {
5850                 printf("\tActive Slaves: []\n");
5851
5852         }
5853
5854         primary_id = rte_eth_bond_primary_get(port_id);
5855         if (primary_id < 0) {
5856                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5857                 return;
5858         } else
5859                 printf("\tPrimary: [%d]\n", primary_id);
5860
5861 }
5862
5863 cmdline_parse_token_string_t cmd_showbonding_config_show =
5864 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5865                 show, "show");
5866 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5867 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5868                 bonding, "bonding");
5869 cmdline_parse_token_string_t cmd_showbonding_config_config =
5870 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5871                 config, "config");
5872 cmdline_parse_token_num_t cmd_showbonding_config_port =
5873 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5874                 port_id, UINT16);
5875
5876 cmdline_parse_inst_t cmd_show_bonding_config = {
5877                 .f = cmd_show_bonding_config_parsed,
5878                 .help_str = "show bonding config <port_id>: "
5879                         "Show the bonding config for port_id",
5880                 .data = NULL,
5881                 .tokens = {
5882                                 (void *)&cmd_showbonding_config_show,
5883                                 (void *)&cmd_showbonding_config_bonding,
5884                                 (void *)&cmd_showbonding_config_config,
5885                                 (void *)&cmd_showbonding_config_port,
5886                                 NULL
5887                 }
5888 };
5889
5890 /* *** SET BONDING PRIMARY *** */
5891 struct cmd_set_bonding_primary_result {
5892         cmdline_fixed_string_t set;
5893         cmdline_fixed_string_t bonding;
5894         cmdline_fixed_string_t primary;
5895         portid_t slave_id;
5896         portid_t port_id;
5897 };
5898
5899 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5900                 __attribute__((unused))  struct cmdline *cl,
5901                 __attribute__((unused)) void *data)
5902 {
5903         struct cmd_set_bonding_primary_result *res = parsed_result;
5904         portid_t master_port_id = res->port_id;
5905         portid_t slave_port_id = res->slave_id;
5906
5907         /* Set the primary slave for a bonded device. */
5908         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5909                 printf("\t Failed to set primary slave for port = %d.\n",
5910                                 master_port_id);
5911                 return;
5912         }
5913         init_port_config();
5914 }
5915
5916 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5917 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5918                 set, "set");
5919 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5921                 bonding, "bonding");
5922 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5923 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5924                 primary, "primary");
5925 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5926 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5927                 slave_id, UINT16);
5928 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5929 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5930                 port_id, UINT16);
5931
5932 cmdline_parse_inst_t cmd_set_bonding_primary = {
5933                 .f = cmd_set_bonding_primary_parsed,
5934                 .help_str = "set bonding primary <slave_id> <port_id>: "
5935                         "Set the primary slave for port_id",
5936                 .data = NULL,
5937                 .tokens = {
5938                                 (void *)&cmd_setbonding_primary_set,
5939                                 (void *)&cmd_setbonding_primary_bonding,
5940                                 (void *)&cmd_setbonding_primary_primary,
5941                                 (void *)&cmd_setbonding_primary_slave,
5942                                 (void *)&cmd_setbonding_primary_port,
5943                                 NULL
5944                 }
5945 };
5946
5947 /* *** ADD SLAVE *** */
5948 struct cmd_add_bonding_slave_result {
5949         cmdline_fixed_string_t add;
5950         cmdline_fixed_string_t bonding;
5951         cmdline_fixed_string_t slave;
5952         portid_t slave_id;
5953         portid_t port_id;
5954 };
5955
5956 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5957                 __attribute__((unused))  struct cmdline *cl,
5958                 __attribute__((unused)) void *data)
5959 {
5960         struct cmd_add_bonding_slave_result *res = parsed_result;
5961         portid_t master_port_id = res->port_id;
5962         portid_t slave_port_id = res->slave_id;
5963
5964         /* add the slave for a bonded device. */
5965         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5966                 printf("\t Failed to add slave %d to master port = %d.\n",
5967                                 slave_port_id, master_port_id);
5968                 return;
5969         }
5970         init_port_config();
5971         set_port_slave_flag(slave_port_id);
5972 }
5973
5974 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5975 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5976                 add, "add");
5977 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5978 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5979                 bonding, "bonding");
5980 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5981 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5982                 slave, "slave");
5983 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5984 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5985                 slave_id, UINT16);
5986 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5987 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5988                 port_id, UINT16);
5989
5990 cmdline_parse_inst_t cmd_add_bonding_slave = {
5991                 .f = cmd_add_bonding_slave_parsed,
5992                 .help_str = "add bonding slave <slave_id> <port_id>: "
5993                         "Add a slave device to a bonded device",
5994                 .data = NULL,
5995                 .tokens = {
5996                                 (void *)&cmd_addbonding_slave_add,
5997                                 (void *)&cmd_addbonding_slave_bonding,
5998                                 (void *)&cmd_addbonding_slave_slave,
5999                                 (void *)&cmd_addbonding_slave_slaveid,
6000                                 (void *)&cmd_addbonding_slave_port,
6001                                 NULL
6002                 }
6003 };
6004
6005 /* *** REMOVE SLAVE *** */
6006 struct cmd_remove_bonding_slave_result {
6007         cmdline_fixed_string_t remove;
6008         cmdline_fixed_string_t bonding;
6009         cmdline_fixed_string_t slave;
6010         portid_t slave_id;
6011         portid_t port_id;
6012 };
6013
6014 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6015                 __attribute__((unused))  struct cmdline *cl,
6016                 __attribute__((unused)) void *data)
6017 {
6018         struct cmd_remove_bonding_slave_result *res = parsed_result;
6019         portid_t master_port_id = res->port_id;
6020         portid_t slave_port_id = res->slave_id;
6021
6022         /* remove the slave from a bonded device. */
6023         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6024                 printf("\t Failed to remove slave %d from master port = %d.\n",
6025                                 slave_port_id, master_port_id);
6026                 return;
6027         }
6028         init_port_config();
6029         clear_port_slave_flag(slave_port_id);
6030 }
6031
6032 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6033                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6034                                 remove, "remove");
6035 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6036                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6037                                 bonding, "bonding");
6038 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6039                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6040                                 slave, "slave");
6041 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6042                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6043                                 slave_id, UINT16);
6044 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6045                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6046                                 port_id, UINT16);
6047
6048 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6049                 .f = cmd_remove_bonding_slave_parsed,
6050                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6051                         "Remove a slave device from a bonded device",
6052                 .data = NULL,
6053                 .tokens = {
6054                                 (void *)&cmd_removebonding_slave_remove,
6055                                 (void *)&cmd_removebonding_slave_bonding,
6056                                 (void *)&cmd_removebonding_slave_slave,
6057                                 (void *)&cmd_removebonding_slave_slaveid,
6058                                 (void *)&cmd_removebonding_slave_port,
6059                                 NULL
6060                 }
6061 };
6062
6063 /* *** CREATE BONDED DEVICE *** */
6064 struct cmd_create_bonded_device_result {
6065         cmdline_fixed_string_t create;
6066         cmdline_fixed_string_t bonded;
6067         cmdline_fixed_string_t device;
6068         uint8_t mode;
6069         uint8_t socket;
6070 };
6071
6072 static int bond_dev_num = 0;
6073
6074 static void cmd_create_bonded_device_parsed(void *parsed_result,
6075                 __attribute__((unused))  struct cmdline *cl,
6076                 __attribute__((unused)) void *data)
6077 {
6078         struct cmd_create_bonded_device_result *res = parsed_result;
6079         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6080         int port_id;
6081
6082         if (test_done == 0) {
6083                 printf("Please stop forwarding first\n");
6084                 return;
6085         }
6086
6087         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6088                         bond_dev_num++);
6089
6090         /* Create a new bonded device. */
6091         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6092         if (port_id < 0) {
6093                 printf("\t Failed to create bonded device.\n");
6094                 return;
6095         } else {
6096                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6097                                 port_id);
6098
6099                 /* Update number of ports */
6100                 nb_ports = rte_eth_dev_count_avail();
6101                 reconfig(port_id, res->socket);
6102                 rte_eth_promiscuous_enable(port_id);
6103                 ports[port_id].need_setup = 0;
6104                 ports[port_id].port_status = RTE_PORT_STOPPED;
6105         }
6106
6107 }
6108
6109 cmdline_parse_token_string_t cmd_createbonded_device_create =
6110                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6111                                 create, "create");
6112 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6113                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6114                                 bonded, "bonded");
6115 cmdline_parse_token_string_t cmd_createbonded_device_device =
6116                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6117                                 device, "device");
6118 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6119                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6120                                 mode, UINT8);
6121 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6122                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6123                                 socket, UINT8);
6124
6125 cmdline_parse_inst_t cmd_create_bonded_device = {
6126                 .f = cmd_create_bonded_device_parsed,
6127                 .help_str = "create bonded device <mode> <socket>: "
6128                         "Create a new bonded device with specific bonding mode and socket",
6129                 .data = NULL,
6130                 .tokens = {
6131                                 (void *)&cmd_createbonded_device_create,
6132                                 (void *)&cmd_createbonded_device_bonded,
6133                                 (void *)&cmd_createbonded_device_device,
6134                                 (void *)&cmd_createbonded_device_mode,
6135                                 (void *)&cmd_createbonded_device_socket,
6136                                 NULL
6137                 }
6138 };
6139
6140 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6141 struct cmd_set_bond_mac_addr_result {
6142         cmdline_fixed_string_t set;
6143         cmdline_fixed_string_t bonding;
6144         cmdline_fixed_string_t mac_addr;
6145         uint16_t port_num;
6146         struct rte_ether_addr address;
6147 };
6148
6149 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6150                 __attribute__((unused))  struct cmdline *cl,
6151                 __attribute__((unused)) void *data)
6152 {
6153         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6154         int ret;
6155
6156         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6157                 return;
6158
6159         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6160
6161         /* check the return value and print it if is < 0 */
6162         if (ret < 0)
6163                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6164 }
6165
6166 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6167                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6168 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6169                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6170                                 "bonding");
6171 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6172                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6173                                 "mac_addr");
6174 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6175                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6176                                 port_num, UINT16);
6177 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6178                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6179
6180 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6181                 .f = cmd_set_bond_mac_addr_parsed,
6182                 .data = (void *) 0,
6183                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6184                 .tokens = {
6185                                 (void *)&cmd_set_bond_mac_addr_set,
6186                                 (void *)&cmd_set_bond_mac_addr_bonding,
6187                                 (void *)&cmd_set_bond_mac_addr_mac,
6188                                 (void *)&cmd_set_bond_mac_addr_portnum,
6189                                 (void *)&cmd_set_bond_mac_addr_addr,
6190                                 NULL
6191                 }
6192 };
6193
6194
6195 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6196 struct cmd_set_bond_mon_period_result {
6197         cmdline_fixed_string_t set;
6198         cmdline_fixed_string_t bonding;
6199         cmdline_fixed_string_t mon_period;
6200         uint16_t port_num;
6201         uint32_t period_ms;
6202 };
6203
6204 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6205                 __attribute__((unused))  struct cmdline *cl,
6206                 __attribute__((unused)) void *data)
6207 {
6208         struct cmd_set_bond_mon_period_result *res = parsed_result;
6209         int ret;
6210
6211         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6212
6213         /* check the return value and print it if is < 0 */
6214         if (ret < 0)
6215                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6216 }
6217
6218 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6219                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6220                                 set, "set");
6221 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6222                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6223                                 bonding, "bonding");
6224 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6225                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6226                                 mon_period,     "mon_period");
6227 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6228                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6229                                 port_num, UINT16);
6230 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6231                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6232                                 period_ms, UINT32);
6233
6234 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6235                 .f = cmd_set_bond_mon_period_parsed,
6236                 .data = (void *) 0,
6237                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6238                 .tokens = {
6239                                 (void *)&cmd_set_bond_mon_period_set,
6240                                 (void *)&cmd_set_bond_mon_period_bonding,
6241                                 (void *)&cmd_set_bond_mon_period_mon_period,
6242                                 (void *)&cmd_set_bond_mon_period_portnum,
6243                                 (void *)&cmd_set_bond_mon_period_period_ms,
6244                                 NULL
6245                 }
6246 };
6247
6248
6249
6250 struct cmd_set_bonding_agg_mode_policy_result {
6251         cmdline_fixed_string_t set;
6252         cmdline_fixed_string_t bonding;
6253         cmdline_fixed_string_t agg_mode;
6254         uint16_t port_num;
6255         cmdline_fixed_string_t policy;
6256 };
6257
6258
6259 static void
6260 cmd_set_bonding_agg_mode(void *parsed_result,
6261                 __attribute__((unused)) struct cmdline *cl,
6262                 __attribute__((unused)) void *data)
6263 {
6264         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6265         uint8_t policy = AGG_BANDWIDTH;
6266
6267         if (!strcmp(res->policy, "bandwidth"))
6268                 policy = AGG_BANDWIDTH;
6269         else if (!strcmp(res->policy, "stable"))
6270                 policy = AGG_STABLE;
6271         else if (!strcmp(res->policy, "count"))
6272                 policy = AGG_COUNT;
6273
6274         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6275 }
6276
6277
6278 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6279         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6280                                 set, "set");
6281 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6282         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6283                                 bonding, "bonding");
6284
6285 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6286         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6287                                 agg_mode, "agg_mode");
6288
6289 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6290         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6291                                 port_num, UINT16);
6292
6293 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6294         TOKEN_STRING_INITIALIZER(
6295                         struct cmd_set_bonding_balance_xmit_policy_result,
6296                 policy, "stable#bandwidth#count");
6297
6298 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6299         .f = cmd_set_bonding_agg_mode,
6300         .data = (void *) 0,
6301         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6302         .tokens = {
6303                         (void *)&cmd_set_bonding_agg_mode_set,
6304                         (void *)&cmd_set_bonding_agg_mode_bonding,
6305                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6306                         (void *)&cmd_set_bonding_agg_mode_portnum,
6307                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6308                         NULL
6309                 }
6310 };
6311
6312
6313 #endif /* RTE_LIBRTE_PMD_BOND */
6314
6315 /* *** SET FORWARDING MODE *** */
6316 struct cmd_set_fwd_mode_result {
6317         cmdline_fixed_string_t set;
6318         cmdline_fixed_string_t fwd;
6319         cmdline_fixed_string_t mode;
6320 };
6321
6322 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6323                                     __attribute__((unused)) struct cmdline *cl,
6324                                     __attribute__((unused)) void *data)
6325 {
6326         struct cmd_set_fwd_mode_result *res = parsed_result;
6327
6328         retry_enabled = 0;
6329         set_pkt_forwarding_mode(res->mode);
6330 }
6331
6332 cmdline_parse_token_string_t cmd_setfwd_set =
6333         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6334 cmdline_parse_token_string_t cmd_setfwd_fwd =
6335         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6336 cmdline_parse_token_string_t cmd_setfwd_mode =
6337         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6338                 "" /* defined at init */);
6339
6340 cmdline_parse_inst_t cmd_set_fwd_mode = {
6341         .f = cmd_set_fwd_mode_parsed,
6342         .data = NULL,
6343         .help_str = NULL, /* defined at init */
6344         .tokens = {
6345                 (void *)&cmd_setfwd_set,
6346                 (void *)&cmd_setfwd_fwd,
6347                 (void *)&cmd_setfwd_mode,
6348                 NULL,
6349         },
6350 };
6351
6352 static void cmd_set_fwd_mode_init(void)
6353 {
6354         char *modes, *c;
6355         static char token[128];
6356         static char help[256];
6357         cmdline_parse_token_string_t *token_struct;
6358
6359         modes = list_pkt_forwarding_modes();
6360         snprintf(help, sizeof(help), "set fwd %s: "
6361                 "Set packet forwarding mode", modes);
6362         cmd_set_fwd_mode.help_str = help;
6363
6364         /* string token separator is # */
6365         for (c = token; *modes != '\0'; modes++)
6366                 if (*modes == '|')
6367                         *c++ = '#';
6368                 else
6369                         *c++ = *modes;
6370         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6371         token_struct->string_data.str = token;
6372 }
6373
6374 /* *** SET RETRY FORWARDING MODE *** */
6375 struct cmd_set_fwd_retry_mode_result {
6376         cmdline_fixed_string_t set;
6377         cmdline_fixed_string_t fwd;
6378         cmdline_fixed_string_t mode;
6379         cmdline_fixed_string_t retry;
6380 };
6381
6382 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6383                             __attribute__((unused)) struct cmdline *cl,
6384                             __attribute__((unused)) void *data)
6385 {
6386         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6387
6388         retry_enabled = 1;
6389         set_pkt_forwarding_mode(res->mode);
6390 }
6391
6392 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6393         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6394                         set, "set");
6395 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6396         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6397                         fwd, "fwd");
6398 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6399         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6400                         mode,
6401                 "" /* defined at init */);
6402 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6403         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6404                         retry, "retry");
6405
6406 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6407         .f = cmd_set_fwd_retry_mode_parsed,
6408         .data = NULL,
6409         .help_str = NULL, /* defined at init */
6410         .tokens = {
6411                 (void *)&cmd_setfwd_retry_set,
6412                 (void *)&cmd_setfwd_retry_fwd,
6413                 (void *)&cmd_setfwd_retry_mode,
6414                 (void *)&cmd_setfwd_retry_retry,
6415                 NULL,
6416         },
6417 };
6418
6419 static void cmd_set_fwd_retry_mode_init(void)
6420 {
6421         char *modes, *c;
6422         static char token[128];
6423         static char help[256];
6424         cmdline_parse_token_string_t *token_struct;
6425
6426         modes = list_pkt_forwarding_retry_modes();
6427         snprintf(help, sizeof(help), "set fwd %s retry: "
6428                 "Set packet forwarding mode with retry", modes);
6429         cmd_set_fwd_retry_mode.help_str = help;
6430
6431         /* string token separator is # */
6432         for (c = token; *modes != '\0'; modes++)
6433                 if (*modes == '|')
6434                         *c++ = '#';
6435                 else
6436                         *c++ = *modes;
6437         token_struct = (cmdline_parse_token_string_t *)
6438                 cmd_set_fwd_retry_mode.tokens[2];
6439         token_struct->string_data.str = token;
6440 }
6441
6442 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6443 struct cmd_set_burst_tx_retry_result {
6444         cmdline_fixed_string_t set;
6445         cmdline_fixed_string_t burst;
6446         cmdline_fixed_string_t tx;
6447         cmdline_fixed_string_t delay;
6448         uint32_t time;
6449         cmdline_fixed_string_t retry;
6450         uint32_t retry_num;
6451 };
6452
6453 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6454                                         __attribute__((unused)) struct cmdline *cl,
6455                                         __attribute__((unused)) void *data)
6456 {
6457         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6458
6459         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6460                 && !strcmp(res->tx, "tx")) {
6461                 if (!strcmp(res->delay, "delay"))
6462                         burst_tx_delay_time = res->time;
6463                 if (!strcmp(res->retry, "retry"))
6464                         burst_tx_retry_num = res->retry_num;
6465         }
6466
6467 }
6468
6469 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6470         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6471 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6472         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6473                                  "burst");
6474 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6475         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6476 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6478 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6479         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6480 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6481         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6482 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6483         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6484
6485 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6486         .f = cmd_set_burst_tx_retry_parsed,
6487         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6488         .tokens = {
6489                 (void *)&cmd_set_burst_tx_retry_set,
6490                 (void *)&cmd_set_burst_tx_retry_burst,
6491                 (void *)&cmd_set_burst_tx_retry_tx,
6492                 (void *)&cmd_set_burst_tx_retry_delay,
6493                 (void *)&cmd_set_burst_tx_retry_time,
6494                 (void *)&cmd_set_burst_tx_retry_retry,
6495                 (void *)&cmd_set_burst_tx_retry_retry_num,
6496                 NULL,
6497         },
6498 };
6499
6500 /* *** SET PROMISC MODE *** */
6501 struct cmd_set_promisc_mode_result {
6502         cmdline_fixed_string_t set;
6503         cmdline_fixed_string_t promisc;
6504         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6505         uint16_t port_num;               /* valid if "allports" argument == 0 */
6506         cmdline_fixed_string_t mode;
6507 };
6508
6509 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6510                                         __attribute__((unused)) struct cmdline *cl,
6511                                         void *allports)
6512 {
6513         struct cmd_set_promisc_mode_result *res = parsed_result;
6514         int enable;
6515         portid_t i;
6516
6517         if (!strcmp(res->mode, "on"))
6518                 enable = 1;
6519         else
6520                 enable = 0;
6521
6522         /* all ports */
6523         if (allports) {
6524                 RTE_ETH_FOREACH_DEV(i) {
6525                         if (enable)
6526                                 rte_eth_promiscuous_enable(i);
6527                         else
6528                                 rte_eth_promiscuous_disable(i);
6529                 }
6530         }
6531         else {
6532                 if (enable)
6533                         rte_eth_promiscuous_enable(res->port_num);
6534                 else
6535                         rte_eth_promiscuous_disable(res->port_num);
6536         }
6537 }
6538
6539 cmdline_parse_token_string_t cmd_setpromisc_set =
6540         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6541 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6542         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6543                                  "promisc");
6544 cmdline_parse_token_string_t cmd_setpromisc_portall =
6545         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6546                                  "all");
6547 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6548         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6549                               UINT16);
6550 cmdline_parse_token_string_t cmd_setpromisc_mode =
6551         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6552                                  "on#off");
6553
6554 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6555         .f = cmd_set_promisc_mode_parsed,
6556         .data = (void *)1,
6557         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6558         .tokens = {
6559                 (void *)&cmd_setpromisc_set,
6560                 (void *)&cmd_setpromisc_promisc,
6561                 (void *)&cmd_setpromisc_portall,
6562                 (void *)&cmd_setpromisc_mode,
6563                 NULL,
6564         },
6565 };
6566
6567 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6568         .f = cmd_set_promisc_mode_parsed,
6569         .data = (void *)0,
6570         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6571         .tokens = {
6572                 (void *)&cmd_setpromisc_set,
6573                 (void *)&cmd_setpromisc_promisc,
6574                 (void *)&cmd_setpromisc_portnum,
6575                 (void *)&cmd_setpromisc_mode,
6576                 NULL,
6577         },
6578 };
6579
6580 /* *** SET ALLMULTI MODE *** */
6581 struct cmd_set_allmulti_mode_result {
6582         cmdline_fixed_string_t set;
6583         cmdline_fixed_string_t allmulti;
6584         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6585         uint16_t port_num;               /* valid if "allports" argument == 0 */
6586         cmdline_fixed_string_t mode;
6587 };
6588
6589 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6590                                         __attribute__((unused)) struct cmdline *cl,
6591                                         void *allports)
6592 {
6593         struct cmd_set_allmulti_mode_result *res = parsed_result;
6594         int enable;
6595         portid_t i;
6596
6597         if (!strcmp(res->mode, "on"))
6598                 enable = 1;
6599         else
6600                 enable = 0;
6601
6602         /* all ports */
6603         if (allports) {
6604                 RTE_ETH_FOREACH_DEV(i) {
6605                         if (enable)
6606                                 rte_eth_allmulticast_enable(i);
6607                         else
6608                                 rte_eth_allmulticast_disable(i);
6609                 }
6610         }
6611         else {
6612                 if (enable)
6613                         rte_eth_allmulticast_enable(res->port_num);
6614                 else
6615                         rte_eth_allmulticast_disable(res->port_num);
6616         }
6617 }
6618
6619 cmdline_parse_token_string_t cmd_setallmulti_set =
6620         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6621 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6622         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6623                                  "allmulti");
6624 cmdline_parse_token_string_t cmd_setallmulti_portall =
6625         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6626                                  "all");
6627 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6628         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6629                               UINT16);
6630 cmdline_parse_token_string_t cmd_setallmulti_mode =
6631         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6632                                  "on#off");
6633
6634 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6635         .f = cmd_set_allmulti_mode_parsed,
6636         .data = (void *)1,
6637         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6638         .tokens = {
6639                 (void *)&cmd_setallmulti_set,
6640                 (void *)&cmd_setallmulti_allmulti,
6641                 (void *)&cmd_setallmulti_portall,
6642                 (void *)&cmd_setallmulti_mode,
6643                 NULL,
6644         },
6645 };
6646
6647 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6648         .f = cmd_set_allmulti_mode_parsed,
6649         .data = (void *)0,
6650         .help_str = "set allmulti <port_id> on|off: "
6651                 "Set allmulti mode on port_id",
6652         .tokens = {
6653                 (void *)&cmd_setallmulti_set,
6654                 (void *)&cmd_setallmulti_allmulti,
6655                 (void *)&cmd_setallmulti_portnum,
6656                 (void *)&cmd_setallmulti_mode,
6657                 NULL,
6658         },
6659 };
6660
6661 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6662 struct cmd_link_flow_ctrl_set_result {
6663         cmdline_fixed_string_t set;
6664         cmdline_fixed_string_t flow_ctrl;
6665         cmdline_fixed_string_t rx;
6666         cmdline_fixed_string_t rx_lfc_mode;
6667         cmdline_fixed_string_t tx;
6668         cmdline_fixed_string_t tx_lfc_mode;
6669         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6670         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6671         cmdline_fixed_string_t autoneg_str;
6672         cmdline_fixed_string_t autoneg;
6673         cmdline_fixed_string_t hw_str;
6674         uint32_t high_water;
6675         cmdline_fixed_string_t lw_str;
6676         uint32_t low_water;
6677         cmdline_fixed_string_t pt_str;
6678         uint16_t pause_time;
6679         cmdline_fixed_string_t xon_str;
6680         uint16_t send_xon;
6681         portid_t port_id;
6682 };
6683
6684 cmdline_parse_token_string_t cmd_lfc_set_set =
6685         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6686                                 set, "set");
6687 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6688         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6689                                 flow_ctrl, "flow_ctrl");
6690 cmdline_parse_token_string_t cmd_lfc_set_rx =
6691         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6692                                 rx, "rx");
6693 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6694         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6695                                 rx_lfc_mode, "on#off");
6696 cmdline_parse_token_string_t cmd_lfc_set_tx =
6697         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6698                                 tx, "tx");
6699 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6700         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6701                                 tx_lfc_mode, "on#off");
6702 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6703         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6704                                 hw_str, "high_water");
6705 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6706         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6707                                 high_water, UINT32);
6708 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6709         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6710                                 lw_str, "low_water");
6711 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6712         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6713                                 low_water, UINT32);
6714 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6715         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6716                                 pt_str, "pause_time");
6717 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6718         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6719                                 pause_time, UINT16);
6720 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6721         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6722                                 xon_str, "send_xon");
6723 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6724         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6725                                 send_xon, UINT16);
6726 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6727         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6728                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6729 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6730         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6731                                 mac_ctrl_frame_fwd_mode, "on#off");
6732 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6733         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6734                                 autoneg_str, "autoneg");
6735 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6736         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6737                                 autoneg, "on#off");
6738 cmdline_parse_token_num_t cmd_lfc_set_portid =
6739         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6740                                 port_id, UINT16);
6741
6742 /* forward declaration */
6743 static void
6744 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6745                               void *data);
6746
6747 cmdline_parse_inst_t cmd_link_flow_control_set = {
6748         .f = cmd_link_flow_ctrl_set_parsed,
6749         .data = NULL,
6750         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6751                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6752                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6753         .tokens = {
6754                 (void *)&cmd_lfc_set_set,
6755                 (void *)&cmd_lfc_set_flow_ctrl,
6756                 (void *)&cmd_lfc_set_rx,
6757                 (void *)&cmd_lfc_set_rx_mode,
6758                 (void *)&cmd_lfc_set_tx,
6759                 (void *)&cmd_lfc_set_tx_mode,
6760                 (void *)&cmd_lfc_set_high_water,
6761                 (void *)&cmd_lfc_set_low_water,
6762                 (void *)&cmd_lfc_set_pause_time,
6763                 (void *)&cmd_lfc_set_send_xon,
6764                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6765                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6766                 (void *)&cmd_lfc_set_autoneg_str,
6767                 (void *)&cmd_lfc_set_autoneg,
6768                 (void *)&cmd_lfc_set_portid,
6769                 NULL,
6770         },
6771 };
6772
6773 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6774         .f = cmd_link_flow_ctrl_set_parsed,
6775         .data = (void *)&cmd_link_flow_control_set_rx,
6776         .help_str = "set flow_ctrl rx on|off <port_id>: "
6777                 "Change rx flow control parameter",
6778         .tokens = {
6779                 (void *)&cmd_lfc_set_set,
6780                 (void *)&cmd_lfc_set_flow_ctrl,
6781                 (void *)&cmd_lfc_set_rx,
6782                 (void *)&cmd_lfc_set_rx_mode,
6783                 (void *)&cmd_lfc_set_portid,
6784                 NULL,
6785         },
6786 };
6787
6788 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6789         .f = cmd_link_flow_ctrl_set_parsed,
6790         .data = (void *)&cmd_link_flow_control_set_tx,
6791         .help_str = "set flow_ctrl tx on|off <port_id>: "
6792                 "Change tx flow control parameter",
6793         .tokens = {
6794                 (void *)&cmd_lfc_set_set,
6795                 (void *)&cmd_lfc_set_flow_ctrl,
6796                 (void *)&cmd_lfc_set_tx,
6797                 (void *)&cmd_lfc_set_tx_mode,
6798                 (void *)&cmd_lfc_set_portid,
6799                 NULL,
6800         },
6801 };
6802
6803 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6804         .f = cmd_link_flow_ctrl_set_parsed,
6805         .data = (void *)&cmd_link_flow_control_set_hw,
6806         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6807                 "Change high water flow control parameter",
6808         .tokens = {
6809                 (void *)&cmd_lfc_set_set,
6810                 (void *)&cmd_lfc_set_flow_ctrl,
6811                 (void *)&cmd_lfc_set_high_water_str,
6812                 (void *)&cmd_lfc_set_high_water,
6813                 (void *)&cmd_lfc_set_portid,
6814                 NULL,
6815         },
6816 };
6817
6818 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6819         .f = cmd_link_flow_ctrl_set_parsed,
6820         .data = (void *)&cmd_link_flow_control_set_lw,
6821         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6822                 "Change low water flow control parameter",
6823         .tokens = {
6824                 (void *)&cmd_lfc_set_set,
6825                 (void *)&cmd_lfc_set_flow_ctrl,
6826                 (void *)&cmd_lfc_set_low_water_str,
6827                 (void *)&cmd_lfc_set_low_water,
6828                 (void *)&cmd_lfc_set_portid,
6829                 NULL,
6830         },
6831 };
6832
6833 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6834         .f = cmd_link_flow_ctrl_set_parsed,
6835         .data = (void *)&cmd_link_flow_control_set_pt,
6836         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6837                 "Change pause time flow control parameter",
6838         .tokens = {
6839                 (void *)&cmd_lfc_set_set,
6840                 (void *)&cmd_lfc_set_flow_ctrl,
6841                 (void *)&cmd_lfc_set_pause_time_str,
6842                 (void *)&cmd_lfc_set_pause_time,
6843                 (void *)&cmd_lfc_set_portid,
6844                 NULL,
6845         },
6846 };
6847
6848 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6849         .f = cmd_link_flow_ctrl_set_parsed,
6850         .data = (void *)&cmd_link_flow_control_set_xon,
6851         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6852                 "Change send_xon flow control parameter",
6853         .tokens = {
6854                 (void *)&cmd_lfc_set_set,
6855                 (void *)&cmd_lfc_set_flow_ctrl,
6856                 (void *)&cmd_lfc_set_send_xon_str,
6857                 (void *)&cmd_lfc_set_send_xon,
6858                 (void *)&cmd_lfc_set_portid,
6859                 NULL,
6860         },
6861 };
6862
6863 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6864         .f = cmd_link_flow_ctrl_set_parsed,
6865         .data = (void *)&cmd_link_flow_control_set_macfwd,
6866         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6867                 "Change mac ctrl fwd flow control parameter",
6868         .tokens = {
6869                 (void *)&cmd_lfc_set_set,
6870                 (void *)&cmd_lfc_set_flow_ctrl,
6871                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6872                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6873                 (void *)&cmd_lfc_set_portid,
6874                 NULL,
6875         },
6876 };
6877
6878 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6879         .f = cmd_link_flow_ctrl_set_parsed,
6880         .data = (void *)&cmd_link_flow_control_set_autoneg,
6881         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6882                 "Change autoneg flow control parameter",
6883         .tokens = {
6884                 (void *)&cmd_lfc_set_set,
6885                 (void *)&cmd_lfc_set_flow_ctrl,
6886                 (void *)&cmd_lfc_set_autoneg_str,
6887                 (void *)&cmd_lfc_set_autoneg,
6888                 (void *)&cmd_lfc_set_portid,
6889                 NULL,
6890         },
6891 };
6892
6893 static void
6894 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6895                               __attribute__((unused)) struct cmdline *cl,
6896                               void *data)
6897 {
6898         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6899         cmdline_parse_inst_t *cmd = data;
6900         struct rte_eth_fc_conf fc_conf;
6901         int rx_fc_en = 0;
6902         int tx_fc_en = 0;
6903         int ret;
6904
6905         /*
6906          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6907          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6908          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6909          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6910          */
6911         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6912                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6913         };
6914
6915         /* Partial command line, retrieve current configuration */
6916         if (cmd) {
6917                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6918                 if (ret != 0) {
6919                         printf("cannot get current flow ctrl parameters, return"
6920                                "code = %d\n", ret);
6921                         return;
6922                 }
6923
6924                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6925                     (fc_conf.mode == RTE_FC_FULL))
6926                         rx_fc_en = 1;
6927                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6928                     (fc_conf.mode == RTE_FC_FULL))
6929                         tx_fc_en = 1;
6930         }
6931
6932         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6933                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6934
6935         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6936                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6937
6938         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6939
6940         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6941                 fc_conf.high_water = res->high_water;
6942
6943         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6944                 fc_conf.low_water = res->low_water;
6945
6946         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6947                 fc_conf.pause_time = res->pause_time;
6948
6949         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6950                 fc_conf.send_xon = res->send_xon;
6951
6952         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6953                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6954                         fc_conf.mac_ctrl_frame_fwd = 1;
6955                 else
6956                         fc_conf.mac_ctrl_frame_fwd = 0;
6957         }
6958
6959         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6960                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6961
6962         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6963         if (ret != 0)
6964                 printf("bad flow contrl parameter, return code = %d \n", ret);
6965 }
6966
6967 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6968 struct cmd_priority_flow_ctrl_set_result {
6969         cmdline_fixed_string_t set;
6970         cmdline_fixed_string_t pfc_ctrl;
6971         cmdline_fixed_string_t rx;
6972         cmdline_fixed_string_t rx_pfc_mode;
6973         cmdline_fixed_string_t tx;
6974         cmdline_fixed_string_t tx_pfc_mode;
6975         uint32_t high_water;
6976         uint32_t low_water;
6977         uint16_t pause_time;
6978         uint8_t  priority;
6979         portid_t port_id;
6980 };
6981
6982 static void
6983 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6984                        __attribute__((unused)) struct cmdline *cl,
6985                        __attribute__((unused)) void *data)
6986 {
6987         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6988         struct rte_eth_pfc_conf pfc_conf;
6989         int rx_fc_enable, tx_fc_enable;
6990         int ret;
6991
6992         /*
6993          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6994          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6995          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6996          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6997          */
6998         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6999                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
7000         };
7001
7002         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7003         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7004         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7005         pfc_conf.fc.high_water = res->high_water;
7006         pfc_conf.fc.low_water  = res->low_water;
7007         pfc_conf.fc.pause_time = res->pause_time;
7008         pfc_conf.priority      = res->priority;
7009
7010         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7011         if (ret != 0)
7012                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7013 }
7014
7015 cmdline_parse_token_string_t cmd_pfc_set_set =
7016         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7017                                 set, "set");
7018 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7019         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7020                                 pfc_ctrl, "pfc_ctrl");
7021 cmdline_parse_token_string_t cmd_pfc_set_rx =
7022         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7023                                 rx, "rx");
7024 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7025         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7026                                 rx_pfc_mode, "on#off");
7027 cmdline_parse_token_string_t cmd_pfc_set_tx =
7028         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7029                                 tx, "tx");
7030 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7031         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7032                                 tx_pfc_mode, "on#off");
7033 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7034         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7035                                 high_water, UINT32);
7036 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7037         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7038                                 low_water, UINT32);
7039 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7040         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7041                                 pause_time, UINT16);
7042 cmdline_parse_token_num_t cmd_pfc_set_priority =
7043         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7044                                 priority, UINT8);
7045 cmdline_parse_token_num_t cmd_pfc_set_portid =
7046         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7047                                 port_id, UINT16);
7048
7049 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7050         .f = cmd_priority_flow_ctrl_set_parsed,
7051         .data = NULL,
7052         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7053                 "<pause_time> <priority> <port_id>: "
7054                 "Configure the Ethernet priority flow control",
7055         .tokens = {
7056                 (void *)&cmd_pfc_set_set,
7057                 (void *)&cmd_pfc_set_flow_ctrl,
7058                 (void *)&cmd_pfc_set_rx,
7059                 (void *)&cmd_pfc_set_rx_mode,
7060                 (void *)&cmd_pfc_set_tx,
7061                 (void *)&cmd_pfc_set_tx_mode,
7062                 (void *)&cmd_pfc_set_high_water,
7063                 (void *)&cmd_pfc_set_low_water,
7064                 (void *)&cmd_pfc_set_pause_time,
7065                 (void *)&cmd_pfc_set_priority,
7066                 (void *)&cmd_pfc_set_portid,
7067                 NULL,
7068         },
7069 };
7070
7071 /* *** RESET CONFIGURATION *** */
7072 struct cmd_reset_result {
7073         cmdline_fixed_string_t reset;
7074         cmdline_fixed_string_t def;
7075 };
7076
7077 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7078                              struct cmdline *cl,
7079                              __attribute__((unused)) void *data)
7080 {
7081         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7082         set_def_fwd_config();
7083 }
7084
7085 cmdline_parse_token_string_t cmd_reset_set =
7086         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7087 cmdline_parse_token_string_t cmd_reset_def =
7088         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7089                                  "default");
7090
7091 cmdline_parse_inst_t cmd_reset = {
7092         .f = cmd_reset_parsed,
7093         .data = NULL,
7094         .help_str = "set default: Reset default forwarding configuration",
7095         .tokens = {
7096                 (void *)&cmd_reset_set,
7097                 (void *)&cmd_reset_def,
7098                 NULL,
7099         },
7100 };
7101
7102 /* *** START FORWARDING *** */
7103 struct cmd_start_result {
7104         cmdline_fixed_string_t start;
7105 };
7106
7107 cmdline_parse_token_string_t cmd_start_start =
7108         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7109
7110 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7111                              __attribute__((unused)) struct cmdline *cl,
7112                              __attribute__((unused)) void *data)
7113 {
7114         start_packet_forwarding(0);
7115 }
7116
7117 cmdline_parse_inst_t cmd_start = {
7118         .f = cmd_start_parsed,
7119         .data = NULL,
7120         .help_str = "start: Start packet forwarding",
7121         .tokens = {
7122                 (void *)&cmd_start_start,
7123                 NULL,
7124         },
7125 };
7126
7127 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7128 struct cmd_start_tx_first_result {
7129         cmdline_fixed_string_t start;
7130         cmdline_fixed_string_t tx_first;
7131 };
7132
7133 static void
7134 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7135                           __attribute__((unused)) struct cmdline *cl,
7136                           __attribute__((unused)) void *data)
7137 {
7138         start_packet_forwarding(1);
7139 }
7140
7141 cmdline_parse_token_string_t cmd_start_tx_first_start =
7142         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7143                                  "start");
7144 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7145         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7146                                  tx_first, "tx_first");
7147
7148 cmdline_parse_inst_t cmd_start_tx_first = {
7149         .f = cmd_start_tx_first_parsed,
7150         .data = NULL,
7151         .help_str = "start tx_first: Start packet forwarding, "
7152                 "after sending 1 burst of packets",
7153         .tokens = {
7154                 (void *)&cmd_start_tx_first_start,
7155                 (void *)&cmd_start_tx_first_tx_first,
7156                 NULL,
7157         },
7158 };
7159
7160 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7161 struct cmd_start_tx_first_n_result {
7162         cmdline_fixed_string_t start;
7163         cmdline_fixed_string_t tx_first;
7164         uint32_t tx_num;
7165 };
7166
7167 static void
7168 cmd_start_tx_first_n_parsed(void *parsed_result,
7169                           __attribute__((unused)) struct cmdline *cl,
7170                           __attribute__((unused)) void *data)
7171 {
7172         struct cmd_start_tx_first_n_result *res = parsed_result;
7173
7174         start_packet_forwarding(res->tx_num);
7175 }
7176
7177 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7178         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7179                         start, "start");
7180 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7181         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7182                         tx_first, "tx_first");
7183 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7184         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7185                         tx_num, UINT32);
7186
7187 cmdline_parse_inst_t cmd_start_tx_first_n = {
7188         .f = cmd_start_tx_first_n_parsed,
7189         .data = NULL,
7190         .help_str = "start tx_first <num>: "
7191                 "packet forwarding, after sending <num> bursts of packets",
7192         .tokens = {
7193                 (void *)&cmd_start_tx_first_n_start,
7194                 (void *)&cmd_start_tx_first_n_tx_first,
7195                 (void *)&cmd_start_tx_first_n_tx_num,
7196                 NULL,
7197         },
7198 };
7199
7200 /* *** SET LINK UP *** */
7201 struct cmd_set_link_up_result {
7202         cmdline_fixed_string_t set;
7203         cmdline_fixed_string_t link_up;
7204         cmdline_fixed_string_t port;
7205         portid_t port_id;
7206 };
7207
7208 cmdline_parse_token_string_t cmd_set_link_up_set =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7210 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7212                                 "link-up");
7213 cmdline_parse_token_string_t cmd_set_link_up_port =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7215 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7216         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7217
7218 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7219                              __attribute__((unused)) struct cmdline *cl,
7220                              __attribute__((unused)) void *data)
7221 {
7222         struct cmd_set_link_up_result *res = parsed_result;
7223         dev_set_link_up(res->port_id);
7224 }
7225
7226 cmdline_parse_inst_t cmd_set_link_up = {
7227         .f = cmd_set_link_up_parsed,
7228         .data = NULL,
7229         .help_str = "set link-up port <port id>",
7230         .tokens = {
7231                 (void *)&cmd_set_link_up_set,
7232                 (void *)&cmd_set_link_up_link_up,
7233                 (void *)&cmd_set_link_up_port,
7234                 (void *)&cmd_set_link_up_port_id,
7235                 NULL,
7236         },
7237 };
7238
7239 /* *** SET LINK DOWN *** */
7240 struct cmd_set_link_down_result {
7241         cmdline_fixed_string_t set;
7242         cmdline_fixed_string_t link_down;
7243         cmdline_fixed_string_t port;
7244         portid_t port_id;
7245 };
7246
7247 cmdline_parse_token_string_t cmd_set_link_down_set =
7248         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7249 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7250         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7251                                 "link-down");
7252 cmdline_parse_token_string_t cmd_set_link_down_port =
7253         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7254 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7255         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7256
7257 static void cmd_set_link_down_parsed(
7258                                 __attribute__((unused)) void *parsed_result,
7259                                 __attribute__((unused)) struct cmdline *cl,
7260                                 __attribute__((unused)) void *data)
7261 {
7262         struct cmd_set_link_down_result *res = parsed_result;
7263         dev_set_link_down(res->port_id);
7264 }
7265
7266 cmdline_parse_inst_t cmd_set_link_down = {
7267         .f = cmd_set_link_down_parsed,
7268         .data = NULL,
7269         .help_str = "set link-down port <port id>",
7270         .tokens = {
7271                 (void *)&cmd_set_link_down_set,
7272                 (void *)&cmd_set_link_down_link_down,
7273                 (void *)&cmd_set_link_down_port,
7274                 (void *)&cmd_set_link_down_port_id,
7275                 NULL,
7276         },
7277 };
7278
7279 /* *** SHOW CFG *** */
7280 struct cmd_showcfg_result {
7281         cmdline_fixed_string_t show;
7282         cmdline_fixed_string_t cfg;
7283         cmdline_fixed_string_t what;
7284 };
7285
7286 static void cmd_showcfg_parsed(void *parsed_result,
7287                                __attribute__((unused)) struct cmdline *cl,
7288                                __attribute__((unused)) void *data)
7289 {
7290         struct cmd_showcfg_result *res = parsed_result;
7291         if (!strcmp(res->what, "rxtx"))
7292                 rxtx_config_display();
7293         else if (!strcmp(res->what, "cores"))
7294                 fwd_lcores_config_display();
7295         else if (!strcmp(res->what, "fwd"))
7296                 pkt_fwd_config_display(&cur_fwd_config);
7297         else if (!strcmp(res->what, "txpkts"))
7298                 show_tx_pkt_segments();
7299 }
7300
7301 cmdline_parse_token_string_t cmd_showcfg_show =
7302         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7303 cmdline_parse_token_string_t cmd_showcfg_port =
7304         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7305 cmdline_parse_token_string_t cmd_showcfg_what =
7306         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7307                                  "rxtx#cores#fwd#txpkts");
7308
7309 cmdline_parse_inst_t cmd_showcfg = {
7310         .f = cmd_showcfg_parsed,
7311         .data = NULL,
7312         .help_str = "show config rxtx|cores|fwd|txpkts",
7313         .tokens = {
7314                 (void *)&cmd_showcfg_show,
7315                 (void *)&cmd_showcfg_port,
7316                 (void *)&cmd_showcfg_what,
7317                 NULL,
7318         },
7319 };
7320
7321 /* *** SHOW ALL PORT INFO *** */
7322 struct cmd_showportall_result {
7323         cmdline_fixed_string_t show;
7324         cmdline_fixed_string_t port;
7325         cmdline_fixed_string_t what;
7326         cmdline_fixed_string_t all;
7327 };
7328
7329 static void cmd_showportall_parsed(void *parsed_result,
7330                                 __attribute__((unused)) struct cmdline *cl,
7331                                 __attribute__((unused)) void *data)
7332 {
7333         portid_t i;
7334
7335         struct cmd_showportall_result *res = parsed_result;
7336         if (!strcmp(res->show, "clear")) {
7337                 if (!strcmp(res->what, "stats"))
7338                         RTE_ETH_FOREACH_DEV(i)
7339                                 nic_stats_clear(i);
7340                 else if (!strcmp(res->what, "xstats"))
7341                         RTE_ETH_FOREACH_DEV(i)
7342                                 nic_xstats_clear(i);
7343         } else if (!strcmp(res->what, "info"))
7344                 RTE_ETH_FOREACH_DEV(i)
7345                         port_infos_display(i);
7346         else if (!strcmp(res->what, "summary")) {
7347                 port_summary_header_display();
7348                 RTE_ETH_FOREACH_DEV(i)
7349                         port_summary_display(i);
7350         }
7351         else if (!strcmp(res->what, "stats"))
7352                 RTE_ETH_FOREACH_DEV(i)
7353                         nic_stats_display(i);
7354         else if (!strcmp(res->what, "xstats"))
7355                 RTE_ETH_FOREACH_DEV(i)
7356                         nic_xstats_display(i);
7357         else if (!strcmp(res->what, "fdir"))
7358                 RTE_ETH_FOREACH_DEV(i)
7359                         fdir_get_infos(i);
7360         else if (!strcmp(res->what, "stat_qmap"))
7361                 RTE_ETH_FOREACH_DEV(i)
7362                         nic_stats_mapping_display(i);
7363         else if (!strcmp(res->what, "dcb_tc"))
7364                 RTE_ETH_FOREACH_DEV(i)
7365                         port_dcb_info_display(i);
7366         else if (!strcmp(res->what, "cap"))
7367                 RTE_ETH_FOREACH_DEV(i)
7368                         port_offload_cap_display(i);
7369 }
7370
7371 cmdline_parse_token_string_t cmd_showportall_show =
7372         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7373                                  "show#clear");
7374 cmdline_parse_token_string_t cmd_showportall_port =
7375         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7376 cmdline_parse_token_string_t cmd_showportall_what =
7377         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7378                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7379 cmdline_parse_token_string_t cmd_showportall_all =
7380         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7381 cmdline_parse_inst_t cmd_showportall = {
7382         .f = cmd_showportall_parsed,
7383         .data = NULL,
7384         .help_str = "show|clear port "
7385                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7386         .tokens = {
7387                 (void *)&cmd_showportall_show,
7388                 (void *)&cmd_showportall_port,
7389                 (void *)&cmd_showportall_what,
7390                 (void *)&cmd_showportall_all,
7391                 NULL,
7392         },
7393 };
7394
7395 /* *** SHOW PORT INFO *** */
7396 struct cmd_showport_result {
7397         cmdline_fixed_string_t show;
7398         cmdline_fixed_string_t port;
7399         cmdline_fixed_string_t what;
7400         uint16_t portnum;
7401 };
7402
7403 static void cmd_showport_parsed(void *parsed_result,
7404                                 __attribute__((unused)) struct cmdline *cl,
7405                                 __attribute__((unused)) void *data)
7406 {
7407         struct cmd_showport_result *res = parsed_result;
7408         if (!strcmp(res->show, "clear")) {
7409                 if (!strcmp(res->what, "stats"))
7410                         nic_stats_clear(res->portnum);
7411                 else if (!strcmp(res->what, "xstats"))
7412                         nic_xstats_clear(res->portnum);
7413         } else if (!strcmp(res->what, "info"))
7414                 port_infos_display(res->portnum);
7415         else if (!strcmp(res->what, "summary")) {
7416                 port_summary_header_display();
7417                 port_summary_display(res->portnum);
7418         }
7419         else if (!strcmp(res->what, "stats"))
7420                 nic_stats_display(res->portnum);
7421         else if (!strcmp(res->what, "xstats"))
7422                 nic_xstats_display(res->portnum);
7423         else if (!strcmp(res->what, "fdir"))
7424                  fdir_get_infos(res->portnum);
7425         else if (!strcmp(res->what, "stat_qmap"))
7426                 nic_stats_mapping_display(res->portnum);
7427         else if (!strcmp(res->what, "dcb_tc"))
7428                 port_dcb_info_display(res->portnum);
7429         else if (!strcmp(res->what, "cap"))
7430                 port_offload_cap_display(res->portnum);
7431 }
7432
7433 cmdline_parse_token_string_t cmd_showport_show =
7434         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7435                                  "show#clear");
7436 cmdline_parse_token_string_t cmd_showport_port =
7437         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7438 cmdline_parse_token_string_t cmd_showport_what =
7439         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7440                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7441 cmdline_parse_token_num_t cmd_showport_portnum =
7442         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7443
7444 cmdline_parse_inst_t cmd_showport = {
7445         .f = cmd_showport_parsed,
7446         .data = NULL,
7447         .help_str = "show|clear port "
7448                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7449                 "<port_id>",
7450         .tokens = {
7451                 (void *)&cmd_showport_show,
7452                 (void *)&cmd_showport_port,
7453                 (void *)&cmd_showport_what,
7454                 (void *)&cmd_showport_portnum,
7455                 NULL,
7456         },
7457 };
7458
7459 /* *** SHOW QUEUE INFO *** */
7460 struct cmd_showqueue_result {
7461         cmdline_fixed_string_t show;
7462         cmdline_fixed_string_t type;
7463         cmdline_fixed_string_t what;
7464         uint16_t portnum;
7465         uint16_t queuenum;
7466 };
7467
7468 static void
7469 cmd_showqueue_parsed(void *parsed_result,
7470         __attribute__((unused)) struct cmdline *cl,
7471         __attribute__((unused)) void *data)
7472 {
7473         struct cmd_showqueue_result *res = parsed_result;
7474
7475         if (!strcmp(res->type, "rxq"))
7476                 rx_queue_infos_display(res->portnum, res->queuenum);
7477         else if (!strcmp(res->type, "txq"))
7478                 tx_queue_infos_display(res->portnum, res->queuenum);
7479 }
7480
7481 cmdline_parse_token_string_t cmd_showqueue_show =
7482         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7483 cmdline_parse_token_string_t cmd_showqueue_type =
7484         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7485 cmdline_parse_token_string_t cmd_showqueue_what =
7486         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7487 cmdline_parse_token_num_t cmd_showqueue_portnum =
7488         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7489 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7490         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7491
7492 cmdline_parse_inst_t cmd_showqueue = {
7493         .f = cmd_showqueue_parsed,
7494         .data = NULL,
7495         .help_str = "show rxq|txq info <port_id> <queue_id>",
7496         .tokens = {
7497                 (void *)&cmd_showqueue_show,
7498                 (void *)&cmd_showqueue_type,
7499                 (void *)&cmd_showqueue_what,
7500                 (void *)&cmd_showqueue_portnum,
7501                 (void *)&cmd_showqueue_queuenum,
7502                 NULL,
7503         },
7504 };
7505
7506 /* show/clear fwd engine statistics */
7507 struct fwd_result {
7508         cmdline_fixed_string_t action;
7509         cmdline_fixed_string_t fwd;
7510         cmdline_fixed_string_t stats;
7511         cmdline_fixed_string_t all;
7512 };
7513
7514 cmdline_parse_token_string_t cmd_fwd_action =
7515         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7516 cmdline_parse_token_string_t cmd_fwd_fwd =
7517         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7518 cmdline_parse_token_string_t cmd_fwd_stats =
7519         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7520 cmdline_parse_token_string_t cmd_fwd_all =
7521         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7522
7523 static void
7524 cmd_showfwdall_parsed(void *parsed_result,
7525                       __rte_unused struct cmdline *cl,
7526                       __rte_unused void *data)
7527 {
7528         struct fwd_result *res = parsed_result;
7529
7530         if (!strcmp(res->action, "show"))
7531                 fwd_stats_display();
7532         else
7533                 fwd_stats_reset();
7534 }
7535
7536 static cmdline_parse_inst_t cmd_showfwdall = {
7537         .f = cmd_showfwdall_parsed,
7538         .data = NULL,
7539         .help_str = "show|clear fwd stats all",
7540         .tokens = {
7541                 (void *)&cmd_fwd_action,
7542                 (void *)&cmd_fwd_fwd,
7543                 (void *)&cmd_fwd_stats,
7544                 (void *)&cmd_fwd_all,
7545                 NULL,
7546         },
7547 };
7548
7549 /* *** READ PORT REGISTER *** */
7550 struct cmd_read_reg_result {
7551         cmdline_fixed_string_t read;
7552         cmdline_fixed_string_t reg;
7553         portid_t port_id;
7554         uint32_t reg_off;
7555 };
7556
7557 static void
7558 cmd_read_reg_parsed(void *parsed_result,
7559                     __attribute__((unused)) struct cmdline *cl,
7560                     __attribute__((unused)) void *data)
7561 {
7562         struct cmd_read_reg_result *res = parsed_result;
7563         port_reg_display(res->port_id, res->reg_off);
7564 }
7565
7566 cmdline_parse_token_string_t cmd_read_reg_read =
7567         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7568 cmdline_parse_token_string_t cmd_read_reg_reg =
7569         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7570 cmdline_parse_token_num_t cmd_read_reg_port_id =
7571         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7572 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7573         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7574
7575 cmdline_parse_inst_t cmd_read_reg = {
7576         .f = cmd_read_reg_parsed,
7577         .data = NULL,
7578         .help_str = "read reg <port_id> <reg_off>",
7579         .tokens = {
7580                 (void *)&cmd_read_reg_read,
7581                 (void *)&cmd_read_reg_reg,
7582                 (void *)&cmd_read_reg_port_id,
7583                 (void *)&cmd_read_reg_reg_off,
7584                 NULL,
7585         },
7586 };
7587
7588 /* *** READ PORT REGISTER BIT FIELD *** */
7589 struct cmd_read_reg_bit_field_result {
7590         cmdline_fixed_string_t read;
7591         cmdline_fixed_string_t regfield;
7592         portid_t port_id;
7593         uint32_t reg_off;
7594         uint8_t bit1_pos;
7595         uint8_t bit2_pos;
7596 };
7597
7598 static void
7599 cmd_read_reg_bit_field_parsed(void *parsed_result,
7600                               __attribute__((unused)) struct cmdline *cl,
7601                               __attribute__((unused)) void *data)
7602 {
7603         struct cmd_read_reg_bit_field_result *res = parsed_result;
7604         port_reg_bit_field_display(res->port_id, res->reg_off,
7605                                    res->bit1_pos, res->bit2_pos);
7606 }
7607
7608 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7609         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7610                                  "read");
7611 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7612         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7613                                  regfield, "regfield");
7614 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7615         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7616                               UINT16);
7617 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7618         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7619                               UINT32);
7620 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7621         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7622                               UINT8);
7623 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7624         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7625                               UINT8);
7626
7627 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7628         .f = cmd_read_reg_bit_field_parsed,
7629         .data = NULL,
7630         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7631         "Read register bit field between bit_x and bit_y included",
7632         .tokens = {
7633                 (void *)&cmd_read_reg_bit_field_read,
7634                 (void *)&cmd_read_reg_bit_field_regfield,
7635                 (void *)&cmd_read_reg_bit_field_port_id,
7636                 (void *)&cmd_read_reg_bit_field_reg_off,
7637                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7638                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7639                 NULL,
7640         },
7641 };
7642
7643 /* *** READ PORT REGISTER BIT *** */
7644 struct cmd_read_reg_bit_result {
7645         cmdline_fixed_string_t read;
7646         cmdline_fixed_string_t regbit;
7647         portid_t port_id;
7648         uint32_t reg_off;
7649         uint8_t bit_pos;
7650 };
7651
7652 static void
7653 cmd_read_reg_bit_parsed(void *parsed_result,
7654                         __attribute__((unused)) struct cmdline *cl,
7655                         __attribute__((unused)) void *data)
7656 {
7657         struct cmd_read_reg_bit_result *res = parsed_result;
7658         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7659 }
7660
7661 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7662         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7663 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7664         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7665                                  regbit, "regbit");
7666 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7667         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7668 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7669         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7670 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7671         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7672
7673 cmdline_parse_inst_t cmd_read_reg_bit = {
7674         .f = cmd_read_reg_bit_parsed,
7675         .data = NULL,
7676         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7677         .tokens = {
7678                 (void *)&cmd_read_reg_bit_read,
7679                 (void *)&cmd_read_reg_bit_regbit,
7680                 (void *)&cmd_read_reg_bit_port_id,
7681                 (void *)&cmd_read_reg_bit_reg_off,
7682                 (void *)&cmd_read_reg_bit_bit_pos,
7683                 NULL,
7684         },
7685 };
7686
7687 /* *** WRITE PORT REGISTER *** */
7688 struct cmd_write_reg_result {
7689         cmdline_fixed_string_t write;
7690         cmdline_fixed_string_t reg;
7691         portid_t port_id;
7692         uint32_t reg_off;
7693         uint32_t value;
7694 };
7695
7696 static void
7697 cmd_write_reg_parsed(void *parsed_result,
7698                      __attribute__((unused)) struct cmdline *cl,
7699                      __attribute__((unused)) void *data)
7700 {
7701         struct cmd_write_reg_result *res = parsed_result;
7702         port_reg_set(res->port_id, res->reg_off, res->value);
7703 }
7704
7705 cmdline_parse_token_string_t cmd_write_reg_write =
7706         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7707 cmdline_parse_token_string_t cmd_write_reg_reg =
7708         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7709 cmdline_parse_token_num_t cmd_write_reg_port_id =
7710         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7711 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7712         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7713 cmdline_parse_token_num_t cmd_write_reg_value =
7714         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7715
7716 cmdline_parse_inst_t cmd_write_reg = {
7717         .f = cmd_write_reg_parsed,
7718         .data = NULL,
7719         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7720         .tokens = {
7721                 (void *)&cmd_write_reg_write,
7722                 (void *)&cmd_write_reg_reg,
7723                 (void *)&cmd_write_reg_port_id,
7724                 (void *)&cmd_write_reg_reg_off,
7725                 (void *)&cmd_write_reg_value,
7726                 NULL,
7727         },
7728 };
7729
7730 /* *** WRITE PORT REGISTER BIT FIELD *** */
7731 struct cmd_write_reg_bit_field_result {
7732         cmdline_fixed_string_t write;
7733         cmdline_fixed_string_t regfield;
7734         portid_t port_id;
7735         uint32_t reg_off;
7736         uint8_t bit1_pos;
7737         uint8_t bit2_pos;
7738         uint32_t value;
7739 };
7740
7741 static void
7742 cmd_write_reg_bit_field_parsed(void *parsed_result,
7743                                __attribute__((unused)) struct cmdline *cl,
7744                                __attribute__((unused)) void *data)
7745 {
7746         struct cmd_write_reg_bit_field_result *res = parsed_result;
7747         port_reg_bit_field_set(res->port_id, res->reg_off,
7748                           res->bit1_pos, res->bit2_pos, res->value);
7749 }
7750
7751 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7752         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7753                                  "write");
7754 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7755         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7756                                  regfield, "regfield");
7757 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7758         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7759                               UINT16);
7760 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7761         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7762                               UINT32);
7763 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7764         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7765                               UINT8);
7766 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7767         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7768                               UINT8);
7769 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7770         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7771                               UINT32);
7772
7773 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7774         .f = cmd_write_reg_bit_field_parsed,
7775         .data = NULL,
7776         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7777                 "<reg_value>: "
7778                 "Set register bit field between bit_x and bit_y included",
7779         .tokens = {
7780                 (void *)&cmd_write_reg_bit_field_write,
7781                 (void *)&cmd_write_reg_bit_field_regfield,
7782                 (void *)&cmd_write_reg_bit_field_port_id,
7783                 (void *)&cmd_write_reg_bit_field_reg_off,
7784                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7785                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7786                 (void *)&cmd_write_reg_bit_field_value,
7787                 NULL,
7788         },
7789 };
7790
7791 /* *** WRITE PORT REGISTER BIT *** */
7792 struct cmd_write_reg_bit_result {
7793         cmdline_fixed_string_t write;
7794         cmdline_fixed_string_t regbit;
7795         portid_t port_id;
7796         uint32_t reg_off;
7797         uint8_t bit_pos;
7798         uint8_t value;
7799 };
7800
7801 static void
7802 cmd_write_reg_bit_parsed(void *parsed_result,
7803                          __attribute__((unused)) struct cmdline *cl,
7804                          __attribute__((unused)) void *data)
7805 {
7806         struct cmd_write_reg_bit_result *res = parsed_result;
7807         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7808 }
7809
7810 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7811         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7812                                  "write");
7813 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7814         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7815                                  regbit, "regbit");
7816 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7817         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7818 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7819         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7820 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7821         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7822 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7823         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7824
7825 cmdline_parse_inst_t cmd_write_reg_bit = {
7826         .f = cmd_write_reg_bit_parsed,
7827         .data = NULL,
7828         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7829                 "0 <= bit_x <= 31",
7830         .tokens = {
7831                 (void *)&cmd_write_reg_bit_write,
7832                 (void *)&cmd_write_reg_bit_regbit,
7833                 (void *)&cmd_write_reg_bit_port_id,
7834                 (void *)&cmd_write_reg_bit_reg_off,
7835                 (void *)&cmd_write_reg_bit_bit_pos,
7836                 (void *)&cmd_write_reg_bit_value,
7837                 NULL,
7838         },
7839 };
7840
7841 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7842 struct cmd_read_rxd_txd_result {
7843         cmdline_fixed_string_t read;
7844         cmdline_fixed_string_t rxd_txd;
7845         portid_t port_id;
7846         uint16_t queue_id;
7847         uint16_t desc_id;
7848 };
7849
7850 static void
7851 cmd_read_rxd_txd_parsed(void *parsed_result,
7852                         __attribute__((unused)) struct cmdline *cl,
7853                         __attribute__((unused)) void *data)
7854 {
7855         struct cmd_read_rxd_txd_result *res = parsed_result;
7856
7857         if (!strcmp(res->rxd_txd, "rxd"))
7858                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7859         else if (!strcmp(res->rxd_txd, "txd"))
7860                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7861 }
7862
7863 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7864         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7865 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7866         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7867                                  "rxd#txd");
7868 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7869         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7870 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7871         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7872 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7873         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7874
7875 cmdline_parse_inst_t cmd_read_rxd_txd = {
7876         .f = cmd_read_rxd_txd_parsed,
7877         .data = NULL,
7878         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7879         .tokens = {
7880                 (void *)&cmd_read_rxd_txd_read,
7881                 (void *)&cmd_read_rxd_txd_rxd_txd,
7882                 (void *)&cmd_read_rxd_txd_port_id,
7883                 (void *)&cmd_read_rxd_txd_queue_id,
7884                 (void *)&cmd_read_rxd_txd_desc_id,
7885                 NULL,
7886         },
7887 };
7888
7889 /* *** QUIT *** */
7890 struct cmd_quit_result {
7891         cmdline_fixed_string_t quit;
7892 };
7893
7894 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7895                             struct cmdline *cl,
7896                             __attribute__((unused)) void *data)
7897 {
7898         cmdline_quit(cl);
7899 }
7900
7901 cmdline_parse_token_string_t cmd_quit_quit =
7902         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7903
7904 cmdline_parse_inst_t cmd_quit = {
7905         .f = cmd_quit_parsed,
7906         .data = NULL,
7907         .help_str = "quit: Exit application",
7908         .tokens = {
7909                 (void *)&cmd_quit_quit,
7910                 NULL,
7911         },
7912 };
7913
7914 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7915 struct cmd_mac_addr_result {
7916         cmdline_fixed_string_t mac_addr_cmd;
7917         cmdline_fixed_string_t what;
7918         uint16_t port_num;
7919         struct rte_ether_addr address;
7920 };
7921
7922 static void cmd_mac_addr_parsed(void *parsed_result,
7923                 __attribute__((unused)) struct cmdline *cl,
7924                 __attribute__((unused)) void *data)
7925 {
7926         struct cmd_mac_addr_result *res = parsed_result;
7927         int ret;
7928
7929         if (strcmp(res->what, "add") == 0)
7930                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7931         else if (strcmp(res->what, "set") == 0)
7932                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7933                                                        &res->address);
7934         else
7935                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7936
7937         /* check the return value and print it if is < 0 */
7938         if(ret < 0)
7939                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7940
7941 }
7942
7943 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7944         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7945                                 "mac_addr");
7946 cmdline_parse_token_string_t cmd_mac_addr_what =
7947         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7948                                 "add#remove#set");
7949 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7950                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7951                                         UINT16);
7952 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7953                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7954
7955 cmdline_parse_inst_t cmd_mac_addr = {
7956         .f = cmd_mac_addr_parsed,
7957         .data = (void *)0,
7958         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7959                         "Add/Remove/Set MAC address on port_id",
7960         .tokens = {
7961                 (void *)&cmd_mac_addr_cmd,
7962                 (void *)&cmd_mac_addr_what,
7963                 (void *)&cmd_mac_addr_portnum,
7964                 (void *)&cmd_mac_addr_addr,
7965                 NULL,
7966         },
7967 };
7968
7969 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
7970 struct cmd_eth_peer_result {
7971         cmdline_fixed_string_t set;
7972         cmdline_fixed_string_t eth_peer;
7973         portid_t port_id;
7974         cmdline_fixed_string_t peer_addr;
7975 };
7976
7977 static void cmd_set_eth_peer_parsed(void *parsed_result,
7978                         __attribute__((unused)) struct cmdline *cl,
7979                         __attribute__((unused)) void *data)
7980 {
7981                 struct cmd_eth_peer_result *res = parsed_result;
7982
7983                 if (test_done == 0) {
7984                         printf("Please stop forwarding first\n");
7985                         return;
7986                 }
7987                 if (!strcmp(res->eth_peer, "eth-peer")) {
7988                         set_fwd_eth_peer(res->port_id, res->peer_addr);
7989                         fwd_config_setup();
7990                 }
7991 }
7992 cmdline_parse_token_string_t cmd_eth_peer_set =
7993         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
7994 cmdline_parse_token_string_t cmd_eth_peer =
7995         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
7996 cmdline_parse_token_num_t cmd_eth_peer_port_id =
7997         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
7998 cmdline_parse_token_string_t cmd_eth_peer_addr =
7999         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8000
8001 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8002         .f = cmd_set_eth_peer_parsed,
8003         .data = NULL,
8004         .help_str = "set eth-peer <port_id> <peer_mac>",
8005         .tokens = {
8006                 (void *)&cmd_eth_peer_set,
8007                 (void *)&cmd_eth_peer,
8008                 (void *)&cmd_eth_peer_port_id,
8009                 (void *)&cmd_eth_peer_addr,
8010                 NULL,
8011         },
8012 };
8013
8014 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8015 struct cmd_set_qmap_result {
8016         cmdline_fixed_string_t set;
8017         cmdline_fixed_string_t qmap;
8018         cmdline_fixed_string_t what;
8019         portid_t port_id;
8020         uint16_t queue_id;
8021         uint8_t map_value;
8022 };
8023
8024 static void
8025 cmd_set_qmap_parsed(void *parsed_result,
8026                        __attribute__((unused)) struct cmdline *cl,
8027                        __attribute__((unused)) void *data)
8028 {
8029         struct cmd_set_qmap_result *res = parsed_result;
8030         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8031
8032         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8033 }
8034
8035 cmdline_parse_token_string_t cmd_setqmap_set =
8036         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8037                                  set, "set");
8038 cmdline_parse_token_string_t cmd_setqmap_qmap =
8039         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8040                                  qmap, "stat_qmap");
8041 cmdline_parse_token_string_t cmd_setqmap_what =
8042         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8043                                  what, "tx#rx");
8044 cmdline_parse_token_num_t cmd_setqmap_portid =
8045         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8046                               port_id, UINT16);
8047 cmdline_parse_token_num_t cmd_setqmap_queueid =
8048         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8049                               queue_id, UINT16);
8050 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8051         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8052                               map_value, UINT8);
8053
8054 cmdline_parse_inst_t cmd_set_qmap = {
8055         .f = cmd_set_qmap_parsed,
8056         .data = NULL,
8057         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8058                 "Set statistics mapping value on tx|rx queue_id of port_id",
8059         .tokens = {
8060                 (void *)&cmd_setqmap_set,
8061                 (void *)&cmd_setqmap_qmap,
8062                 (void *)&cmd_setqmap_what,
8063                 (void *)&cmd_setqmap_portid,
8064                 (void *)&cmd_setqmap_queueid,
8065                 (void *)&cmd_setqmap_mapvalue,
8066                 NULL,
8067         },
8068 };
8069
8070 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8071 struct cmd_set_xstats_hide_zero_result {
8072         cmdline_fixed_string_t keyword;
8073         cmdline_fixed_string_t name;
8074         cmdline_fixed_string_t on_off;
8075 };
8076
8077 static void
8078 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8079                         __attribute__((unused)) struct cmdline *cl,
8080                         __attribute__((unused)) void *data)
8081 {
8082         struct cmd_set_xstats_hide_zero_result *res;
8083         uint16_t on_off = 0;
8084
8085         res = parsed_result;
8086         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8087         set_xstats_hide_zero(on_off);
8088 }
8089
8090 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8091         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8092                                  keyword, "set");
8093 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8094         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8095                                  name, "xstats-hide-zero");
8096 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8097         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8098                                  on_off, "on#off");
8099
8100 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8101         .f = cmd_set_xstats_hide_zero_parsed,
8102         .data = NULL,
8103         .help_str = "set xstats-hide-zero on|off",
8104         .tokens = {
8105                 (void *)&cmd_set_xstats_hide_zero_keyword,
8106                 (void *)&cmd_set_xstats_hide_zero_name,
8107                 (void *)&cmd_set_xstats_hide_zero_on_off,
8108                 NULL,
8109         },
8110 };
8111
8112 /* *** CONFIGURE UNICAST HASH TABLE *** */
8113 struct cmd_set_uc_hash_table {
8114         cmdline_fixed_string_t set;
8115         cmdline_fixed_string_t port;
8116         portid_t port_id;
8117         cmdline_fixed_string_t what;
8118         struct rte_ether_addr address;
8119         cmdline_fixed_string_t mode;
8120 };
8121
8122 static void
8123 cmd_set_uc_hash_parsed(void *parsed_result,
8124                        __attribute__((unused)) struct cmdline *cl,
8125                        __attribute__((unused)) void *data)
8126 {
8127         int ret=0;
8128         struct cmd_set_uc_hash_table *res = parsed_result;
8129
8130         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8131
8132         if (strcmp(res->what, "uta") == 0)
8133                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8134                                                 &res->address,(uint8_t)is_on);
8135         if (ret < 0)
8136                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8137
8138 }
8139
8140 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8141         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8142                                  set, "set");
8143 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8144         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8145                                  port, "port");
8146 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8147         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8148                               port_id, UINT16);
8149 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8150         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8151                                  what, "uta");
8152 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8153         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8154                                 address);
8155 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8156         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8157                                  mode, "on#off");
8158
8159 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8160         .f = cmd_set_uc_hash_parsed,
8161         .data = NULL,
8162         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8163         .tokens = {
8164                 (void *)&cmd_set_uc_hash_set,
8165                 (void *)&cmd_set_uc_hash_port,
8166                 (void *)&cmd_set_uc_hash_portid,
8167                 (void *)&cmd_set_uc_hash_what,
8168                 (void *)&cmd_set_uc_hash_mac,
8169                 (void *)&cmd_set_uc_hash_mode,
8170                 NULL,
8171         },
8172 };
8173
8174 struct cmd_set_uc_all_hash_table {
8175         cmdline_fixed_string_t set;
8176         cmdline_fixed_string_t port;
8177         portid_t port_id;
8178         cmdline_fixed_string_t what;
8179         cmdline_fixed_string_t value;
8180         cmdline_fixed_string_t mode;
8181 };
8182
8183 static void
8184 cmd_set_uc_all_hash_parsed(void *parsed_result,
8185                        __attribute__((unused)) struct cmdline *cl,
8186                        __attribute__((unused)) void *data)
8187 {
8188         int ret=0;
8189         struct cmd_set_uc_all_hash_table *res = parsed_result;
8190
8191         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8192
8193         if ((strcmp(res->what, "uta") == 0) &&
8194                 (strcmp(res->value, "all") == 0))
8195                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8196         if (ret < 0)
8197                 printf("bad unicast hash table parameter,"
8198                         "return code = %d \n", ret);
8199 }
8200
8201 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8202         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8203                                  set, "set");
8204 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8205         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8206                                  port, "port");
8207 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8208         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8209                               port_id, UINT16);
8210 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8211         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8212                                  what, "uta");
8213 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8214         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8215                                 value,"all");
8216 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8217         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8218                                  mode, "on#off");
8219
8220 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8221         .f = cmd_set_uc_all_hash_parsed,
8222         .data = NULL,
8223         .help_str = "set port <port_id> uta all on|off",
8224         .tokens = {
8225                 (void *)&cmd_set_uc_all_hash_set,
8226                 (void *)&cmd_set_uc_all_hash_port,
8227                 (void *)&cmd_set_uc_all_hash_portid,
8228                 (void *)&cmd_set_uc_all_hash_what,
8229                 (void *)&cmd_set_uc_all_hash_value,
8230                 (void *)&cmd_set_uc_all_hash_mode,
8231                 NULL,
8232         },
8233 };
8234
8235 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8236 struct cmd_set_vf_macvlan_filter {
8237         cmdline_fixed_string_t set;
8238         cmdline_fixed_string_t port;
8239         portid_t port_id;
8240         cmdline_fixed_string_t vf;
8241         uint8_t vf_id;
8242         struct rte_ether_addr address;
8243         cmdline_fixed_string_t filter_type;
8244         cmdline_fixed_string_t mode;
8245 };
8246
8247 static void
8248 cmd_set_vf_macvlan_parsed(void *parsed_result,
8249                        __attribute__((unused)) struct cmdline *cl,
8250                        __attribute__((unused)) void *data)
8251 {
8252         int is_on, ret = 0;
8253         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8254         struct rte_eth_mac_filter filter;
8255
8256         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8257
8258         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8259
8260         /* set VF MAC filter */
8261         filter.is_vf = 1;
8262
8263         /* set VF ID */
8264         filter.dst_id = res->vf_id;
8265
8266         if (!strcmp(res->filter_type, "exact-mac"))
8267                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8268         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8269                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8270         else if (!strcmp(res->filter_type, "hashmac"))
8271                 filter.filter_type = RTE_MAC_HASH_MATCH;
8272         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8273                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8274
8275         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8276
8277         if (is_on)
8278                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8279                                         RTE_ETH_FILTER_MACVLAN,
8280                                         RTE_ETH_FILTER_ADD,
8281                                          &filter);
8282         else
8283                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8284                                         RTE_ETH_FILTER_MACVLAN,
8285                                         RTE_ETH_FILTER_DELETE,
8286                                         &filter);
8287
8288         if (ret < 0)
8289                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8290
8291 }
8292
8293 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8294         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8295                                  set, "set");
8296 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8297         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8298                                  port, "port");
8299 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8300         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8301                               port_id, UINT16);
8302 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8303         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8304                                  vf, "vf");
8305 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8306         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8307                                 vf_id, UINT8);
8308 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8309         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8310                                 address);
8311 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8312         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8313                                 filter_type, "exact-mac#exact-mac-vlan"
8314                                 "#hashmac#hashmac-vlan");
8315 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8316         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8317                                  mode, "on#off");
8318
8319 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8320         .f = cmd_set_vf_macvlan_parsed,
8321         .data = NULL,
8322         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8323                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8324                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8325                 "hash match rule: hash match of MAC and exact match of VLAN",
8326         .tokens = {
8327                 (void *)&cmd_set_vf_macvlan_set,
8328                 (void *)&cmd_set_vf_macvlan_port,
8329                 (void *)&cmd_set_vf_macvlan_portid,
8330                 (void *)&cmd_set_vf_macvlan_vf,
8331                 (void *)&cmd_set_vf_macvlan_vf_id,
8332                 (void *)&cmd_set_vf_macvlan_mac,
8333                 (void *)&cmd_set_vf_macvlan_filter_type,
8334                 (void *)&cmd_set_vf_macvlan_mode,
8335                 NULL,
8336         },
8337 };
8338
8339 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8340 struct cmd_set_vf_traffic {
8341         cmdline_fixed_string_t set;
8342         cmdline_fixed_string_t port;
8343         portid_t port_id;
8344         cmdline_fixed_string_t vf;
8345         uint8_t vf_id;
8346         cmdline_fixed_string_t what;
8347         cmdline_fixed_string_t mode;
8348 };
8349
8350 static void
8351 cmd_set_vf_traffic_parsed(void *parsed_result,
8352                        __attribute__((unused)) struct cmdline *cl,
8353                        __attribute__((unused)) void *data)
8354 {
8355         struct cmd_set_vf_traffic *res = parsed_result;
8356         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8357         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8358
8359         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8360 }
8361
8362 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8363         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8364                                  set, "set");
8365 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8366         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8367                                  port, "port");
8368 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8369         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8370                               port_id, UINT16);
8371 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8372         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8373                                  vf, "vf");
8374 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8375         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8376                               vf_id, UINT8);
8377 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8378         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8379                                  what, "tx#rx");
8380 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8381         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8382                                  mode, "on#off");
8383
8384 cmdline_parse_inst_t cmd_set_vf_traffic = {
8385         .f = cmd_set_vf_traffic_parsed,
8386         .data = NULL,
8387         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8388         .tokens = {
8389                 (void *)&cmd_setvf_traffic_set,
8390                 (void *)&cmd_setvf_traffic_port,
8391                 (void *)&cmd_setvf_traffic_portid,
8392                 (void *)&cmd_setvf_traffic_vf,
8393                 (void *)&cmd_setvf_traffic_vfid,
8394                 (void *)&cmd_setvf_traffic_what,
8395                 (void *)&cmd_setvf_traffic_mode,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** CONFIGURE VF RECEIVE MODE *** */
8401 struct cmd_set_vf_rxmode {
8402         cmdline_fixed_string_t set;
8403         cmdline_fixed_string_t port;
8404         portid_t port_id;
8405         cmdline_fixed_string_t vf;
8406         uint8_t vf_id;
8407         cmdline_fixed_string_t what;
8408         cmdline_fixed_string_t mode;
8409         cmdline_fixed_string_t on;
8410 };
8411
8412 static void
8413 cmd_set_vf_rxmode_parsed(void *parsed_result,
8414                        __attribute__((unused)) struct cmdline *cl,
8415                        __attribute__((unused)) void *data)
8416 {
8417         int ret = -ENOTSUP;
8418         uint16_t rx_mode = 0;
8419         struct cmd_set_vf_rxmode *res = parsed_result;
8420
8421         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8422         if (!strcmp(res->what,"rxmode")) {
8423                 if (!strcmp(res->mode, "AUPE"))
8424                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
8425                 else if (!strcmp(res->mode, "ROPE"))
8426                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
8427                 else if (!strcmp(res->mode, "BAM"))
8428                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
8429                 else if (!strncmp(res->mode, "MPE",3))
8430                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
8431         }
8432
8433         RTE_SET_USED(is_on);
8434
8435 #ifdef RTE_LIBRTE_IXGBE_PMD
8436         if (ret == -ENOTSUP)
8437                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8438                                                   rx_mode, (uint8_t)is_on);
8439 #endif
8440 #ifdef RTE_LIBRTE_BNXT_PMD
8441         if (ret == -ENOTSUP)
8442                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8443                                                  rx_mode, (uint8_t)is_on);
8444 #endif
8445         if (ret < 0)
8446                 printf("bad VF receive mode parameter, return code = %d \n",
8447                 ret);
8448 }
8449
8450 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8452                                  set, "set");
8453 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8455                                  port, "port");
8456 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8457         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8458                               port_id, UINT16);
8459 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8461                                  vf, "vf");
8462 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8463         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8464                               vf_id, UINT8);
8465 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8466         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8467                                  what, "rxmode");
8468 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8469         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8470                                  mode, "AUPE#ROPE#BAM#MPE");
8471 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8473                                  on, "on#off");
8474
8475 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8476         .f = cmd_set_vf_rxmode_parsed,
8477         .data = NULL,
8478         .help_str = "set port <port_id> vf <vf_id> rxmode "
8479                 "AUPE|ROPE|BAM|MPE on|off",
8480         .tokens = {
8481                 (void *)&cmd_set_vf_rxmode_set,
8482                 (void *)&cmd_set_vf_rxmode_port,
8483                 (void *)&cmd_set_vf_rxmode_portid,
8484                 (void *)&cmd_set_vf_rxmode_vf,
8485                 (void *)&cmd_set_vf_rxmode_vfid,
8486                 (void *)&cmd_set_vf_rxmode_what,
8487                 (void *)&cmd_set_vf_rxmode_mode,
8488                 (void *)&cmd_set_vf_rxmode_on,
8489                 NULL,
8490         },
8491 };
8492
8493 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8494 struct cmd_vf_mac_addr_result {
8495         cmdline_fixed_string_t mac_addr_cmd;
8496         cmdline_fixed_string_t what;
8497         cmdline_fixed_string_t port;
8498         uint16_t port_num;
8499         cmdline_fixed_string_t vf;
8500         uint8_t vf_num;
8501         struct rte_ether_addr address;
8502 };
8503
8504 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8505                 __attribute__((unused)) struct cmdline *cl,
8506                 __attribute__((unused)) void *data)
8507 {
8508         struct cmd_vf_mac_addr_result *res = parsed_result;
8509         int ret = -ENOTSUP;
8510
8511         if (strcmp(res->what, "add") != 0)
8512                 return;
8513
8514 #ifdef RTE_LIBRTE_I40E_PMD
8515         if (ret == -ENOTSUP)
8516                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8517                                                    &res->address);
8518 #endif
8519 #ifdef RTE_LIBRTE_BNXT_PMD
8520         if (ret == -ENOTSUP)
8521                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8522                                                 res->vf_num);
8523 #endif
8524
8525         if(ret < 0)
8526                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8527
8528 }
8529
8530 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8531         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8532                                 mac_addr_cmd,"mac_addr");
8533 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8534         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8535                                 what,"add");
8536 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8537         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8538                                 port,"port");
8539 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8540         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8541                                 port_num, UINT16);
8542 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8543         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8544                                 vf,"vf");
8545 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8546         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8547                                 vf_num, UINT8);
8548 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8549         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8550                                 address);
8551
8552 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8553         .f = cmd_vf_mac_addr_parsed,
8554         .data = (void *)0,
8555         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8556                 "Add MAC address filtering for a VF on port_id",
8557         .tokens = {
8558                 (void *)&cmd_vf_mac_addr_cmd,
8559                 (void *)&cmd_vf_mac_addr_what,
8560                 (void *)&cmd_vf_mac_addr_port,
8561                 (void *)&cmd_vf_mac_addr_portnum,
8562                 (void *)&cmd_vf_mac_addr_vf,
8563                 (void *)&cmd_vf_mac_addr_vfnum,
8564                 (void *)&cmd_vf_mac_addr_addr,
8565                 NULL,
8566         },
8567 };
8568
8569 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8570 struct cmd_vf_rx_vlan_filter {
8571         cmdline_fixed_string_t rx_vlan;
8572         cmdline_fixed_string_t what;
8573         uint16_t vlan_id;
8574         cmdline_fixed_string_t port;
8575         portid_t port_id;
8576         cmdline_fixed_string_t vf;
8577         uint64_t vf_mask;
8578 };
8579
8580 static void
8581 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8582                           __attribute__((unused)) struct cmdline *cl,
8583                           __attribute__((unused)) void *data)
8584 {
8585         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8586         int ret = -ENOTSUP;
8587
8588         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8589
8590 #ifdef RTE_LIBRTE_IXGBE_PMD
8591         if (ret == -ENOTSUP)
8592                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8593                                 res->vlan_id, res->vf_mask, is_add);
8594 #endif
8595 #ifdef RTE_LIBRTE_I40E_PMD
8596         if (ret == -ENOTSUP)
8597                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8598                                 res->vlan_id, res->vf_mask, is_add);
8599 #endif
8600 #ifdef RTE_LIBRTE_BNXT_PMD
8601         if (ret == -ENOTSUP)
8602                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8603                                 res->vlan_id, res->vf_mask, is_add);
8604 #endif
8605
8606         switch (ret) {
8607         case 0:
8608                 break;
8609         case -EINVAL:
8610                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8611                                 res->vlan_id, res->vf_mask);
8612                 break;
8613         case -ENODEV:
8614                 printf("invalid port_id %d\n", res->port_id);
8615                 break;
8616         case -ENOTSUP:
8617                 printf("function not implemented or supported\n");
8618                 break;
8619         default:
8620                 printf("programming error: (%s)\n", strerror(-ret));
8621         }
8622 }
8623
8624 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8625         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8626                                  rx_vlan, "rx_vlan");
8627 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8628         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8629                                  what, "add#rm");
8630 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8631         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8632                               vlan_id, UINT16);
8633 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8634         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8635                                  port, "port");
8636 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8637         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8638                               port_id, UINT16);
8639 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8640         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8641                                  vf, "vf");
8642 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8643         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8644                               vf_mask, UINT64);
8645
8646 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8647         .f = cmd_vf_rx_vlan_filter_parsed,
8648         .data = NULL,
8649         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8650                 "(vf_mask = hexadecimal VF mask)",
8651         .tokens = {
8652                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8653                 (void *)&cmd_vf_rx_vlan_filter_what,
8654                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8655                 (void *)&cmd_vf_rx_vlan_filter_port,
8656                 (void *)&cmd_vf_rx_vlan_filter_portid,
8657                 (void *)&cmd_vf_rx_vlan_filter_vf,
8658                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8659                 NULL,
8660         },
8661 };
8662
8663 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8664 struct cmd_queue_rate_limit_result {
8665         cmdline_fixed_string_t set;
8666         cmdline_fixed_string_t port;
8667         uint16_t port_num;
8668         cmdline_fixed_string_t queue;
8669         uint8_t queue_num;
8670         cmdline_fixed_string_t rate;
8671         uint16_t rate_num;
8672 };
8673
8674 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8675                 __attribute__((unused)) struct cmdline *cl,
8676                 __attribute__((unused)) void *data)
8677 {
8678         struct cmd_queue_rate_limit_result *res = parsed_result;
8679         int ret = 0;
8680
8681         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8682                 && (strcmp(res->queue, "queue") == 0)
8683                 && (strcmp(res->rate, "rate") == 0))
8684                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8685                                         res->rate_num);
8686         if (ret < 0)
8687                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8688
8689 }
8690
8691 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8692         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8693                                 set, "set");
8694 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8695         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8696                                 port, "port");
8697 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8698         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8699                                 port_num, UINT16);
8700 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8701         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8702                                 queue, "queue");
8703 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8704         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8705                                 queue_num, UINT8);
8706 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8707         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8708                                 rate, "rate");
8709 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8710         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8711                                 rate_num, UINT16);
8712
8713 cmdline_parse_inst_t cmd_queue_rate_limit = {
8714         .f = cmd_queue_rate_limit_parsed,
8715         .data = (void *)0,
8716         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8717                 "Set rate limit for a queue on port_id",
8718         .tokens = {
8719                 (void *)&cmd_queue_rate_limit_set,
8720                 (void *)&cmd_queue_rate_limit_port,
8721                 (void *)&cmd_queue_rate_limit_portnum,
8722                 (void *)&cmd_queue_rate_limit_queue,
8723                 (void *)&cmd_queue_rate_limit_queuenum,
8724                 (void *)&cmd_queue_rate_limit_rate,
8725                 (void *)&cmd_queue_rate_limit_ratenum,
8726                 NULL,
8727         },
8728 };
8729
8730 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8731 struct cmd_vf_rate_limit_result {
8732         cmdline_fixed_string_t set;
8733         cmdline_fixed_string_t port;
8734         uint16_t port_num;
8735         cmdline_fixed_string_t vf;
8736         uint8_t vf_num;
8737         cmdline_fixed_string_t rate;
8738         uint16_t rate_num;
8739         cmdline_fixed_string_t q_msk;
8740         uint64_t q_msk_val;
8741 };
8742
8743 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8744                 __attribute__((unused)) struct cmdline *cl,
8745                 __attribute__((unused)) void *data)
8746 {
8747         struct cmd_vf_rate_limit_result *res = parsed_result;
8748         int ret = 0;
8749
8750         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8751                 && (strcmp(res->vf, "vf") == 0)
8752                 && (strcmp(res->rate, "rate") == 0)
8753                 && (strcmp(res->q_msk, "queue_mask") == 0))
8754                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8755                                         res->rate_num, res->q_msk_val);
8756         if (ret < 0)
8757                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8758
8759 }
8760
8761 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8762         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8763                                 set, "set");
8764 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8765         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8766                                 port, "port");
8767 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8768         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8769                                 port_num, UINT16);
8770 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8771         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8772                                 vf, "vf");
8773 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8774         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8775                                 vf_num, UINT8);
8776 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8777         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8778                                 rate, "rate");
8779 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8780         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8781                                 rate_num, UINT16);
8782 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8783         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8784                                 q_msk, "queue_mask");
8785 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8786         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8787                                 q_msk_val, UINT64);
8788
8789 cmdline_parse_inst_t cmd_vf_rate_limit = {
8790         .f = cmd_vf_rate_limit_parsed,
8791         .data = (void *)0,
8792         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8793                 "queue_mask <queue_mask_value>: "
8794                 "Set rate limit for queues of VF on port_id",
8795         .tokens = {
8796                 (void *)&cmd_vf_rate_limit_set,
8797                 (void *)&cmd_vf_rate_limit_port,
8798                 (void *)&cmd_vf_rate_limit_portnum,
8799                 (void *)&cmd_vf_rate_limit_vf,
8800                 (void *)&cmd_vf_rate_limit_vfnum,
8801                 (void *)&cmd_vf_rate_limit_rate,
8802                 (void *)&cmd_vf_rate_limit_ratenum,
8803                 (void *)&cmd_vf_rate_limit_q_msk,
8804                 (void *)&cmd_vf_rate_limit_q_msk_val,
8805                 NULL,
8806         },
8807 };
8808
8809 /* *** ADD TUNNEL FILTER OF A PORT *** */
8810 struct cmd_tunnel_filter_result {
8811         cmdline_fixed_string_t cmd;
8812         cmdline_fixed_string_t what;
8813         portid_t port_id;
8814         struct rte_ether_addr outer_mac;
8815         struct rte_ether_addr inner_mac;
8816         cmdline_ipaddr_t ip_value;
8817         uint16_t inner_vlan;
8818         cmdline_fixed_string_t tunnel_type;
8819         cmdline_fixed_string_t filter_type;
8820         uint32_t tenant_id;
8821         uint16_t queue_num;
8822 };
8823
8824 static void
8825 cmd_tunnel_filter_parsed(void *parsed_result,
8826                           __attribute__((unused)) struct cmdline *cl,
8827                           __attribute__((unused)) void *data)
8828 {
8829         struct cmd_tunnel_filter_result *res = parsed_result;
8830         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8831         int ret = 0;
8832
8833         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8834
8835         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8836         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8837         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8838
8839         if (res->ip_value.family == AF_INET) {
8840                 tunnel_filter_conf.ip_addr.ipv4_addr =
8841                         res->ip_value.addr.ipv4.s_addr;
8842                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8843         } else {
8844                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8845                         &(res->ip_value.addr.ipv6),
8846                         sizeof(struct in6_addr));
8847                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8848         }
8849
8850         if (!strcmp(res->filter_type, "imac-ivlan"))
8851                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8852         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8853                 tunnel_filter_conf.filter_type =
8854                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8855         else if (!strcmp(res->filter_type, "imac-tenid"))
8856                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8857         else if (!strcmp(res->filter_type, "imac"))
8858                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8859         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8860                 tunnel_filter_conf.filter_type =
8861                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
8862         else if (!strcmp(res->filter_type, "oip"))
8863                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
8864         else if (!strcmp(res->filter_type, "iip"))
8865                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
8866         else {
8867                 printf("The filter type is not supported");
8868                 return;
8869         }
8870
8871         if (!strcmp(res->tunnel_type, "vxlan"))
8872                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8873         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
8874                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
8875         else if (!strcmp(res->tunnel_type, "nvgre"))
8876                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8877         else if (!strcmp(res->tunnel_type, "ipingre"))
8878                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8879         else {
8880                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8881                 return;
8882         }
8883
8884         tunnel_filter_conf.tenant_id = res->tenant_id;
8885         tunnel_filter_conf.queue_id = res->queue_num;
8886         if (!strcmp(res->what, "add"))
8887                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8888                                         RTE_ETH_FILTER_TUNNEL,
8889                                         RTE_ETH_FILTER_ADD,
8890                                         &tunnel_filter_conf);
8891         else
8892                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8893                                         RTE_ETH_FILTER_TUNNEL,
8894                                         RTE_ETH_FILTER_DELETE,
8895                                         &tunnel_filter_conf);
8896         if (ret < 0)
8897                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8898                                 strerror(-ret));
8899
8900 }
8901 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8902         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8903         cmd, "tunnel_filter");
8904 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8905         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8906         what, "add#rm");
8907 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8908         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8909         port_id, UINT16);
8910 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8911         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8912         outer_mac);
8913 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8914         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8915         inner_mac);
8916 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8917         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8918         inner_vlan, UINT16);
8919 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8920         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8921         ip_value);
8922 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8923         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8924         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
8925
8926 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8927         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8928         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8929                 "imac#omac-imac-tenid");
8930 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8931         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8932         tenant_id, UINT32);
8933 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8934         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8935         queue_num, UINT16);
8936
8937 cmdline_parse_inst_t cmd_tunnel_filter = {
8938         .f = cmd_tunnel_filter_parsed,
8939         .data = (void *)0,
8940         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8941                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8942                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8943                 "<queue_id>: Add/Rm tunnel filter of a port",
8944         .tokens = {
8945                 (void *)&cmd_tunnel_filter_cmd,
8946                 (void *)&cmd_tunnel_filter_what,
8947                 (void *)&cmd_tunnel_filter_port_id,
8948                 (void *)&cmd_tunnel_filter_outer_mac,
8949                 (void *)&cmd_tunnel_filter_inner_mac,
8950                 (void *)&cmd_tunnel_filter_ip_value,
8951                 (void *)&cmd_tunnel_filter_innner_vlan,
8952                 (void *)&cmd_tunnel_filter_tunnel_type,
8953                 (void *)&cmd_tunnel_filter_filter_type,
8954                 (void *)&cmd_tunnel_filter_tenant_id,
8955                 (void *)&cmd_tunnel_filter_queue_num,
8956                 NULL,
8957         },
8958 };
8959
8960 /* *** CONFIGURE TUNNEL UDP PORT *** */
8961 struct cmd_tunnel_udp_config {
8962         cmdline_fixed_string_t cmd;
8963         cmdline_fixed_string_t what;
8964         uint16_t udp_port;
8965         portid_t port_id;
8966 };
8967
8968 static void
8969 cmd_tunnel_udp_config_parsed(void *parsed_result,
8970                           __attribute__((unused)) struct cmdline *cl,
8971                           __attribute__((unused)) void *data)
8972 {
8973         struct cmd_tunnel_udp_config *res = parsed_result;
8974         struct rte_eth_udp_tunnel tunnel_udp;
8975         int ret;
8976
8977         tunnel_udp.udp_port = res->udp_port;
8978
8979         if (!strcmp(res->cmd, "rx_vxlan_port"))
8980                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8981
8982         if (!strcmp(res->what, "add"))
8983                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8984                                                       &tunnel_udp);
8985         else
8986                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8987                                                          &tunnel_udp);
8988
8989         if (ret < 0)
8990                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8991 }
8992
8993 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8994         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8995                                 cmd, "rx_vxlan_port");
8996 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8997         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8998                                 what, "add#rm");
8999 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9000         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9001                                 udp_port, UINT16);
9002 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9003         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9004                                 port_id, UINT16);
9005
9006 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9007         .f = cmd_tunnel_udp_config_parsed,
9008         .data = (void *)0,
9009         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9010                 "Add/Remove a tunneling UDP port filter",
9011         .tokens = {
9012                 (void *)&cmd_tunnel_udp_config_cmd,
9013                 (void *)&cmd_tunnel_udp_config_what,
9014                 (void *)&cmd_tunnel_udp_config_udp_port,
9015                 (void *)&cmd_tunnel_udp_config_port_id,
9016                 NULL,
9017         },
9018 };
9019
9020 struct cmd_config_tunnel_udp_port {
9021         cmdline_fixed_string_t port;
9022         cmdline_fixed_string_t config;
9023         portid_t port_id;
9024         cmdline_fixed_string_t udp_tunnel_port;
9025         cmdline_fixed_string_t action;
9026         cmdline_fixed_string_t tunnel_type;
9027         uint16_t udp_port;
9028 };
9029
9030 static void
9031 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9032                                __attribute__((unused)) struct cmdline *cl,
9033                                __attribute__((unused)) void *data)
9034 {
9035         struct cmd_config_tunnel_udp_port *res = parsed_result;
9036         struct rte_eth_udp_tunnel tunnel_udp;
9037         int ret = 0;
9038
9039         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9040                 return;
9041
9042         tunnel_udp.udp_port = res->udp_port;
9043
9044         if (!strcmp(res->tunnel_type, "vxlan")) {
9045                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9046         } else if (!strcmp(res->tunnel_type, "geneve")) {
9047                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9048         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9049                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9050         } else {
9051                 printf("Invalid tunnel type\n");
9052                 return;
9053         }
9054
9055         if (!strcmp(res->action, "add"))
9056                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9057                                                       &tunnel_udp);
9058         else
9059                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9060                                                          &tunnel_udp);
9061
9062         if (ret < 0)
9063                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9064 }
9065
9066 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9067         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9068                                  "port");
9069 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9070         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9071                                  "config");
9072 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9073         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9074                               UINT16);
9075 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9076         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9077                                  udp_tunnel_port,
9078                                  "udp_tunnel_port");
9079 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9080         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9081                                  "add#rm");
9082 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9083         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9084                                  "vxlan#geneve#vxlan-gpe");
9085 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9086         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9087                               UINT16);
9088
9089 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9090         .f = cmd_cfg_tunnel_udp_port_parsed,
9091         .data = NULL,
9092         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9093         .tokens = {
9094                 (void *)&cmd_config_tunnel_udp_port_port,
9095                 (void *)&cmd_config_tunnel_udp_port_config,
9096                 (void *)&cmd_config_tunnel_udp_port_port_id,
9097                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9098                 (void *)&cmd_config_tunnel_udp_port_action,
9099                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9100                 (void *)&cmd_config_tunnel_udp_port_value,
9101                 NULL,
9102         },
9103 };
9104
9105 /* *** GLOBAL CONFIG *** */
9106 struct cmd_global_config_result {
9107         cmdline_fixed_string_t cmd;
9108         portid_t port_id;
9109         cmdline_fixed_string_t cfg_type;
9110         uint8_t len;
9111 };
9112
9113 static void
9114 cmd_global_config_parsed(void *parsed_result,
9115                          __attribute__((unused)) struct cmdline *cl,
9116                          __attribute__((unused)) void *data)
9117 {
9118         struct cmd_global_config_result *res = parsed_result;
9119         struct rte_eth_global_cfg conf;
9120         int ret;
9121
9122         memset(&conf, 0, sizeof(conf));
9123         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9124         conf.cfg.gre_key_len = res->len;
9125         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9126                                       RTE_ETH_FILTER_SET, &conf);
9127         if (ret != 0)
9128                 printf("Global config error\n");
9129 }
9130
9131 cmdline_parse_token_string_t cmd_global_config_cmd =
9132         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9133                 "global_config");
9134 cmdline_parse_token_num_t cmd_global_config_port_id =
9135         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9136                                UINT16);
9137 cmdline_parse_token_string_t cmd_global_config_type =
9138         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9139                 cfg_type, "gre-key-len");
9140 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9141         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9142                 len, UINT8);
9143
9144 cmdline_parse_inst_t cmd_global_config = {
9145         .f = cmd_global_config_parsed,
9146         .data = (void *)NULL,
9147         .help_str = "global_config <port_id> gre-key-len <key_len>",
9148         .tokens = {
9149                 (void *)&cmd_global_config_cmd,
9150                 (void *)&cmd_global_config_port_id,
9151                 (void *)&cmd_global_config_type,
9152                 (void *)&cmd_global_config_gre_key_len,
9153                 NULL,
9154         },
9155 };
9156
9157 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9158 struct cmd_set_mirror_mask_result {
9159         cmdline_fixed_string_t set;
9160         cmdline_fixed_string_t port;
9161         portid_t port_id;
9162         cmdline_fixed_string_t mirror;
9163         uint8_t rule_id;
9164         cmdline_fixed_string_t what;
9165         cmdline_fixed_string_t value;
9166         cmdline_fixed_string_t dstpool;
9167         uint8_t dstpool_id;
9168         cmdline_fixed_string_t on;
9169 };
9170
9171 cmdline_parse_token_string_t cmd_mirror_mask_set =
9172         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9173                                 set, "set");
9174 cmdline_parse_token_string_t cmd_mirror_mask_port =
9175         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9176                                 port, "port");
9177 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9178         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9179                                 port_id, UINT16);
9180 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9181         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9182                                 mirror, "mirror-rule");
9183 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9184         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9185                                 rule_id, UINT8);
9186 cmdline_parse_token_string_t cmd_mirror_mask_what =
9187         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9188                                 what, "pool-mirror-up#pool-mirror-down"
9189                                       "#vlan-mirror");
9190 cmdline_parse_token_string_t cmd_mirror_mask_value =
9191         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9192                                 value, NULL);
9193 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9194         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9195                                 dstpool, "dst-pool");
9196 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9197         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9198                                 dstpool_id, UINT8);
9199 cmdline_parse_token_string_t cmd_mirror_mask_on =
9200         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9201                                 on, "on#off");
9202
9203 static void
9204 cmd_set_mirror_mask_parsed(void *parsed_result,
9205                        __attribute__((unused)) struct cmdline *cl,
9206                        __attribute__((unused)) void *data)
9207 {
9208         int ret,nb_item,i;
9209         struct cmd_set_mirror_mask_result *res = parsed_result;
9210         struct rte_eth_mirror_conf mr_conf;
9211
9212         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9213
9214         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9215
9216         mr_conf.dst_pool = res->dstpool_id;
9217
9218         if (!strcmp(res->what, "pool-mirror-up")) {
9219                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9220                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9221         } else if (!strcmp(res->what, "pool-mirror-down")) {
9222                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9223                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9224         } else if (!strcmp(res->what, "vlan-mirror")) {
9225                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9226                 nb_item = parse_item_list(res->value, "vlan",
9227                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9228                 if (nb_item <= 0)
9229                         return;
9230
9231                 for (i = 0; i < nb_item; i++) {
9232                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9233                                 printf("Invalid vlan_id: must be < 4096\n");
9234                                 return;
9235                         }
9236
9237                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9238                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9239                 }
9240         }
9241
9242         if (!strcmp(res->on, "on"))
9243                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9244                                                 res->rule_id, 1);
9245         else
9246                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9247                                                 res->rule_id, 0);
9248         if (ret < 0)
9249                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9250 }
9251
9252 cmdline_parse_inst_t cmd_set_mirror_mask = {
9253                 .f = cmd_set_mirror_mask_parsed,
9254                 .data = NULL,
9255                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9256                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9257                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9258                 .tokens = {
9259                         (void *)&cmd_mirror_mask_set,
9260                         (void *)&cmd_mirror_mask_port,
9261                         (void *)&cmd_mirror_mask_portid,
9262                         (void *)&cmd_mirror_mask_mirror,
9263                         (void *)&cmd_mirror_mask_ruleid,
9264                         (void *)&cmd_mirror_mask_what,
9265                         (void *)&cmd_mirror_mask_value,
9266                         (void *)&cmd_mirror_mask_dstpool,
9267                         (void *)&cmd_mirror_mask_poolid,
9268                         (void *)&cmd_mirror_mask_on,
9269                         NULL,
9270                 },
9271 };
9272
9273 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9274 struct cmd_set_mirror_link_result {
9275         cmdline_fixed_string_t set;
9276         cmdline_fixed_string_t port;
9277         portid_t port_id;
9278         cmdline_fixed_string_t mirror;
9279         uint8_t rule_id;
9280         cmdline_fixed_string_t what;
9281         cmdline_fixed_string_t dstpool;
9282         uint8_t dstpool_id;
9283         cmdline_fixed_string_t on;
9284 };
9285
9286 cmdline_parse_token_string_t cmd_mirror_link_set =
9287         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9288                                  set, "set");
9289 cmdline_parse_token_string_t cmd_mirror_link_port =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9291                                 port, "port");
9292 cmdline_parse_token_num_t cmd_mirror_link_portid =
9293         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9294                                 port_id, UINT16);
9295 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9296         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9297                                 mirror, "mirror-rule");
9298 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9299         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9300                             rule_id, UINT8);
9301 cmdline_parse_token_string_t cmd_mirror_link_what =
9302         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9303                                 what, "uplink-mirror#downlink-mirror");
9304 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9305         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9306                                 dstpool, "dst-pool");
9307 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9308         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9309                                 dstpool_id, UINT8);
9310 cmdline_parse_token_string_t cmd_mirror_link_on =
9311         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9312                                 on, "on#off");
9313
9314 static void
9315 cmd_set_mirror_link_parsed(void *parsed_result,
9316                        __attribute__((unused)) struct cmdline *cl,
9317                        __attribute__((unused)) void *data)
9318 {
9319         int ret;
9320         struct cmd_set_mirror_link_result *res = parsed_result;
9321         struct rte_eth_mirror_conf mr_conf;
9322
9323         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9324         if (!strcmp(res->what, "uplink-mirror"))
9325                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9326         else
9327                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9328
9329         mr_conf.dst_pool = res->dstpool_id;
9330
9331         if (!strcmp(res->on, "on"))
9332                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9333                                                 res->rule_id, 1);
9334         else
9335                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9336                                                 res->rule_id, 0);
9337
9338         /* check the return value and print it if is < 0 */
9339         if (ret < 0)
9340                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9341
9342 }
9343
9344 cmdline_parse_inst_t cmd_set_mirror_link = {
9345                 .f = cmd_set_mirror_link_parsed,
9346                 .data = NULL,
9347                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9348                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9349                 .tokens = {
9350                         (void *)&cmd_mirror_link_set,
9351                         (void *)&cmd_mirror_link_port,
9352                         (void *)&cmd_mirror_link_portid,
9353                         (void *)&cmd_mirror_link_mirror,
9354                         (void *)&cmd_mirror_link_ruleid,
9355                         (void *)&cmd_mirror_link_what,
9356                         (void *)&cmd_mirror_link_dstpool,
9357                         (void *)&cmd_mirror_link_poolid,
9358                         (void *)&cmd_mirror_link_on,
9359                         NULL,
9360                 },
9361 };
9362
9363 /* *** RESET VM MIRROR RULE *** */
9364 struct cmd_rm_mirror_rule_result {
9365         cmdline_fixed_string_t reset;
9366         cmdline_fixed_string_t port;
9367         portid_t port_id;
9368         cmdline_fixed_string_t mirror;
9369         uint8_t rule_id;
9370 };
9371
9372 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9373         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9374                                  reset, "reset");
9375 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9376         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9377                                 port, "port");
9378 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9379         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9380                                 port_id, UINT16);
9381 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9382         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9383                                 mirror, "mirror-rule");
9384 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9385         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9386                                 rule_id, UINT8);
9387
9388 static void
9389 cmd_reset_mirror_rule_parsed(void *parsed_result,
9390                        __attribute__((unused)) struct cmdline *cl,
9391                        __attribute__((unused)) void *data)
9392 {
9393         int ret;
9394         struct cmd_set_mirror_link_result *res = parsed_result;
9395         /* check rule_id */
9396         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9397         if(ret < 0)
9398                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9399 }
9400
9401 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9402                 .f = cmd_reset_mirror_rule_parsed,
9403                 .data = NULL,
9404                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9405                 .tokens = {
9406                         (void *)&cmd_rm_mirror_rule_reset,
9407                         (void *)&cmd_rm_mirror_rule_port,
9408                         (void *)&cmd_rm_mirror_rule_portid,
9409                         (void *)&cmd_rm_mirror_rule_mirror,
9410                         (void *)&cmd_rm_mirror_rule_ruleid,
9411                         NULL,
9412                 },
9413 };
9414
9415 /* ******************************************************************************** */
9416
9417 struct cmd_dump_result {
9418         cmdline_fixed_string_t dump;
9419 };
9420
9421 static void
9422 dump_struct_sizes(void)
9423 {
9424 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9425         DUMP_SIZE(struct rte_mbuf);
9426         DUMP_SIZE(struct rte_mempool);
9427         DUMP_SIZE(struct rte_ring);
9428 #undef DUMP_SIZE
9429 }
9430
9431 static void cmd_dump_parsed(void *parsed_result,
9432                             __attribute__((unused)) struct cmdline *cl,
9433                             __attribute__((unused)) void *data)
9434 {
9435         struct cmd_dump_result *res = parsed_result;
9436
9437         if (!strcmp(res->dump, "dump_physmem"))
9438                 rte_dump_physmem_layout(stdout);
9439         else if (!strcmp(res->dump, "dump_memzone"))
9440                 rte_memzone_dump(stdout);
9441         else if (!strcmp(res->dump, "dump_struct_sizes"))
9442                 dump_struct_sizes();
9443         else if (!strcmp(res->dump, "dump_ring"))
9444                 rte_ring_list_dump(stdout);
9445         else if (!strcmp(res->dump, "dump_mempool"))
9446                 rte_mempool_list_dump(stdout);
9447         else if (!strcmp(res->dump, "dump_devargs"))
9448                 rte_devargs_dump(stdout);
9449         else if (!strcmp(res->dump, "dump_log_types"))
9450                 rte_log_dump(stdout);
9451 }
9452
9453 cmdline_parse_token_string_t cmd_dump_dump =
9454         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9455                 "dump_physmem#"
9456                 "dump_memzone#"
9457                 "dump_struct_sizes#"
9458                 "dump_ring#"
9459                 "dump_mempool#"
9460                 "dump_devargs#"
9461                 "dump_log_types");
9462
9463 cmdline_parse_inst_t cmd_dump = {
9464         .f = cmd_dump_parsed,  /* function to call */
9465         .data = NULL,      /* 2nd arg of func */
9466         .help_str = "Dump status",
9467         .tokens = {        /* token list, NULL terminated */
9468                 (void *)&cmd_dump_dump,
9469                 NULL,
9470         },
9471 };
9472
9473 /* ******************************************************************************** */
9474
9475 struct cmd_dump_one_result {
9476         cmdline_fixed_string_t dump;
9477         cmdline_fixed_string_t name;
9478 };
9479
9480 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9481                                 __attribute__((unused)) void *data)
9482 {
9483         struct cmd_dump_one_result *res = parsed_result;
9484
9485         if (!strcmp(res->dump, "dump_ring")) {
9486                 struct rte_ring *r;
9487                 r = rte_ring_lookup(res->name);
9488                 if (r == NULL) {
9489                         cmdline_printf(cl, "Cannot find ring\n");
9490                         return;
9491                 }
9492                 rte_ring_dump(stdout, r);
9493         } else if (!strcmp(res->dump, "dump_mempool")) {
9494                 struct rte_mempool *mp;
9495                 mp = rte_mempool_lookup(res->name);
9496                 if (mp == NULL) {
9497                         cmdline_printf(cl, "Cannot find mempool\n");
9498                         return;
9499                 }
9500                 rte_mempool_dump(stdout, mp);
9501         }
9502 }
9503
9504 cmdline_parse_token_string_t cmd_dump_one_dump =
9505         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9506                                  "dump_ring#dump_mempool");
9507
9508 cmdline_parse_token_string_t cmd_dump_one_name =
9509         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9510
9511 cmdline_parse_inst_t cmd_dump_one = {
9512         .f = cmd_dump_one_parsed,  /* function to call */
9513         .data = NULL,      /* 2nd arg of func */
9514         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9515         .tokens = {        /* token list, NULL terminated */
9516                 (void *)&cmd_dump_one_dump,
9517                 (void *)&cmd_dump_one_name,
9518                 NULL,
9519         },
9520 };
9521
9522 /* *** Add/Del syn filter *** */
9523 struct cmd_syn_filter_result {
9524         cmdline_fixed_string_t filter;
9525         portid_t port_id;
9526         cmdline_fixed_string_t ops;
9527         cmdline_fixed_string_t priority;
9528         cmdline_fixed_string_t high;
9529         cmdline_fixed_string_t queue;
9530         uint16_t queue_id;
9531 };
9532
9533 static void
9534 cmd_syn_filter_parsed(void *parsed_result,
9535                         __attribute__((unused)) struct cmdline *cl,
9536                         __attribute__((unused)) void *data)
9537 {
9538         struct cmd_syn_filter_result *res = parsed_result;
9539         struct rte_eth_syn_filter syn_filter;
9540         int ret = 0;
9541
9542         ret = rte_eth_dev_filter_supported(res->port_id,
9543                                         RTE_ETH_FILTER_SYN);
9544         if (ret < 0) {
9545                 printf("syn filter is not supported on port %u.\n",
9546                                 res->port_id);
9547                 return;
9548         }
9549
9550         memset(&syn_filter, 0, sizeof(syn_filter));
9551
9552         if (!strcmp(res->ops, "add")) {
9553                 if (!strcmp(res->high, "high"))
9554                         syn_filter.hig_pri = 1;
9555                 else
9556                         syn_filter.hig_pri = 0;
9557
9558                 syn_filter.queue = res->queue_id;
9559                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9560                                                 RTE_ETH_FILTER_SYN,
9561                                                 RTE_ETH_FILTER_ADD,
9562                                                 &syn_filter);
9563         } else
9564                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9565                                                 RTE_ETH_FILTER_SYN,
9566                                                 RTE_ETH_FILTER_DELETE,
9567                                                 &syn_filter);
9568
9569         if (ret < 0)
9570                 printf("syn filter programming error: (%s)\n",
9571                                 strerror(-ret));
9572 }
9573
9574 cmdline_parse_token_string_t cmd_syn_filter_filter =
9575         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9576         filter, "syn_filter");
9577 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9578         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9579         port_id, UINT16);
9580 cmdline_parse_token_string_t cmd_syn_filter_ops =
9581         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9582         ops, "add#del");
9583 cmdline_parse_token_string_t cmd_syn_filter_priority =
9584         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9585                                 priority, "priority");
9586 cmdline_parse_token_string_t cmd_syn_filter_high =
9587         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9588                                 high, "high#low");
9589 cmdline_parse_token_string_t cmd_syn_filter_queue =
9590         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9591                                 queue, "queue");
9592 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9593         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9594                                 queue_id, UINT16);
9595
9596 cmdline_parse_inst_t cmd_syn_filter = {
9597         .f = cmd_syn_filter_parsed,
9598         .data = NULL,
9599         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9600                 "<queue_id>: Add/Delete syn filter",
9601         .tokens = {
9602                 (void *)&cmd_syn_filter_filter,
9603                 (void *)&cmd_syn_filter_port_id,
9604                 (void *)&cmd_syn_filter_ops,
9605                 (void *)&cmd_syn_filter_priority,
9606                 (void *)&cmd_syn_filter_high,
9607                 (void *)&cmd_syn_filter_queue,
9608                 (void *)&cmd_syn_filter_queue_id,
9609                 NULL,
9610         },
9611 };
9612
9613 /* *** queue region set *** */
9614 struct cmd_queue_region_result {
9615         cmdline_fixed_string_t set;
9616         cmdline_fixed_string_t port;
9617         portid_t port_id;
9618         cmdline_fixed_string_t cmd;
9619         cmdline_fixed_string_t region;
9620         uint8_t  region_id;
9621         cmdline_fixed_string_t queue_start_index;
9622         uint8_t  queue_id;
9623         cmdline_fixed_string_t queue_num;
9624         uint8_t  queue_num_value;
9625 };
9626
9627 static void
9628 cmd_queue_region_parsed(void *parsed_result,
9629                         __attribute__((unused)) struct cmdline *cl,
9630                         __attribute__((unused)) void *data)
9631 {
9632         struct cmd_queue_region_result *res = parsed_result;
9633         int ret = -ENOTSUP;
9634 #ifdef RTE_LIBRTE_I40E_PMD
9635         struct rte_pmd_i40e_queue_region_conf region_conf;
9636         enum rte_pmd_i40e_queue_region_op op_type;
9637 #endif
9638
9639         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9640                 return;
9641
9642 #ifdef RTE_LIBRTE_I40E_PMD
9643         memset(&region_conf, 0, sizeof(region_conf));
9644         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9645         region_conf.region_id = res->region_id;
9646         region_conf.queue_num = res->queue_num_value;
9647         region_conf.queue_start_index = res->queue_id;
9648
9649         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9650                                 op_type, &region_conf);
9651 #endif
9652
9653         switch (ret) {
9654         case 0:
9655                 break;
9656         case -ENOTSUP:
9657                 printf("function not implemented or supported\n");
9658                 break;
9659         default:
9660                 printf("queue region config error: (%s)\n", strerror(-ret));
9661         }
9662 }
9663
9664 cmdline_parse_token_string_t cmd_queue_region_set =
9665 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9666                 set, "set");
9667 cmdline_parse_token_string_t cmd_queue_region_port =
9668         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9669 cmdline_parse_token_num_t cmd_queue_region_port_id =
9670         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9671                                 port_id, UINT16);
9672 cmdline_parse_token_string_t cmd_queue_region_cmd =
9673         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9674                                  cmd, "queue-region");
9675 cmdline_parse_token_string_t cmd_queue_region_id =
9676         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9677                                 region, "region_id");
9678 cmdline_parse_token_num_t cmd_queue_region_index =
9679         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9680                                 region_id, UINT8);
9681 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9682         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9683                                 queue_start_index, "queue_start_index");
9684 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9685         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9686                                 queue_id, UINT8);
9687 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9688         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9689                                 queue_num, "queue_num");
9690 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9691         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9692                                 queue_num_value, UINT8);
9693
9694 cmdline_parse_inst_t cmd_queue_region = {
9695         .f = cmd_queue_region_parsed,
9696         .data = NULL,
9697         .help_str = "set port <port_id> queue-region region_id <value> "
9698                 "queue_start_index <value> queue_num <value>: Set a queue region",
9699         .tokens = {
9700                 (void *)&cmd_queue_region_set,
9701                 (void *)&cmd_queue_region_port,
9702                 (void *)&cmd_queue_region_port_id,
9703                 (void *)&cmd_queue_region_cmd,
9704                 (void *)&cmd_queue_region_id,
9705                 (void *)&cmd_queue_region_index,
9706                 (void *)&cmd_queue_region_queue_start_index,
9707                 (void *)&cmd_queue_region_queue_id,
9708                 (void *)&cmd_queue_region_queue_num,
9709                 (void *)&cmd_queue_region_queue_num_value,
9710                 NULL,
9711         },
9712 };
9713
9714 /* *** queue region and flowtype set *** */
9715 struct cmd_region_flowtype_result {
9716         cmdline_fixed_string_t set;
9717         cmdline_fixed_string_t port;
9718         portid_t port_id;
9719         cmdline_fixed_string_t cmd;
9720         cmdline_fixed_string_t region;
9721         uint8_t  region_id;
9722         cmdline_fixed_string_t flowtype;
9723         uint8_t  flowtype_id;
9724 };
9725
9726 static void
9727 cmd_region_flowtype_parsed(void *parsed_result,
9728                         __attribute__((unused)) struct cmdline *cl,
9729                         __attribute__((unused)) void *data)
9730 {
9731         struct cmd_region_flowtype_result *res = parsed_result;
9732         int ret = -ENOTSUP;
9733 #ifdef RTE_LIBRTE_I40E_PMD
9734         struct rte_pmd_i40e_queue_region_conf region_conf;
9735         enum rte_pmd_i40e_queue_region_op op_type;
9736 #endif
9737
9738         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9739                 return;
9740
9741 #ifdef RTE_LIBRTE_I40E_PMD
9742         memset(&region_conf, 0, sizeof(region_conf));
9743
9744         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9745         region_conf.region_id = res->region_id;
9746         region_conf.hw_flowtype = res->flowtype_id;
9747
9748         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9749                         op_type, &region_conf);
9750 #endif
9751
9752         switch (ret) {
9753         case 0:
9754                 break;
9755         case -ENOTSUP:
9756                 printf("function not implemented or supported\n");
9757                 break;
9758         default:
9759                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9760         }
9761 }
9762
9763 cmdline_parse_token_string_t cmd_region_flowtype_set =
9764 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9765                                 set, "set");
9766 cmdline_parse_token_string_t cmd_region_flowtype_port =
9767         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9768                                 port, "port");
9769 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9770         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9771                                 port_id, UINT16);
9772 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9773         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9774                                 cmd, "queue-region");
9775 cmdline_parse_token_string_t cmd_region_flowtype_index =
9776         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9777                                 region, "region_id");
9778 cmdline_parse_token_num_t cmd_region_flowtype_id =
9779         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9780                                 region_id, UINT8);
9781 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9782         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9783                                 flowtype, "flowtype");
9784 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9785         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9786                                 flowtype_id, UINT8);
9787 cmdline_parse_inst_t cmd_region_flowtype = {
9788         .f = cmd_region_flowtype_parsed,
9789         .data = NULL,
9790         .help_str = "set port <port_id> queue-region region_id <value> "
9791                 "flowtype <value>: Set a flowtype region index",
9792         .tokens = {
9793                 (void *)&cmd_region_flowtype_set,
9794                 (void *)&cmd_region_flowtype_port,
9795                 (void *)&cmd_region_flowtype_port_index,
9796                 (void *)&cmd_region_flowtype_cmd,
9797                 (void *)&cmd_region_flowtype_index,
9798                 (void *)&cmd_region_flowtype_id,
9799                 (void *)&cmd_region_flowtype_flow_index,
9800                 (void *)&cmd_region_flowtype_flow_id,
9801                 NULL,
9802         },
9803 };
9804
9805 /* *** User Priority (UP) to queue region (region_id) set *** */
9806 struct cmd_user_priority_region_result {
9807         cmdline_fixed_string_t set;
9808         cmdline_fixed_string_t port;
9809         portid_t port_id;
9810         cmdline_fixed_string_t cmd;
9811         cmdline_fixed_string_t user_priority;
9812         uint8_t  user_priority_id;
9813         cmdline_fixed_string_t region;
9814         uint8_t  region_id;
9815 };
9816
9817 static void
9818 cmd_user_priority_region_parsed(void *parsed_result,
9819                         __attribute__((unused)) struct cmdline *cl,
9820                         __attribute__((unused)) void *data)
9821 {
9822         struct cmd_user_priority_region_result *res = parsed_result;
9823         int ret = -ENOTSUP;
9824 #ifdef RTE_LIBRTE_I40E_PMD
9825         struct rte_pmd_i40e_queue_region_conf region_conf;
9826         enum rte_pmd_i40e_queue_region_op op_type;
9827 #endif
9828
9829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9830                 return;
9831
9832 #ifdef RTE_LIBRTE_I40E_PMD
9833         memset(&region_conf, 0, sizeof(region_conf));
9834         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9835         region_conf.user_priority = res->user_priority_id;
9836         region_conf.region_id = res->region_id;
9837
9838         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9839                                 op_type, &region_conf);
9840 #endif
9841
9842         switch (ret) {
9843         case 0:
9844                 break;
9845         case -ENOTSUP:
9846                 printf("function not implemented or supported\n");
9847                 break;
9848         default:
9849                 printf("user_priority region config error: (%s)\n",
9850                                 strerror(-ret));
9851         }
9852 }
9853
9854 cmdline_parse_token_string_t cmd_user_priority_region_set =
9855         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9856                                 set, "set");
9857 cmdline_parse_token_string_t cmd_user_priority_region_port =
9858         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9859                                 port, "port");
9860 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9861         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9862                                 port_id, UINT16);
9863 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
9864         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9865                                 cmd, "queue-region");
9866 cmdline_parse_token_string_t cmd_user_priority_region_UP =
9867         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9868                                 user_priority, "UP");
9869 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
9870         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9871                                 user_priority_id, UINT8);
9872 cmdline_parse_token_string_t cmd_user_priority_region_region =
9873         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9874                                 region, "region_id");
9875 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
9876         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
9877                                 region_id, UINT8);
9878
9879 cmdline_parse_inst_t cmd_user_priority_region = {
9880         .f = cmd_user_priority_region_parsed,
9881         .data = NULL,
9882         .help_str = "set port <port_id> queue-region UP <value> "
9883                 "region_id <value>: Set the mapping of User Priority (UP) "
9884                 "to queue region (region_id) ",
9885         .tokens = {
9886                 (void *)&cmd_user_priority_region_set,
9887                 (void *)&cmd_user_priority_region_port,
9888                 (void *)&cmd_user_priority_region_port_index,
9889                 (void *)&cmd_user_priority_region_cmd,
9890                 (void *)&cmd_user_priority_region_UP,
9891                 (void *)&cmd_user_priority_region_UP_id,
9892                 (void *)&cmd_user_priority_region_region,
9893                 (void *)&cmd_user_priority_region_region_id,
9894                 NULL,
9895         },
9896 };
9897
9898 /* *** flush all queue region related configuration *** */
9899 struct cmd_flush_queue_region_result {
9900         cmdline_fixed_string_t set;
9901         cmdline_fixed_string_t port;
9902         portid_t port_id;
9903         cmdline_fixed_string_t cmd;
9904         cmdline_fixed_string_t flush;
9905         cmdline_fixed_string_t what;
9906 };
9907
9908 static void
9909 cmd_flush_queue_region_parsed(void *parsed_result,
9910                         __attribute__((unused)) struct cmdline *cl,
9911                         __attribute__((unused)) void *data)
9912 {
9913         struct cmd_flush_queue_region_result *res = parsed_result;
9914         int ret = -ENOTSUP;
9915 #ifdef RTE_LIBRTE_I40E_PMD
9916         struct rte_pmd_i40e_queue_region_conf region_conf;
9917         enum rte_pmd_i40e_queue_region_op op_type;
9918 #endif
9919
9920         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9921                 return;
9922
9923 #ifdef RTE_LIBRTE_I40E_PMD
9924         memset(&region_conf, 0, sizeof(region_conf));
9925
9926         if (strcmp(res->what, "on") == 0)
9927                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
9928         else
9929                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
9930
9931         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9932                                 op_type, &region_conf);
9933 #endif
9934
9935         switch (ret) {
9936         case 0:
9937                 break;
9938         case -ENOTSUP:
9939                 printf("function not implemented or supported\n");
9940                 break;
9941         default:
9942                 printf("queue region config flush error: (%s)\n",
9943                                 strerror(-ret));
9944         }
9945 }
9946
9947 cmdline_parse_token_string_t cmd_flush_queue_region_set =
9948         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9949                                 set, "set");
9950 cmdline_parse_token_string_t cmd_flush_queue_region_port =
9951         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9952                                 port, "port");
9953 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
9954         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
9955                                 port_id, UINT16);
9956 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
9957         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9958                                 cmd, "queue-region");
9959 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9960         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9961                                 flush, "flush");
9962 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9963         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9964                                 what, "on#off");
9965
9966 cmdline_parse_inst_t cmd_flush_queue_region = {
9967         .f = cmd_flush_queue_region_parsed,
9968         .data = NULL,
9969         .help_str = "set port <port_id> queue-region flush on|off"
9970                 ": flush all queue region related configuration",
9971         .tokens = {
9972                 (void *)&cmd_flush_queue_region_set,
9973                 (void *)&cmd_flush_queue_region_port,
9974                 (void *)&cmd_flush_queue_region_port_index,
9975                 (void *)&cmd_flush_queue_region_cmd,
9976                 (void *)&cmd_flush_queue_region_flush,
9977                 (void *)&cmd_flush_queue_region_what,
9978                 NULL,
9979         },
9980 };
9981
9982 /* *** get all queue region related configuration info *** */
9983 struct cmd_show_queue_region_info {
9984         cmdline_fixed_string_t show;
9985         cmdline_fixed_string_t port;
9986         portid_t port_id;
9987         cmdline_fixed_string_t cmd;
9988 };
9989
9990 static void
9991 cmd_show_queue_region_info_parsed(void *parsed_result,
9992                         __attribute__((unused)) struct cmdline *cl,
9993                         __attribute__((unused)) void *data)
9994 {
9995         struct cmd_show_queue_region_info *res = parsed_result;
9996         int ret = -ENOTSUP;
9997 #ifdef RTE_LIBRTE_I40E_PMD
9998         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9999         enum rte_pmd_i40e_queue_region_op op_type;
10000 #endif
10001
10002         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10003                 return;
10004
10005 #ifdef RTE_LIBRTE_I40E_PMD
10006         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10007
10008         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10009
10010         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10011                                         op_type, &rte_pmd_regions);
10012
10013         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10014 #endif
10015
10016         switch (ret) {
10017         case 0:
10018                 break;
10019         case -ENOTSUP:
10020                 printf("function not implemented or supported\n");
10021                 break;
10022         default:
10023                 printf("queue region config info show error: (%s)\n",
10024                                 strerror(-ret));
10025         }
10026 }
10027
10028 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10029 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10030                                 show, "show");
10031 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10032         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10033                                 port, "port");
10034 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10035         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10036                                 port_id, UINT16);
10037 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10038         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10039                                 cmd, "queue-region");
10040
10041 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10042         .f = cmd_show_queue_region_info_parsed,
10043         .data = NULL,
10044         .help_str = "show port <port_id> queue-region"
10045                 ": show all queue region related configuration info",
10046         .tokens = {
10047                 (void *)&cmd_show_queue_region_info_get,
10048                 (void *)&cmd_show_queue_region_info_port,
10049                 (void *)&cmd_show_queue_region_info_port_index,
10050                 (void *)&cmd_show_queue_region_info_cmd,
10051                 NULL,
10052         },
10053 };
10054
10055 /* *** ADD/REMOVE A 2tuple FILTER *** */
10056 struct cmd_2tuple_filter_result {
10057         cmdline_fixed_string_t filter;
10058         portid_t port_id;
10059         cmdline_fixed_string_t ops;
10060         cmdline_fixed_string_t dst_port;
10061         uint16_t dst_port_value;
10062         cmdline_fixed_string_t protocol;
10063         uint8_t protocol_value;
10064         cmdline_fixed_string_t mask;
10065         uint8_t  mask_value;
10066         cmdline_fixed_string_t tcp_flags;
10067         uint8_t tcp_flags_value;
10068         cmdline_fixed_string_t priority;
10069         uint8_t  priority_value;
10070         cmdline_fixed_string_t queue;
10071         uint16_t  queue_id;
10072 };
10073
10074 static void
10075 cmd_2tuple_filter_parsed(void *parsed_result,
10076                         __attribute__((unused)) struct cmdline *cl,
10077                         __attribute__((unused)) void *data)
10078 {
10079         struct rte_eth_ntuple_filter filter;
10080         struct cmd_2tuple_filter_result *res = parsed_result;
10081         int ret = 0;
10082
10083         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10084         if (ret < 0) {
10085                 printf("ntuple filter is not supported on port %u.\n",
10086                         res->port_id);
10087                 return;
10088         }
10089
10090         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10091
10092         filter.flags = RTE_2TUPLE_FLAGS;
10093         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10094         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10095         filter.proto = res->protocol_value;
10096         filter.priority = res->priority_value;
10097         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10098                 printf("nonzero tcp_flags is only meaningful"
10099                         " when protocol is TCP.\n");
10100                 return;
10101         }
10102         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10103                 printf("invalid TCP flags.\n");
10104                 return;
10105         }
10106
10107         if (res->tcp_flags_value != 0) {
10108                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10109                 filter.tcp_flags = res->tcp_flags_value;
10110         }
10111
10112         /* need convert to big endian. */
10113         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10114         filter.queue = res->queue_id;
10115
10116         if (!strcmp(res->ops, "add"))
10117                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10118                                 RTE_ETH_FILTER_NTUPLE,
10119                                 RTE_ETH_FILTER_ADD,
10120                                 &filter);
10121         else
10122                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10123                                 RTE_ETH_FILTER_NTUPLE,
10124                                 RTE_ETH_FILTER_DELETE,
10125                                 &filter);
10126         if (ret < 0)
10127                 printf("2tuple filter programming error: (%s)\n",
10128                         strerror(-ret));
10129
10130 }
10131
10132 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10133         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10134                                  filter, "2tuple_filter");
10135 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10136         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10137                                 port_id, UINT16);
10138 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10139         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10140                                  ops, "add#del");
10141 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10142         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10143                                 dst_port, "dst_port");
10144 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10145         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10146                                 dst_port_value, UINT16);
10147 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10148         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10149                                 protocol, "protocol");
10150 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10151         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10152                                 protocol_value, UINT8);
10153 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10154         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10155                                 mask, "mask");
10156 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10157         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10158                                 mask_value, INT8);
10159 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10160         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10161                                 tcp_flags, "tcp_flags");
10162 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10163         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10164                                 tcp_flags_value, UINT8);
10165 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10166         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10167                                 priority, "priority");
10168 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10169         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10170                                 priority_value, UINT8);
10171 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10172         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10173                                 queue, "queue");
10174 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10175         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10176                                 queue_id, UINT16);
10177
10178 cmdline_parse_inst_t cmd_2tuple_filter = {
10179         .f = cmd_2tuple_filter_parsed,
10180         .data = NULL,
10181         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10182                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10183                 "<queue_id>: Add a 2tuple filter",
10184         .tokens = {
10185                 (void *)&cmd_2tuple_filter_filter,
10186                 (void *)&cmd_2tuple_filter_port_id,
10187                 (void *)&cmd_2tuple_filter_ops,
10188                 (void *)&cmd_2tuple_filter_dst_port,
10189                 (void *)&cmd_2tuple_filter_dst_port_value,
10190                 (void *)&cmd_2tuple_filter_protocol,
10191                 (void *)&cmd_2tuple_filter_protocol_value,
10192                 (void *)&cmd_2tuple_filter_mask,
10193                 (void *)&cmd_2tuple_filter_mask_value,
10194                 (void *)&cmd_2tuple_filter_tcp_flags,
10195                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10196                 (void *)&cmd_2tuple_filter_priority,
10197                 (void *)&cmd_2tuple_filter_priority_value,
10198                 (void *)&cmd_2tuple_filter_queue,
10199                 (void *)&cmd_2tuple_filter_queue_id,
10200                 NULL,
10201         },
10202 };
10203
10204 /* *** ADD/REMOVE A 5tuple FILTER *** */
10205 struct cmd_5tuple_filter_result {
10206         cmdline_fixed_string_t filter;
10207         portid_t port_id;
10208         cmdline_fixed_string_t ops;
10209         cmdline_fixed_string_t dst_ip;
10210         cmdline_ipaddr_t dst_ip_value;
10211         cmdline_fixed_string_t src_ip;
10212         cmdline_ipaddr_t src_ip_value;
10213         cmdline_fixed_string_t dst_port;
10214         uint16_t dst_port_value;
10215         cmdline_fixed_string_t src_port;
10216         uint16_t src_port_value;
10217         cmdline_fixed_string_t protocol;
10218         uint8_t protocol_value;
10219         cmdline_fixed_string_t mask;
10220         uint8_t  mask_value;
10221         cmdline_fixed_string_t tcp_flags;
10222         uint8_t tcp_flags_value;
10223         cmdline_fixed_string_t priority;
10224         uint8_t  priority_value;
10225         cmdline_fixed_string_t queue;
10226         uint16_t  queue_id;
10227 };
10228
10229 static void
10230 cmd_5tuple_filter_parsed(void *parsed_result,
10231                         __attribute__((unused)) struct cmdline *cl,
10232                         __attribute__((unused)) void *data)
10233 {
10234         struct rte_eth_ntuple_filter filter;
10235         struct cmd_5tuple_filter_result *res = parsed_result;
10236         int ret = 0;
10237
10238         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10239         if (ret < 0) {
10240                 printf("ntuple filter is not supported on port %u.\n",
10241                         res->port_id);
10242                 return;
10243         }
10244
10245         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10246
10247         filter.flags = RTE_5TUPLE_FLAGS;
10248         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10249         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10250         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10251         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10252         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10253         filter.proto = res->protocol_value;
10254         filter.priority = res->priority_value;
10255         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10256                 printf("nonzero tcp_flags is only meaningful"
10257                         " when protocol is TCP.\n");
10258                 return;
10259         }
10260         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10261                 printf("invalid TCP flags.\n");
10262                 return;
10263         }
10264
10265         if (res->tcp_flags_value != 0) {
10266                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10267                 filter.tcp_flags = res->tcp_flags_value;
10268         }
10269
10270         if (res->dst_ip_value.family == AF_INET)
10271                 /* no need to convert, already big endian. */
10272                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10273         else {
10274                 if (filter.dst_ip_mask == 0) {
10275                         printf("can not support ipv6 involved compare.\n");
10276                         return;
10277                 }
10278                 filter.dst_ip = 0;
10279         }
10280
10281         if (res->src_ip_value.family == AF_INET)
10282                 /* no need to convert, already big endian. */
10283                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10284         else {
10285                 if (filter.src_ip_mask == 0) {
10286                         printf("can not support ipv6 involved compare.\n");
10287                         return;
10288                 }
10289                 filter.src_ip = 0;
10290         }
10291         /* need convert to big endian. */
10292         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10293         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10294         filter.queue = res->queue_id;
10295
10296         if (!strcmp(res->ops, "add"))
10297                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10298                                 RTE_ETH_FILTER_NTUPLE,
10299                                 RTE_ETH_FILTER_ADD,
10300                                 &filter);
10301         else
10302                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10303                                 RTE_ETH_FILTER_NTUPLE,
10304                                 RTE_ETH_FILTER_DELETE,
10305                                 &filter);
10306         if (ret < 0)
10307                 printf("5tuple filter programming error: (%s)\n",
10308                         strerror(-ret));
10309 }
10310
10311 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10312         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10313                                  filter, "5tuple_filter");
10314 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10315         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10316                                 port_id, UINT16);
10317 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10318         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10319                                  ops, "add#del");
10320 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10321         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10322                                 dst_ip, "dst_ip");
10323 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10324         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10325                                 dst_ip_value);
10326 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10327         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10328                                 src_ip, "src_ip");
10329 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10330         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10331                                 src_ip_value);
10332 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10333         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10334                                 dst_port, "dst_port");
10335 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10336         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10337                                 dst_port_value, UINT16);
10338 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10339         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10340                                 src_port, "src_port");
10341 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10342         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10343                                 src_port_value, UINT16);
10344 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10345         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10346                                 protocol, "protocol");
10347 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10348         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10349                                 protocol_value, UINT8);
10350 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10351         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10352                                 mask, "mask");
10353 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10354         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10355                                 mask_value, INT8);
10356 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10357         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10358                                 tcp_flags, "tcp_flags");
10359 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10360         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10361                                 tcp_flags_value, UINT8);
10362 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10363         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10364                                 priority, "priority");
10365 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10366         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10367                                 priority_value, UINT8);
10368 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10369         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10370                                 queue, "queue");
10371 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10372         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10373                                 queue_id, UINT16);
10374
10375 cmdline_parse_inst_t cmd_5tuple_filter = {
10376         .f = cmd_5tuple_filter_parsed,
10377         .data = NULL,
10378         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10379                 "src_ip <value> dst_port <value> src_port <value> "
10380                 "protocol <value>  mask <value> tcp_flags <value> "
10381                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10382         .tokens = {
10383                 (void *)&cmd_5tuple_filter_filter,
10384                 (void *)&cmd_5tuple_filter_port_id,
10385                 (void *)&cmd_5tuple_filter_ops,
10386                 (void *)&cmd_5tuple_filter_dst_ip,
10387                 (void *)&cmd_5tuple_filter_dst_ip_value,
10388                 (void *)&cmd_5tuple_filter_src_ip,
10389                 (void *)&cmd_5tuple_filter_src_ip_value,
10390                 (void *)&cmd_5tuple_filter_dst_port,
10391                 (void *)&cmd_5tuple_filter_dst_port_value,
10392                 (void *)&cmd_5tuple_filter_src_port,
10393                 (void *)&cmd_5tuple_filter_src_port_value,
10394                 (void *)&cmd_5tuple_filter_protocol,
10395                 (void *)&cmd_5tuple_filter_protocol_value,
10396                 (void *)&cmd_5tuple_filter_mask,
10397                 (void *)&cmd_5tuple_filter_mask_value,
10398                 (void *)&cmd_5tuple_filter_tcp_flags,
10399                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10400                 (void *)&cmd_5tuple_filter_priority,
10401                 (void *)&cmd_5tuple_filter_priority_value,
10402                 (void *)&cmd_5tuple_filter_queue,
10403                 (void *)&cmd_5tuple_filter_queue_id,
10404                 NULL,
10405         },
10406 };
10407
10408 /* *** ADD/REMOVE A flex FILTER *** */
10409 struct cmd_flex_filter_result {
10410         cmdline_fixed_string_t filter;
10411         cmdline_fixed_string_t ops;
10412         portid_t port_id;
10413         cmdline_fixed_string_t len;
10414         uint8_t len_value;
10415         cmdline_fixed_string_t bytes;
10416         cmdline_fixed_string_t bytes_value;
10417         cmdline_fixed_string_t mask;
10418         cmdline_fixed_string_t mask_value;
10419         cmdline_fixed_string_t priority;
10420         uint8_t priority_value;
10421         cmdline_fixed_string_t queue;
10422         uint16_t queue_id;
10423 };
10424
10425 static int xdigit2val(unsigned char c)
10426 {
10427         int val;
10428         if (isdigit(c))
10429                 val = c - '0';
10430         else if (isupper(c))
10431                 val = c - 'A' + 10;
10432         else
10433                 val = c - 'a' + 10;
10434         return val;
10435 }
10436
10437 static void
10438 cmd_flex_filter_parsed(void *parsed_result,
10439                           __attribute__((unused)) struct cmdline *cl,
10440                           __attribute__((unused)) void *data)
10441 {
10442         int ret = 0;
10443         struct rte_eth_flex_filter filter;
10444         struct cmd_flex_filter_result *res = parsed_result;
10445         char *bytes_ptr, *mask_ptr;
10446         uint16_t len, i, j = 0;
10447         char c;
10448         int val;
10449         uint8_t byte = 0;
10450
10451         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10452                 printf("the len exceed the max length 128\n");
10453                 return;
10454         }
10455         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10456         filter.len = res->len_value;
10457         filter.priority = res->priority_value;
10458         filter.queue = res->queue_id;
10459         bytes_ptr = res->bytes_value;
10460         mask_ptr = res->mask_value;
10461
10462          /* translate bytes string to array. */
10463         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10464                 (bytes_ptr[1] == 'X')))
10465                 bytes_ptr += 2;
10466         len = strnlen(bytes_ptr, res->len_value * 2);
10467         if (len == 0 || (len % 8 != 0)) {
10468                 printf("please check len and bytes input\n");
10469                 return;
10470         }
10471         for (i = 0; i < len; i++) {
10472                 c = bytes_ptr[i];
10473                 if (isxdigit(c) == 0) {
10474                         /* invalid characters. */
10475                         printf("invalid input\n");
10476                         return;
10477                 }
10478                 val = xdigit2val(c);
10479                 if (i % 2) {
10480                         byte |= val;
10481                         filter.bytes[j] = byte;
10482                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10483                         j++;
10484                         byte = 0;
10485                 } else
10486                         byte |= val << 4;
10487         }
10488         printf("\n");
10489          /* translate mask string to uint8_t array. */
10490         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10491                 (mask_ptr[1] == 'X')))
10492                 mask_ptr += 2;
10493         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10494         if (len == 0) {
10495                 printf("invalid input\n");
10496                 return;
10497         }
10498         j = 0;
10499         byte = 0;
10500         for (i = 0; i < len; i++) {
10501                 c = mask_ptr[i];
10502                 if (isxdigit(c) == 0) {
10503                         /* invalid characters. */
10504                         printf("invalid input\n");
10505                         return;
10506                 }
10507                 val = xdigit2val(c);
10508                 if (i % 2) {
10509                         byte |= val;
10510                         filter.mask[j] = byte;
10511                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10512                         j++;
10513                         byte = 0;
10514                 } else
10515                         byte |= val << 4;
10516         }
10517         printf("\n");
10518
10519         if (!strcmp(res->ops, "add"))
10520                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10521                                 RTE_ETH_FILTER_FLEXIBLE,
10522                                 RTE_ETH_FILTER_ADD,
10523                                 &filter);
10524         else
10525                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10526                                 RTE_ETH_FILTER_FLEXIBLE,
10527                                 RTE_ETH_FILTER_DELETE,
10528                                 &filter);
10529
10530         if (ret < 0)
10531                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10532 }
10533
10534 cmdline_parse_token_string_t cmd_flex_filter_filter =
10535         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10536                                 filter, "flex_filter");
10537 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10538         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10539                                 port_id, UINT16);
10540 cmdline_parse_token_string_t cmd_flex_filter_ops =
10541         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10542                                 ops, "add#del");
10543 cmdline_parse_token_string_t cmd_flex_filter_len =
10544         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10545                                 len, "len");
10546 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10547         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10548                                 len_value, UINT8);
10549 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10550         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10551                                 bytes, "bytes");
10552 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10553         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10554                                 bytes_value, NULL);
10555 cmdline_parse_token_string_t cmd_flex_filter_mask =
10556         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10557                                 mask, "mask");
10558 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10559         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10560                                 mask_value, NULL);
10561 cmdline_parse_token_string_t cmd_flex_filter_priority =
10562         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10563                                 priority, "priority");
10564 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10565         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10566                                 priority_value, UINT8);
10567 cmdline_parse_token_string_t cmd_flex_filter_queue =
10568         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10569                                 queue, "queue");
10570 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10571         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10572                                 queue_id, UINT16);
10573 cmdline_parse_inst_t cmd_flex_filter = {
10574         .f = cmd_flex_filter_parsed,
10575         .data = NULL,
10576         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10577                 "<value> mask <value> priority <value> queue <queue_id>: "
10578                 "Add/Del a flex filter",
10579         .tokens = {
10580                 (void *)&cmd_flex_filter_filter,
10581                 (void *)&cmd_flex_filter_port_id,
10582                 (void *)&cmd_flex_filter_ops,
10583                 (void *)&cmd_flex_filter_len,
10584                 (void *)&cmd_flex_filter_len_value,
10585                 (void *)&cmd_flex_filter_bytes,
10586                 (void *)&cmd_flex_filter_bytes_value,
10587                 (void *)&cmd_flex_filter_mask,
10588                 (void *)&cmd_flex_filter_mask_value,
10589                 (void *)&cmd_flex_filter_priority,
10590                 (void *)&cmd_flex_filter_priority_value,
10591                 (void *)&cmd_flex_filter_queue,
10592                 (void *)&cmd_flex_filter_queue_id,
10593                 NULL,
10594         },
10595 };
10596
10597 /* *** Filters Control *** */
10598
10599 /* *** deal with ethertype filter *** */
10600 struct cmd_ethertype_filter_result {
10601         cmdline_fixed_string_t filter;
10602         portid_t port_id;
10603         cmdline_fixed_string_t ops;
10604         cmdline_fixed_string_t mac;
10605         struct rte_ether_addr mac_addr;
10606         cmdline_fixed_string_t ethertype;
10607         uint16_t ethertype_value;
10608         cmdline_fixed_string_t drop;
10609         cmdline_fixed_string_t queue;
10610         uint16_t  queue_id;
10611 };
10612
10613 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10614         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10615                                  filter, "ethertype_filter");
10616 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10617         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10618                               port_id, UINT16);
10619 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10620         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10621                                  ops, "add#del");
10622 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10623         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10624                                  mac, "mac_addr#mac_ignr");
10625 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10626         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10627                                      mac_addr);
10628 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10629         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10630                                  ethertype, "ethertype");
10631 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10632         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10633                               ethertype_value, UINT16);
10634 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10635         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10636                                  drop, "drop#fwd");
10637 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10638         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10639                                  queue, "queue");
10640 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10641         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10642                               queue_id, UINT16);
10643
10644 static void
10645 cmd_ethertype_filter_parsed(void *parsed_result,
10646                           __attribute__((unused)) struct cmdline *cl,
10647                           __attribute__((unused)) void *data)
10648 {
10649         struct cmd_ethertype_filter_result *res = parsed_result;
10650         struct rte_eth_ethertype_filter filter;
10651         int ret = 0;
10652
10653         ret = rte_eth_dev_filter_supported(res->port_id,
10654                         RTE_ETH_FILTER_ETHERTYPE);
10655         if (ret < 0) {
10656                 printf("ethertype filter is not supported on port %u.\n",
10657                         res->port_id);
10658                 return;
10659         }
10660
10661         memset(&filter, 0, sizeof(filter));
10662         if (!strcmp(res->mac, "mac_addr")) {
10663                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10664                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10665                         sizeof(struct rte_ether_addr));
10666         }
10667         if (!strcmp(res->drop, "drop"))
10668                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10669         filter.ether_type = res->ethertype_value;
10670         filter.queue = res->queue_id;
10671
10672         if (!strcmp(res->ops, "add"))
10673                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10674                                 RTE_ETH_FILTER_ETHERTYPE,
10675                                 RTE_ETH_FILTER_ADD,
10676                                 &filter);
10677         else
10678                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10679                                 RTE_ETH_FILTER_ETHERTYPE,
10680                                 RTE_ETH_FILTER_DELETE,
10681                                 &filter);
10682         if (ret < 0)
10683                 printf("ethertype filter programming error: (%s)\n",
10684                         strerror(-ret));
10685 }
10686
10687 cmdline_parse_inst_t cmd_ethertype_filter = {
10688         .f = cmd_ethertype_filter_parsed,
10689         .data = NULL,
10690         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10691                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10692                 "Add or delete an ethertype filter entry",
10693         .tokens = {
10694                 (void *)&cmd_ethertype_filter_filter,
10695                 (void *)&cmd_ethertype_filter_port_id,
10696                 (void *)&cmd_ethertype_filter_ops,
10697                 (void *)&cmd_ethertype_filter_mac,
10698                 (void *)&cmd_ethertype_filter_mac_addr,
10699                 (void *)&cmd_ethertype_filter_ethertype,
10700                 (void *)&cmd_ethertype_filter_ethertype_value,
10701                 (void *)&cmd_ethertype_filter_drop,
10702                 (void *)&cmd_ethertype_filter_queue,
10703                 (void *)&cmd_ethertype_filter_queue_id,
10704                 NULL,
10705         },
10706 };
10707
10708 /* *** deal with flow director filter *** */
10709 struct cmd_flow_director_result {
10710         cmdline_fixed_string_t flow_director_filter;
10711         portid_t port_id;
10712         cmdline_fixed_string_t mode;
10713         cmdline_fixed_string_t mode_value;
10714         cmdline_fixed_string_t ops;
10715         cmdline_fixed_string_t flow;
10716         cmdline_fixed_string_t flow_type;
10717         cmdline_fixed_string_t ether;
10718         uint16_t ether_type;
10719         cmdline_fixed_string_t src;
10720         cmdline_ipaddr_t ip_src;
10721         uint16_t port_src;
10722         cmdline_fixed_string_t dst;
10723         cmdline_ipaddr_t ip_dst;
10724         uint16_t port_dst;
10725         cmdline_fixed_string_t verify_tag;
10726         uint32_t verify_tag_value;
10727         cmdline_fixed_string_t tos;
10728         uint8_t tos_value;
10729         cmdline_fixed_string_t proto;
10730         uint8_t proto_value;
10731         cmdline_fixed_string_t ttl;
10732         uint8_t ttl_value;
10733         cmdline_fixed_string_t vlan;
10734         uint16_t vlan_value;
10735         cmdline_fixed_string_t flexbytes;
10736         cmdline_fixed_string_t flexbytes_value;
10737         cmdline_fixed_string_t pf_vf;
10738         cmdline_fixed_string_t drop;
10739         cmdline_fixed_string_t queue;
10740         uint16_t  queue_id;
10741         cmdline_fixed_string_t fd_id;
10742         uint32_t  fd_id_value;
10743         cmdline_fixed_string_t mac;
10744         struct rte_ether_addr mac_addr;
10745         cmdline_fixed_string_t tunnel;
10746         cmdline_fixed_string_t tunnel_type;
10747         cmdline_fixed_string_t tunnel_id;
10748         uint32_t tunnel_id_value;
10749         cmdline_fixed_string_t packet;
10750         char filepath[];
10751 };
10752
10753 static inline int
10754 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10755 {
10756         char s[256];
10757         const char *p, *p0 = q_arg;
10758         char *end;
10759         unsigned long int_fld;
10760         char *str_fld[max_num];
10761         int i;
10762         unsigned size;
10763         int ret = -1;
10764
10765         p = strchr(p0, '(');
10766         if (p == NULL)
10767                 return -1;
10768         ++p;
10769         p0 = strchr(p, ')');
10770         if (p0 == NULL)
10771                 return -1;
10772
10773         size = p0 - p;
10774         if (size >= sizeof(s))
10775                 return -1;
10776
10777         snprintf(s, sizeof(s), "%.*s", size, p);
10778         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10779         if (ret < 0 || ret > max_num)
10780                 return -1;
10781         for (i = 0; i < ret; i++) {
10782                 errno = 0;
10783                 int_fld = strtoul(str_fld[i], &end, 0);
10784                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10785                         return -1;
10786                 flexbytes[i] = (uint8_t)int_fld;
10787         }
10788         return ret;
10789 }
10790
10791 static uint16_t
10792 str2flowtype(char *string)
10793 {
10794         uint8_t i = 0;
10795         static const struct {
10796                 char str[32];
10797                 uint16_t type;
10798         } flowtype_str[] = {
10799                 {"raw", RTE_ETH_FLOW_RAW},
10800                 {"ipv4", RTE_ETH_FLOW_IPV4},
10801                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10802                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10803                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10804                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10805                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10806                 {"ipv6", RTE_ETH_FLOW_IPV6},
10807                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10808                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10809                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10810                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10811                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10812                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10813         };
10814
10815         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10816                 if (!strcmp(flowtype_str[i].str, string))
10817                         return flowtype_str[i].type;
10818         }
10819
10820         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10821                 return (uint16_t)atoi(string);
10822
10823         return RTE_ETH_FLOW_UNKNOWN;
10824 }
10825
10826 static enum rte_eth_fdir_tunnel_type
10827 str2fdir_tunneltype(char *string)
10828 {
10829         uint8_t i = 0;
10830
10831         static const struct {
10832                 char str[32];
10833                 enum rte_eth_fdir_tunnel_type type;
10834         } tunneltype_str[] = {
10835                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10836                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10837         };
10838
10839         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10840                 if (!strcmp(tunneltype_str[i].str, string))
10841                         return tunneltype_str[i].type;
10842         }
10843         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10844 }
10845
10846 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10847 do { \
10848         if ((ip_addr).family == AF_INET) \
10849                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10850         else { \
10851                 printf("invalid parameter.\n"); \
10852                 return; \
10853         } \
10854 } while (0)
10855
10856 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10857 do { \
10858         if ((ip_addr).family == AF_INET6) \
10859                 rte_memcpy(&(ip), \
10860                                  &((ip_addr).addr.ipv6), \
10861                                  sizeof(struct in6_addr)); \
10862         else { \
10863                 printf("invalid parameter.\n"); \
10864                 return; \
10865         } \
10866 } while (0)
10867
10868 static void
10869 cmd_flow_director_filter_parsed(void *parsed_result,
10870                           __attribute__((unused)) struct cmdline *cl,
10871                           __attribute__((unused)) void *data)
10872 {
10873         struct cmd_flow_director_result *res = parsed_result;
10874         struct rte_eth_fdir_filter entry;
10875         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10876         char *end;
10877         unsigned long vf_id;
10878         int ret = 0;
10879
10880         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10881         if (ret < 0) {
10882                 printf("flow director is not supported on port %u.\n",
10883                         res->port_id);
10884                 return;
10885         }
10886         memset(flexbytes, 0, sizeof(flexbytes));
10887         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10888
10889         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10890                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10891                         printf("Please set mode to MAC-VLAN.\n");
10892                         return;
10893                 }
10894         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10895                 if (strcmp(res->mode_value, "Tunnel")) {
10896                         printf("Please set mode to Tunnel.\n");
10897                         return;
10898                 }
10899         } else {
10900                 if (!strcmp(res->mode_value, "raw")) {
10901 #ifdef RTE_LIBRTE_I40E_PMD
10902                         struct rte_pmd_i40e_flow_type_mapping
10903                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10904                         struct rte_pmd_i40e_pkt_template_conf conf;
10905                         uint16_t flow_type = str2flowtype(res->flow_type);
10906                         uint16_t i, port = res->port_id;
10907                         uint8_t add;
10908
10909                         memset(&conf, 0, sizeof(conf));
10910
10911                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10912                                 printf("Invalid flow type specified.\n");
10913                                 return;
10914                         }
10915                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10916                                                                  mapping);
10917                         if (ret)
10918                                 return;
10919                         if (mapping[flow_type].pctype == 0ULL) {
10920                                 printf("Invalid flow type specified.\n");
10921                                 return;
10922                         }
10923                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10924                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10925                                         conf.input.pctype = i;
10926                                         break;
10927                                 }
10928                         }
10929
10930                         conf.input.packet = open_file(res->filepath,
10931                                                 &conf.input.length);
10932                         if (!conf.input.packet)
10933                                 return;
10934                         if (!strcmp(res->drop, "drop"))
10935                                 conf.action.behavior =
10936                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10937                         else
10938                                 conf.action.behavior =
10939                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10940                         conf.action.report_status =
10941                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10942                         conf.action.rx_queue = res->queue_id;
10943                         conf.soft_id = res->fd_id_value;
10944                         add  = strcmp(res->ops, "del") ? 1 : 0;
10945                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10946                                                                         &conf,
10947                                                                         add);
10948                         if (ret < 0)
10949                                 printf("flow director config error: (%s)\n",
10950                                        strerror(-ret));
10951                         close_file(conf.input.packet);
10952 #endif
10953                         return;
10954                 } else if (strcmp(res->mode_value, "IP")) {
10955                         printf("Please set mode to IP or raw.\n");
10956                         return;
10957                 }
10958                 entry.input.flow_type = str2flowtype(res->flow_type);
10959         }
10960
10961         ret = parse_flexbytes(res->flexbytes_value,
10962                                         flexbytes,
10963                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10964         if (ret < 0) {
10965                 printf("error: Cannot parse flexbytes input.\n");
10966                 return;
10967         }
10968
10969         switch (entry.input.flow_type) {
10970         case RTE_ETH_FLOW_FRAG_IPV4:
10971         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10972                 entry.input.flow.ip4_flow.proto = res->proto_value;
10973                 /* fall-through */
10974         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10975         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10976                 IPV4_ADDR_TO_UINT(res->ip_dst,
10977                         entry.input.flow.ip4_flow.dst_ip);
10978                 IPV4_ADDR_TO_UINT(res->ip_src,
10979                         entry.input.flow.ip4_flow.src_ip);
10980                 entry.input.flow.ip4_flow.tos = res->tos_value;
10981                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10982                 /* need convert to big endian. */
10983                 entry.input.flow.udp4_flow.dst_port =
10984                                 rte_cpu_to_be_16(res->port_dst);
10985                 entry.input.flow.udp4_flow.src_port =
10986                                 rte_cpu_to_be_16(res->port_src);
10987                 break;
10988         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10989                 IPV4_ADDR_TO_UINT(res->ip_dst,
10990                         entry.input.flow.sctp4_flow.ip.dst_ip);
10991                 IPV4_ADDR_TO_UINT(res->ip_src,
10992                         entry.input.flow.sctp4_flow.ip.src_ip);
10993                 entry.input.flow.ip4_flow.tos = res->tos_value;
10994                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10995                 /* need convert to big endian. */
10996                 entry.input.flow.sctp4_flow.dst_port =
10997                                 rte_cpu_to_be_16(res->port_dst);
10998                 entry.input.flow.sctp4_flow.src_port =
10999                                 rte_cpu_to_be_16(res->port_src);
11000                 entry.input.flow.sctp4_flow.verify_tag =
11001                                 rte_cpu_to_be_32(res->verify_tag_value);
11002                 break;
11003         case RTE_ETH_FLOW_FRAG_IPV6:
11004         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11005                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11006                 /* fall-through */
11007         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11008         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11009                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11010                         entry.input.flow.ipv6_flow.dst_ip);
11011                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11012                         entry.input.flow.ipv6_flow.src_ip);
11013                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11014                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11015                 /* need convert to big endian. */
11016                 entry.input.flow.udp6_flow.dst_port =
11017                                 rte_cpu_to_be_16(res->port_dst);
11018                 entry.input.flow.udp6_flow.src_port =
11019                                 rte_cpu_to_be_16(res->port_src);
11020                 break;
11021         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11022                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11023                         entry.input.flow.sctp6_flow.ip.dst_ip);
11024                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11025                         entry.input.flow.sctp6_flow.ip.src_ip);
11026                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11027                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11028                 /* need convert to big endian. */
11029                 entry.input.flow.sctp6_flow.dst_port =
11030                                 rte_cpu_to_be_16(res->port_dst);
11031                 entry.input.flow.sctp6_flow.src_port =
11032                                 rte_cpu_to_be_16(res->port_src);
11033                 entry.input.flow.sctp6_flow.verify_tag =
11034                                 rte_cpu_to_be_32(res->verify_tag_value);
11035                 break;
11036         case RTE_ETH_FLOW_L2_PAYLOAD:
11037                 entry.input.flow.l2_flow.ether_type =
11038                         rte_cpu_to_be_16(res->ether_type);
11039                 break;
11040         default:
11041                 break;
11042         }
11043
11044         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11045                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11046                                  &res->mac_addr,
11047                                  sizeof(struct rte_ether_addr));
11048
11049         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11050                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11051                                  &res->mac_addr,
11052                                  sizeof(struct rte_ether_addr));
11053                 entry.input.flow.tunnel_flow.tunnel_type =
11054                         str2fdir_tunneltype(res->tunnel_type);
11055                 entry.input.flow.tunnel_flow.tunnel_id =
11056                         rte_cpu_to_be_32(res->tunnel_id_value);
11057         }
11058
11059         rte_memcpy(entry.input.flow_ext.flexbytes,
11060                    flexbytes,
11061                    RTE_ETH_FDIR_MAX_FLEXLEN);
11062
11063         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11064
11065         entry.action.flex_off = 0;  /*use 0 by default */
11066         if (!strcmp(res->drop, "drop"))
11067                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11068         else
11069                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11070
11071         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11072             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11073                 if (!strcmp(res->pf_vf, "pf"))
11074                         entry.input.flow_ext.is_vf = 0;
11075                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11076                         struct rte_eth_dev_info dev_info;
11077
11078                         memset(&dev_info, 0, sizeof(dev_info));
11079                         rte_eth_dev_info_get(res->port_id, &dev_info);
11080                         errno = 0;
11081                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11082                         if (errno != 0 || *end != '\0' ||
11083                             vf_id >= dev_info.max_vfs) {
11084                                 printf("invalid parameter %s.\n", res->pf_vf);
11085                                 return;
11086                         }
11087                         entry.input.flow_ext.is_vf = 1;
11088                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11089                 } else {
11090                         printf("invalid parameter %s.\n", res->pf_vf);
11091                         return;
11092                 }
11093         }
11094
11095         /* set to report FD ID by default */
11096         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11097         entry.action.rx_queue = res->queue_id;
11098         entry.soft_id = res->fd_id_value;
11099         if (!strcmp(res->ops, "add"))
11100                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11101                                              RTE_ETH_FILTER_ADD, &entry);
11102         else if (!strcmp(res->ops, "del"))
11103                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11104                                              RTE_ETH_FILTER_DELETE, &entry);
11105         else
11106                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11107                                              RTE_ETH_FILTER_UPDATE, &entry);
11108         if (ret < 0)
11109                 printf("flow director programming error: (%s)\n",
11110                         strerror(-ret));
11111 }
11112
11113 cmdline_parse_token_string_t cmd_flow_director_filter =
11114         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11115                                  flow_director_filter, "flow_director_filter");
11116 cmdline_parse_token_num_t cmd_flow_director_port_id =
11117         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11118                               port_id, UINT16);
11119 cmdline_parse_token_string_t cmd_flow_director_ops =
11120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11121                                  ops, "add#del#update");
11122 cmdline_parse_token_string_t cmd_flow_director_flow =
11123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11124                                  flow, "flow");
11125 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11126         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11127                 flow_type, NULL);
11128 cmdline_parse_token_string_t cmd_flow_director_ether =
11129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11130                                  ether, "ether");
11131 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11132         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11133                               ether_type, UINT16);
11134 cmdline_parse_token_string_t cmd_flow_director_src =
11135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11136                                  src, "src");
11137 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11138         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11139                                  ip_src);
11140 cmdline_parse_token_num_t cmd_flow_director_port_src =
11141         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11142                               port_src, UINT16);
11143 cmdline_parse_token_string_t cmd_flow_director_dst =
11144         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11145                                  dst, "dst");
11146 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11147         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11148                                  ip_dst);
11149 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11150         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11151                               port_dst, UINT16);
11152 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11153         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11154                                   verify_tag, "verify_tag");
11155 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11156         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11157                               verify_tag_value, UINT32);
11158 cmdline_parse_token_string_t cmd_flow_director_tos =
11159         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11160                                  tos, "tos");
11161 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11162         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11163                               tos_value, UINT8);
11164 cmdline_parse_token_string_t cmd_flow_director_proto =
11165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11166                                  proto, "proto");
11167 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11168         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11169                               proto_value, UINT8);
11170 cmdline_parse_token_string_t cmd_flow_director_ttl =
11171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11172                                  ttl, "ttl");
11173 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11174         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11175                               ttl_value, UINT8);
11176 cmdline_parse_token_string_t cmd_flow_director_vlan =
11177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11178                                  vlan, "vlan");
11179 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11180         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11181                               vlan_value, UINT16);
11182 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11184                                  flexbytes, "flexbytes");
11185 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11187                               flexbytes_value, NULL);
11188 cmdline_parse_token_string_t cmd_flow_director_drop =
11189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11190                                  drop, "drop#fwd");
11191 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11192         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11193                               pf_vf, NULL);
11194 cmdline_parse_token_string_t cmd_flow_director_queue =
11195         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11196                                  queue, "queue");
11197 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11198         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11199                               queue_id, UINT16);
11200 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11202                                  fd_id, "fd_id");
11203 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11204         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11205                               fd_id_value, UINT32);
11206
11207 cmdline_parse_token_string_t cmd_flow_director_mode =
11208         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11209                                  mode, "mode");
11210 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11211         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11212                                  mode_value, "IP");
11213 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11215                                  mode_value, "MAC-VLAN");
11216 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11217         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11218                                  mode_value, "Tunnel");
11219 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11220         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11221                                  mode_value, "raw");
11222 cmdline_parse_token_string_t cmd_flow_director_mac =
11223         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11224                                  mac, "mac");
11225 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11226         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11227                                     mac_addr);
11228 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11229         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11230                                  tunnel, "tunnel");
11231 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11232         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11233                                  tunnel_type, "NVGRE#VxLAN");
11234 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11235         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11236                                  tunnel_id, "tunnel-id");
11237 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11238         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11239                               tunnel_id_value, UINT32);
11240 cmdline_parse_token_string_t cmd_flow_director_packet =
11241         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11242                                  packet, "packet");
11243 cmdline_parse_token_string_t cmd_flow_director_filepath =
11244         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11245                                  filepath, NULL);
11246
11247 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11248         .f = cmd_flow_director_filter_parsed,
11249         .data = NULL,
11250         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11251                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11252                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11253                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11254                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11255                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11256                 "fd_id <fd_id_value>: "
11257                 "Add or delete an ip flow director entry on NIC",
11258         .tokens = {
11259                 (void *)&cmd_flow_director_filter,
11260                 (void *)&cmd_flow_director_port_id,
11261                 (void *)&cmd_flow_director_mode,
11262                 (void *)&cmd_flow_director_mode_ip,
11263                 (void *)&cmd_flow_director_ops,
11264                 (void *)&cmd_flow_director_flow,
11265                 (void *)&cmd_flow_director_flow_type,
11266                 (void *)&cmd_flow_director_src,
11267                 (void *)&cmd_flow_director_ip_src,
11268                 (void *)&cmd_flow_director_dst,
11269                 (void *)&cmd_flow_director_ip_dst,
11270                 (void *)&cmd_flow_director_tos,
11271                 (void *)&cmd_flow_director_tos_value,
11272                 (void *)&cmd_flow_director_proto,
11273                 (void *)&cmd_flow_director_proto_value,
11274                 (void *)&cmd_flow_director_ttl,
11275                 (void *)&cmd_flow_director_ttl_value,
11276                 (void *)&cmd_flow_director_vlan,
11277                 (void *)&cmd_flow_director_vlan_value,
11278                 (void *)&cmd_flow_director_flexbytes,
11279                 (void *)&cmd_flow_director_flexbytes_value,
11280                 (void *)&cmd_flow_director_drop,
11281                 (void *)&cmd_flow_director_pf_vf,
11282                 (void *)&cmd_flow_director_queue,
11283                 (void *)&cmd_flow_director_queue_id,
11284                 (void *)&cmd_flow_director_fd_id,
11285                 (void *)&cmd_flow_director_fd_id_value,
11286                 NULL,
11287         },
11288 };
11289
11290 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11291         .f = cmd_flow_director_filter_parsed,
11292         .data = NULL,
11293         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11294                 "director entry on NIC",
11295         .tokens = {
11296                 (void *)&cmd_flow_director_filter,
11297                 (void *)&cmd_flow_director_port_id,
11298                 (void *)&cmd_flow_director_mode,
11299                 (void *)&cmd_flow_director_mode_ip,
11300                 (void *)&cmd_flow_director_ops,
11301                 (void *)&cmd_flow_director_flow,
11302                 (void *)&cmd_flow_director_flow_type,
11303                 (void *)&cmd_flow_director_src,
11304                 (void *)&cmd_flow_director_ip_src,
11305                 (void *)&cmd_flow_director_port_src,
11306                 (void *)&cmd_flow_director_dst,
11307                 (void *)&cmd_flow_director_ip_dst,
11308                 (void *)&cmd_flow_director_port_dst,
11309                 (void *)&cmd_flow_director_tos,
11310                 (void *)&cmd_flow_director_tos_value,
11311                 (void *)&cmd_flow_director_ttl,
11312                 (void *)&cmd_flow_director_ttl_value,
11313                 (void *)&cmd_flow_director_vlan,
11314                 (void *)&cmd_flow_director_vlan_value,
11315                 (void *)&cmd_flow_director_flexbytes,
11316                 (void *)&cmd_flow_director_flexbytes_value,
11317                 (void *)&cmd_flow_director_drop,
11318                 (void *)&cmd_flow_director_pf_vf,
11319                 (void *)&cmd_flow_director_queue,
11320                 (void *)&cmd_flow_director_queue_id,
11321                 (void *)&cmd_flow_director_fd_id,
11322                 (void *)&cmd_flow_director_fd_id_value,
11323                 NULL,
11324         },
11325 };
11326
11327 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11328         .f = cmd_flow_director_filter_parsed,
11329         .data = NULL,
11330         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11331                 "director entry on NIC",
11332         .tokens = {
11333                 (void *)&cmd_flow_director_filter,
11334                 (void *)&cmd_flow_director_port_id,
11335                 (void *)&cmd_flow_director_mode,
11336                 (void *)&cmd_flow_director_mode_ip,
11337                 (void *)&cmd_flow_director_ops,
11338                 (void *)&cmd_flow_director_flow,
11339                 (void *)&cmd_flow_director_flow_type,
11340                 (void *)&cmd_flow_director_src,
11341                 (void *)&cmd_flow_director_ip_src,
11342                 (void *)&cmd_flow_director_port_src,
11343                 (void *)&cmd_flow_director_dst,
11344                 (void *)&cmd_flow_director_ip_dst,
11345                 (void *)&cmd_flow_director_port_dst,
11346                 (void *)&cmd_flow_director_verify_tag,
11347                 (void *)&cmd_flow_director_verify_tag_value,
11348                 (void *)&cmd_flow_director_tos,
11349                 (void *)&cmd_flow_director_tos_value,
11350                 (void *)&cmd_flow_director_ttl,
11351                 (void *)&cmd_flow_director_ttl_value,
11352                 (void *)&cmd_flow_director_vlan,
11353                 (void *)&cmd_flow_director_vlan_value,
11354                 (void *)&cmd_flow_director_flexbytes,
11355                 (void *)&cmd_flow_director_flexbytes_value,
11356                 (void *)&cmd_flow_director_drop,
11357                 (void *)&cmd_flow_director_pf_vf,
11358                 (void *)&cmd_flow_director_queue,
11359                 (void *)&cmd_flow_director_queue_id,
11360                 (void *)&cmd_flow_director_fd_id,
11361                 (void *)&cmd_flow_director_fd_id_value,
11362                 NULL,
11363         },
11364 };
11365
11366 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11367         .f = cmd_flow_director_filter_parsed,
11368         .data = NULL,
11369         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11370                 "director entry on NIC",
11371         .tokens = {
11372                 (void *)&cmd_flow_director_filter,
11373                 (void *)&cmd_flow_director_port_id,
11374                 (void *)&cmd_flow_director_mode,
11375                 (void *)&cmd_flow_director_mode_ip,
11376                 (void *)&cmd_flow_director_ops,
11377                 (void *)&cmd_flow_director_flow,
11378                 (void *)&cmd_flow_director_flow_type,
11379                 (void *)&cmd_flow_director_ether,
11380                 (void *)&cmd_flow_director_ether_type,
11381                 (void *)&cmd_flow_director_flexbytes,
11382                 (void *)&cmd_flow_director_flexbytes_value,
11383                 (void *)&cmd_flow_director_drop,
11384                 (void *)&cmd_flow_director_pf_vf,
11385                 (void *)&cmd_flow_director_queue,
11386                 (void *)&cmd_flow_director_queue_id,
11387                 (void *)&cmd_flow_director_fd_id,
11388                 (void *)&cmd_flow_director_fd_id_value,
11389                 NULL,
11390         },
11391 };
11392
11393 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11394         .f = cmd_flow_director_filter_parsed,
11395         .data = NULL,
11396         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11397                 "director entry on NIC",
11398         .tokens = {
11399                 (void *)&cmd_flow_director_filter,
11400                 (void *)&cmd_flow_director_port_id,
11401                 (void *)&cmd_flow_director_mode,
11402                 (void *)&cmd_flow_director_mode_mac_vlan,
11403                 (void *)&cmd_flow_director_ops,
11404                 (void *)&cmd_flow_director_mac,
11405                 (void *)&cmd_flow_director_mac_addr,
11406                 (void *)&cmd_flow_director_vlan,
11407                 (void *)&cmd_flow_director_vlan_value,
11408                 (void *)&cmd_flow_director_flexbytes,
11409                 (void *)&cmd_flow_director_flexbytes_value,
11410                 (void *)&cmd_flow_director_drop,
11411                 (void *)&cmd_flow_director_queue,
11412                 (void *)&cmd_flow_director_queue_id,
11413                 (void *)&cmd_flow_director_fd_id,
11414                 (void *)&cmd_flow_director_fd_id_value,
11415                 NULL,
11416         },
11417 };
11418
11419 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11420         .f = cmd_flow_director_filter_parsed,
11421         .data = NULL,
11422         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11423                 "director entry on NIC",
11424         .tokens = {
11425                 (void *)&cmd_flow_director_filter,
11426                 (void *)&cmd_flow_director_port_id,
11427                 (void *)&cmd_flow_director_mode,
11428                 (void *)&cmd_flow_director_mode_tunnel,
11429                 (void *)&cmd_flow_director_ops,
11430                 (void *)&cmd_flow_director_mac,
11431                 (void *)&cmd_flow_director_mac_addr,
11432                 (void *)&cmd_flow_director_vlan,
11433                 (void *)&cmd_flow_director_vlan_value,
11434                 (void *)&cmd_flow_director_tunnel,
11435                 (void *)&cmd_flow_director_tunnel_type,
11436                 (void *)&cmd_flow_director_tunnel_id,
11437                 (void *)&cmd_flow_director_tunnel_id_value,
11438                 (void *)&cmd_flow_director_flexbytes,
11439                 (void *)&cmd_flow_director_flexbytes_value,
11440                 (void *)&cmd_flow_director_drop,
11441                 (void *)&cmd_flow_director_queue,
11442                 (void *)&cmd_flow_director_queue_id,
11443                 (void *)&cmd_flow_director_fd_id,
11444                 (void *)&cmd_flow_director_fd_id_value,
11445                 NULL,
11446         },
11447 };
11448
11449 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11450         .f = cmd_flow_director_filter_parsed,
11451         .data = NULL,
11452         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11453                 "director entry on NIC",
11454         .tokens = {
11455                 (void *)&cmd_flow_director_filter,
11456                 (void *)&cmd_flow_director_port_id,
11457                 (void *)&cmd_flow_director_mode,
11458                 (void *)&cmd_flow_director_mode_raw,
11459                 (void *)&cmd_flow_director_ops,
11460                 (void *)&cmd_flow_director_flow,
11461                 (void *)&cmd_flow_director_flow_type,
11462                 (void *)&cmd_flow_director_drop,
11463                 (void *)&cmd_flow_director_queue,
11464                 (void *)&cmd_flow_director_queue_id,
11465                 (void *)&cmd_flow_director_fd_id,
11466                 (void *)&cmd_flow_director_fd_id_value,
11467                 (void *)&cmd_flow_director_packet,
11468                 (void *)&cmd_flow_director_filepath,
11469                 NULL,
11470         },
11471 };
11472
11473 struct cmd_flush_flow_director_result {
11474         cmdline_fixed_string_t flush_flow_director;
11475         portid_t port_id;
11476 };
11477
11478 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11479         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11480                                  flush_flow_director, "flush_flow_director");
11481 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11482         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11483                               port_id, UINT16);
11484
11485 static void
11486 cmd_flush_flow_director_parsed(void *parsed_result,
11487                           __attribute__((unused)) struct cmdline *cl,
11488                           __attribute__((unused)) void *data)
11489 {
11490         struct cmd_flow_director_result *res = parsed_result;
11491         int ret = 0;
11492
11493         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11494         if (ret < 0) {
11495                 printf("flow director is not supported on port %u.\n",
11496                         res->port_id);
11497                 return;
11498         }
11499
11500         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11501                         RTE_ETH_FILTER_FLUSH, NULL);
11502         if (ret < 0)
11503                 printf("flow director table flushing error: (%s)\n",
11504                         strerror(-ret));
11505 }
11506
11507 cmdline_parse_inst_t cmd_flush_flow_director = {
11508         .f = cmd_flush_flow_director_parsed,
11509         .data = NULL,
11510         .help_str = "flush_flow_director <port_id>: "
11511                 "Flush all flow director entries of a device on NIC",
11512         .tokens = {
11513                 (void *)&cmd_flush_flow_director_flush,
11514                 (void *)&cmd_flush_flow_director_port_id,
11515                 NULL,
11516         },
11517 };
11518
11519 /* *** deal with flow director mask *** */
11520 struct cmd_flow_director_mask_result {
11521         cmdline_fixed_string_t flow_director_mask;
11522         portid_t port_id;
11523         cmdline_fixed_string_t mode;
11524         cmdline_fixed_string_t mode_value;
11525         cmdline_fixed_string_t vlan;
11526         uint16_t vlan_mask;
11527         cmdline_fixed_string_t src_mask;
11528         cmdline_ipaddr_t ipv4_src;
11529         cmdline_ipaddr_t ipv6_src;
11530         uint16_t port_src;
11531         cmdline_fixed_string_t dst_mask;
11532         cmdline_ipaddr_t ipv4_dst;
11533         cmdline_ipaddr_t ipv6_dst;
11534         uint16_t port_dst;
11535         cmdline_fixed_string_t mac;
11536         uint8_t mac_addr_byte_mask;
11537         cmdline_fixed_string_t tunnel_id;
11538         uint32_t tunnel_id_mask;
11539         cmdline_fixed_string_t tunnel_type;
11540         uint8_t tunnel_type_mask;
11541 };
11542
11543 static void
11544 cmd_flow_director_mask_parsed(void *parsed_result,
11545                           __attribute__((unused)) struct cmdline *cl,
11546                           __attribute__((unused)) void *data)
11547 {
11548         struct cmd_flow_director_mask_result *res = parsed_result;
11549         struct rte_eth_fdir_masks *mask;
11550         struct rte_port *port;
11551
11552         port = &ports[res->port_id];
11553         /** Check if the port is not started **/
11554         if (port->port_status != RTE_PORT_STOPPED) {
11555                 printf("Please stop port %d first\n", res->port_id);
11556                 return;
11557         }
11558
11559         mask = &port->dev_conf.fdir_conf.mask;
11560
11561         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11562                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11563                         printf("Please set mode to MAC-VLAN.\n");
11564                         return;
11565                 }
11566
11567                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11568         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11569                 if (strcmp(res->mode_value, "Tunnel")) {
11570                         printf("Please set mode to Tunnel.\n");
11571                         return;
11572                 }
11573
11574                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11575                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11576                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11577                 mask->tunnel_type_mask = res->tunnel_type_mask;
11578         } else {
11579                 if (strcmp(res->mode_value, "IP")) {
11580                         printf("Please set mode to IP.\n");
11581                         return;
11582                 }
11583
11584                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11585                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11586                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11587                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11588                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11589                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11590                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11591         }
11592
11593         cmd_reconfig_device_queue(res->port_id, 1, 1);
11594 }
11595
11596 cmdline_parse_token_string_t cmd_flow_director_mask =
11597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11598                                  flow_director_mask, "flow_director_mask");
11599 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11600         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11601                               port_id, UINT16);
11602 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11604                                  vlan, "vlan");
11605 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11606         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11607                               vlan_mask, UINT16);
11608 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11610                                  src_mask, "src_mask");
11611 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11612         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11613                                  ipv4_src);
11614 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11615         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11616                                  ipv6_src);
11617 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11619                               port_src, UINT16);
11620 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11622                                  dst_mask, "dst_mask");
11623 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11624         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11625                                  ipv4_dst);
11626 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11627         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11628                                  ipv6_dst);
11629 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11630         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11631                               port_dst, UINT16);
11632
11633 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11634         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11635                                  mode, "mode");
11636 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11637         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11638                                  mode_value, "IP");
11639 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11640         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11641                                  mode_value, "MAC-VLAN");
11642 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11643         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11644                                  mode_value, "Tunnel");
11645 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11646         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11647                                  mac, "mac");
11648 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11649         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11650                               mac_addr_byte_mask, UINT8);
11651 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11652         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11653                                  tunnel_type, "tunnel-type");
11654 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11655         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11656                               tunnel_type_mask, UINT8);
11657 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11658         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11659                                  tunnel_id, "tunnel-id");
11660 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11661         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11662                               tunnel_id_mask, UINT32);
11663
11664 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11665         .f = cmd_flow_director_mask_parsed,
11666         .data = NULL,
11667         .help_str = "flow_director_mask ... : "
11668                 "Set IP mode flow director's mask on NIC",
11669         .tokens = {
11670                 (void *)&cmd_flow_director_mask,
11671                 (void *)&cmd_flow_director_mask_port_id,
11672                 (void *)&cmd_flow_director_mask_mode,
11673                 (void *)&cmd_flow_director_mask_mode_ip,
11674                 (void *)&cmd_flow_director_mask_vlan,
11675                 (void *)&cmd_flow_director_mask_vlan_value,
11676                 (void *)&cmd_flow_director_mask_src,
11677                 (void *)&cmd_flow_director_mask_ipv4_src,
11678                 (void *)&cmd_flow_director_mask_ipv6_src,
11679                 (void *)&cmd_flow_director_mask_port_src,
11680                 (void *)&cmd_flow_director_mask_dst,
11681                 (void *)&cmd_flow_director_mask_ipv4_dst,
11682                 (void *)&cmd_flow_director_mask_ipv6_dst,
11683                 (void *)&cmd_flow_director_mask_port_dst,
11684                 NULL,
11685         },
11686 };
11687
11688 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11689         .f = cmd_flow_director_mask_parsed,
11690         .data = NULL,
11691         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11692                 "flow director's mask on NIC",
11693         .tokens = {
11694                 (void *)&cmd_flow_director_mask,
11695                 (void *)&cmd_flow_director_mask_port_id,
11696                 (void *)&cmd_flow_director_mask_mode,
11697                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11698                 (void *)&cmd_flow_director_mask_vlan,
11699                 (void *)&cmd_flow_director_mask_vlan_value,
11700                 NULL,
11701         },
11702 };
11703
11704 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11705         .f = cmd_flow_director_mask_parsed,
11706         .data = NULL,
11707         .help_str = "flow_director_mask ... : Set tunnel mode "
11708                 "flow director's mask on NIC",
11709         .tokens = {
11710                 (void *)&cmd_flow_director_mask,
11711                 (void *)&cmd_flow_director_mask_port_id,
11712                 (void *)&cmd_flow_director_mask_mode,
11713                 (void *)&cmd_flow_director_mask_mode_tunnel,
11714                 (void *)&cmd_flow_director_mask_vlan,
11715                 (void *)&cmd_flow_director_mask_vlan_value,
11716                 (void *)&cmd_flow_director_mask_mac,
11717                 (void *)&cmd_flow_director_mask_mac_value,
11718                 (void *)&cmd_flow_director_mask_tunnel_type,
11719                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11720                 (void *)&cmd_flow_director_mask_tunnel_id,
11721                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11722                 NULL,
11723         },
11724 };
11725
11726 /* *** deal with flow director mask on flexible payload *** */
11727 struct cmd_flow_director_flex_mask_result {
11728         cmdline_fixed_string_t flow_director_flexmask;
11729         portid_t port_id;
11730         cmdline_fixed_string_t flow;
11731         cmdline_fixed_string_t flow_type;
11732         cmdline_fixed_string_t mask;
11733 };
11734
11735 static void
11736 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11737                           __attribute__((unused)) struct cmdline *cl,
11738                           __attribute__((unused)) void *data)
11739 {
11740         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11741         struct rte_eth_fdir_info fdir_info;
11742         struct rte_eth_fdir_flex_mask flex_mask;
11743         struct rte_port *port;
11744         uint64_t flow_type_mask;
11745         uint16_t i;
11746         int ret;
11747
11748         port = &ports[res->port_id];
11749         /** Check if the port is not started **/
11750         if (port->port_status != RTE_PORT_STOPPED) {
11751                 printf("Please stop port %d first\n", res->port_id);
11752                 return;
11753         }
11754
11755         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11756         ret = parse_flexbytes(res->mask,
11757                         flex_mask.mask,
11758                         RTE_ETH_FDIR_MAX_FLEXLEN);
11759         if (ret < 0) {
11760                 printf("error: Cannot parse mask input.\n");
11761                 return;
11762         }
11763
11764         memset(&fdir_info, 0, sizeof(fdir_info));
11765         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11766                                 RTE_ETH_FILTER_INFO, &fdir_info);
11767         if (ret < 0) {
11768                 printf("Cannot get FDir filter info\n");
11769                 return;
11770         }
11771
11772         if (!strcmp(res->flow_type, "none")) {
11773                 /* means don't specify the flow type */
11774                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11775                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11776                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11777                                0, sizeof(struct rte_eth_fdir_flex_mask));
11778                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11779                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11780                                  &flex_mask,
11781                                  sizeof(struct rte_eth_fdir_flex_mask));
11782                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11783                 return;
11784         }
11785         flow_type_mask = fdir_info.flow_types_mask[0];
11786         if (!strcmp(res->flow_type, "all")) {
11787                 if (!flow_type_mask) {
11788                         printf("No flow type supported\n");
11789                         return;
11790                 }
11791                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11792                         if (flow_type_mask & (1ULL << i)) {
11793                                 flex_mask.flow_type = i;
11794                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11795                         }
11796                 }
11797                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11798                 return;
11799         }
11800         flex_mask.flow_type = str2flowtype(res->flow_type);
11801         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11802                 printf("Flow type %s not supported on port %d\n",
11803                                 res->flow_type, res->port_id);
11804                 return;
11805         }
11806         fdir_set_flex_mask(res->port_id, &flex_mask);
11807         cmd_reconfig_device_queue(res->port_id, 1, 1);
11808 }
11809
11810 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11811         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11812                                  flow_director_flexmask,
11813                                  "flow_director_flex_mask");
11814 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11815         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11816                               port_id, UINT16);
11817 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11818         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11819                                  flow, "flow");
11820 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11821         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11822                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11823                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11824 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11825         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11826                                  mask, NULL);
11827
11828 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11829         .f = cmd_flow_director_flex_mask_parsed,
11830         .data = NULL,
11831         .help_str = "flow_director_flex_mask ... : "
11832                 "Set flow director's flex mask on NIC",
11833         .tokens = {
11834                 (void *)&cmd_flow_director_flexmask,
11835                 (void *)&cmd_flow_director_flexmask_port_id,
11836                 (void *)&cmd_flow_director_flexmask_flow,
11837                 (void *)&cmd_flow_director_flexmask_flow_type,
11838                 (void *)&cmd_flow_director_flexmask_mask,
11839                 NULL,
11840         },
11841 };
11842
11843 /* *** deal with flow director flexible payload configuration *** */
11844 struct cmd_flow_director_flexpayload_result {
11845         cmdline_fixed_string_t flow_director_flexpayload;
11846         portid_t port_id;
11847         cmdline_fixed_string_t payload_layer;
11848         cmdline_fixed_string_t payload_cfg;
11849 };
11850
11851 static inline int
11852 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11853 {
11854         char s[256];
11855         const char *p, *p0 = q_arg;
11856         char *end;
11857         unsigned long int_fld;
11858         char *str_fld[max_num];
11859         int i;
11860         unsigned size;
11861         int ret = -1;
11862
11863         p = strchr(p0, '(');
11864         if (p == NULL)
11865                 return -1;
11866         ++p;
11867         p0 = strchr(p, ')');
11868         if (p0 == NULL)
11869                 return -1;
11870
11871         size = p0 - p;
11872         if (size >= sizeof(s))
11873                 return -1;
11874
11875         snprintf(s, sizeof(s), "%.*s", size, p);
11876         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11877         if (ret < 0 || ret > max_num)
11878                 return -1;
11879         for (i = 0; i < ret; i++) {
11880                 errno = 0;
11881                 int_fld = strtoul(str_fld[i], &end, 0);
11882                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11883                         return -1;
11884                 offsets[i] = (uint16_t)int_fld;
11885         }
11886         return ret;
11887 }
11888
11889 static void
11890 cmd_flow_director_flxpld_parsed(void *parsed_result,
11891                           __attribute__((unused)) struct cmdline *cl,
11892                           __attribute__((unused)) void *data)
11893 {
11894         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11895         struct rte_eth_flex_payload_cfg flex_cfg;
11896         struct rte_port *port;
11897         int ret = 0;
11898
11899         port = &ports[res->port_id];
11900         /** Check if the port is not started **/
11901         if (port->port_status != RTE_PORT_STOPPED) {
11902                 printf("Please stop port %d first\n", res->port_id);
11903                 return;
11904         }
11905
11906         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11907
11908         if (!strcmp(res->payload_layer, "raw"))
11909                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11910         else if (!strcmp(res->payload_layer, "l2"))
11911                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11912         else if (!strcmp(res->payload_layer, "l3"))
11913                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11914         else if (!strcmp(res->payload_layer, "l4"))
11915                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11916
11917         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11918                             RTE_ETH_FDIR_MAX_FLEXLEN);
11919         if (ret < 0) {
11920                 printf("error: Cannot parse flex payload input.\n");
11921                 return;
11922         }
11923
11924         fdir_set_flex_payload(res->port_id, &flex_cfg);
11925         cmd_reconfig_device_queue(res->port_id, 1, 1);
11926 }
11927
11928 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11929         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11930                                  flow_director_flexpayload,
11931                                  "flow_director_flex_payload");
11932 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11933         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11934                               port_id, UINT16);
11935 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11936         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11937                                  payload_layer, "raw#l2#l3#l4");
11938 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11939         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11940                                  payload_cfg, NULL);
11941
11942 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11943         .f = cmd_flow_director_flxpld_parsed,
11944         .data = NULL,
11945         .help_str = "flow_director_flexpayload ... : "
11946                 "Set flow director's flex payload on NIC",
11947         .tokens = {
11948                 (void *)&cmd_flow_director_flexpayload,
11949                 (void *)&cmd_flow_director_flexpayload_port_id,
11950                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11951                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11952                 NULL,
11953         },
11954 };
11955
11956 /* Generic flow interface command. */
11957 extern cmdline_parse_inst_t cmd_flow;
11958
11959 /* *** Classification Filters Control *** */
11960 /* *** Get symmetric hash enable per port *** */
11961 struct cmd_get_sym_hash_ena_per_port_result {
11962         cmdline_fixed_string_t get_sym_hash_ena_per_port;
11963         portid_t port_id;
11964 };
11965
11966 static void
11967 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
11968                                  __rte_unused struct cmdline *cl,
11969                                  __rte_unused void *data)
11970 {
11971         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
11972         struct rte_eth_hash_filter_info info;
11973         int ret;
11974
11975         if (rte_eth_dev_filter_supported(res->port_id,
11976                                 RTE_ETH_FILTER_HASH) < 0) {
11977                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11978                                                         res->port_id);
11979                 return;
11980         }
11981
11982         memset(&info, 0, sizeof(info));
11983         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11984         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11985                                                 RTE_ETH_FILTER_GET, &info);
11986
11987         if (ret < 0) {
11988                 printf("Cannot get symmetric hash enable per port "
11989                                         "on port %u\n", res->port_id);
11990                 return;
11991         }
11992
11993         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
11994                                 "enabled" : "disabled", res->port_id);
11995 }
11996
11997 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
11998         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
11999                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12000 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12001         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12002                 port_id, UINT16);
12003
12004 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12005         .f = cmd_get_sym_hash_per_port_parsed,
12006         .data = NULL,
12007         .help_str = "get_sym_hash_ena_per_port <port_id>",
12008         .tokens = {
12009                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12010                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12011                 NULL,
12012         },
12013 };
12014
12015 /* *** Set symmetric hash enable per port *** */
12016 struct cmd_set_sym_hash_ena_per_port_result {
12017         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12018         cmdline_fixed_string_t enable;
12019         portid_t port_id;
12020 };
12021
12022 static void
12023 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12024                                  __rte_unused struct cmdline *cl,
12025                                  __rte_unused void *data)
12026 {
12027         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12028         struct rte_eth_hash_filter_info info;
12029         int ret;
12030
12031         if (rte_eth_dev_filter_supported(res->port_id,
12032                                 RTE_ETH_FILTER_HASH) < 0) {
12033                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12034                                                         res->port_id);
12035                 return;
12036         }
12037
12038         memset(&info, 0, sizeof(info));
12039         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12040         if (!strcmp(res->enable, "enable"))
12041                 info.info.enable = 1;
12042         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12043                                         RTE_ETH_FILTER_SET, &info);
12044         if (ret < 0) {
12045                 printf("Cannot set symmetric hash enable per port on "
12046                                         "port %u\n", res->port_id);
12047                 return;
12048         }
12049         printf("Symmetric hash has been set to %s on port %u\n",
12050                                         res->enable, res->port_id);
12051 }
12052
12053 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12054         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12055                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12056 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12057         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12058                 port_id, UINT16);
12059 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12060         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12061                 enable, "enable#disable");
12062
12063 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12064         .f = cmd_set_sym_hash_per_port_parsed,
12065         .data = NULL,
12066         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12067         .tokens = {
12068                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12069                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12070                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12071                 NULL,
12072         },
12073 };
12074
12075 /* Get global config of hash function */
12076 struct cmd_get_hash_global_config_result {
12077         cmdline_fixed_string_t get_hash_global_config;
12078         portid_t port_id;
12079 };
12080
12081 static char *
12082 flowtype_to_str(uint16_t ftype)
12083 {
12084         uint16_t i;
12085         static struct {
12086                 char str[16];
12087                 uint16_t ftype;
12088         } ftype_table[] = {
12089                 {"ipv4", RTE_ETH_FLOW_IPV4},
12090                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12091                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12092                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12093                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12094                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12095                 {"ipv6", RTE_ETH_FLOW_IPV6},
12096                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12097                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12098                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12099                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12100                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12101                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12102                 {"port", RTE_ETH_FLOW_PORT},
12103                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12104                 {"geneve", RTE_ETH_FLOW_GENEVE},
12105                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12106                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12107         };
12108
12109         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12110                 if (ftype_table[i].ftype == ftype)
12111                         return ftype_table[i].str;
12112         }
12113
12114         return NULL;
12115 }
12116
12117 static void
12118 cmd_get_hash_global_config_parsed(void *parsed_result,
12119                                   __rte_unused struct cmdline *cl,
12120                                   __rte_unused void *data)
12121 {
12122         struct cmd_get_hash_global_config_result *res = parsed_result;
12123         struct rte_eth_hash_filter_info info;
12124         uint32_t idx, offset;
12125         uint16_t i;
12126         char *str;
12127         int ret;
12128
12129         if (rte_eth_dev_filter_supported(res->port_id,
12130                         RTE_ETH_FILTER_HASH) < 0) {
12131                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12132                                                         res->port_id);
12133                 return;
12134         }
12135
12136         memset(&info, 0, sizeof(info));
12137         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12138         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12139                                         RTE_ETH_FILTER_GET, &info);
12140         if (ret < 0) {
12141                 printf("Cannot get hash global configurations by port %d\n",
12142                                                         res->port_id);
12143                 return;
12144         }
12145
12146         switch (info.info.global_conf.hash_func) {
12147         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12148                 printf("Hash function is Toeplitz\n");
12149                 break;
12150         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12151                 printf("Hash function is Simple XOR\n");
12152                 break;
12153         default:
12154                 printf("Unknown hash function\n");
12155                 break;
12156         }
12157
12158         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12159                 idx = i / UINT64_BIT;
12160                 offset = i % UINT64_BIT;
12161                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12162                                                 (1ULL << offset)))
12163                         continue;
12164                 str = flowtype_to_str(i);
12165                 if (!str)
12166                         continue;
12167                 printf("Symmetric hash is %s globally for flow type %s "
12168                                                         "by port %d\n",
12169                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12170                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12171                                                         res->port_id);
12172         }
12173 }
12174
12175 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12176         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12177                 get_hash_global_config, "get_hash_global_config");
12178 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12179         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12180                 port_id, UINT16);
12181
12182 cmdline_parse_inst_t cmd_get_hash_global_config = {
12183         .f = cmd_get_hash_global_config_parsed,
12184         .data = NULL,
12185         .help_str = "get_hash_global_config <port_id>",
12186         .tokens = {
12187                 (void *)&cmd_get_hash_global_config_all,
12188                 (void *)&cmd_get_hash_global_config_port_id,
12189                 NULL,
12190         },
12191 };
12192
12193 /* Set global config of hash function */
12194 struct cmd_set_hash_global_config_result {
12195         cmdline_fixed_string_t set_hash_global_config;
12196         portid_t port_id;
12197         cmdline_fixed_string_t hash_func;
12198         cmdline_fixed_string_t flow_type;
12199         cmdline_fixed_string_t enable;
12200 };
12201
12202 static void
12203 cmd_set_hash_global_config_parsed(void *parsed_result,
12204                                   __rte_unused struct cmdline *cl,
12205                                   __rte_unused void *data)
12206 {
12207         struct cmd_set_hash_global_config_result *res = parsed_result;
12208         struct rte_eth_hash_filter_info info;
12209         uint32_t ftype, idx, offset;
12210         int ret;
12211
12212         if (rte_eth_dev_filter_supported(res->port_id,
12213                                 RTE_ETH_FILTER_HASH) < 0) {
12214                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12215                                                         res->port_id);
12216                 return;
12217         }
12218         memset(&info, 0, sizeof(info));
12219         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12220         if (!strcmp(res->hash_func, "toeplitz"))
12221                 info.info.global_conf.hash_func =
12222                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12223         else if (!strcmp(res->hash_func, "simple_xor"))
12224                 info.info.global_conf.hash_func =
12225                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12226         else if (!strcmp(res->hash_func, "default"))
12227                 info.info.global_conf.hash_func =
12228                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12229
12230         ftype = str2flowtype(res->flow_type);
12231         idx = ftype / UINT64_BIT;
12232         offset = ftype % UINT64_BIT;
12233         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12234         if (!strcmp(res->enable, "enable"))
12235                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12236                                                 (1ULL << offset);
12237         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12238                                         RTE_ETH_FILTER_SET, &info);
12239         if (ret < 0)
12240                 printf("Cannot set global hash configurations by port %d\n",
12241                                                         res->port_id);
12242         else
12243                 printf("Global hash configurations have been set "
12244                         "successfully by port %d\n", res->port_id);
12245 }
12246
12247 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12248         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12249                 set_hash_global_config, "set_hash_global_config");
12250 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12251         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12252                 port_id, UINT16);
12253 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12254         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12255                 hash_func, "toeplitz#simple_xor#default");
12256 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12257         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12258                 flow_type,
12259                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12260                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12261 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12262         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12263                 enable, "enable#disable");
12264
12265 cmdline_parse_inst_t cmd_set_hash_global_config = {
12266         .f = cmd_set_hash_global_config_parsed,
12267         .data = NULL,
12268         .help_str = "set_hash_global_config <port_id> "
12269                 "toeplitz|simple_xor|default "
12270                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12271                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12272                 "l2_payload enable|disable",
12273         .tokens = {
12274                 (void *)&cmd_set_hash_global_config_all,
12275                 (void *)&cmd_set_hash_global_config_port_id,
12276                 (void *)&cmd_set_hash_global_config_hash_func,
12277                 (void *)&cmd_set_hash_global_config_flow_type,
12278                 (void *)&cmd_set_hash_global_config_enable,
12279                 NULL,
12280         },
12281 };
12282
12283 /* Set hash input set */
12284 struct cmd_set_hash_input_set_result {
12285         cmdline_fixed_string_t set_hash_input_set;
12286         portid_t port_id;
12287         cmdline_fixed_string_t flow_type;
12288         cmdline_fixed_string_t inset_field;
12289         cmdline_fixed_string_t select;
12290 };
12291
12292 static enum rte_eth_input_set_field
12293 str2inset(char *string)
12294 {
12295         uint16_t i;
12296
12297         static const struct {
12298                 char str[32];
12299                 enum rte_eth_input_set_field inset;
12300         } inset_table[] = {
12301                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12302                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12303                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12304                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12305                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12306                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12307                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12308                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12309                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12310                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12311                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12312                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12313                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12314                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12315                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12316                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12317                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12318                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12319                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12320                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12321                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12322                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12323                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12324                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12325                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12326                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12327                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12328                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12329                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12330                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12331                 {"none", RTE_ETH_INPUT_SET_NONE},
12332         };
12333
12334         for (i = 0; i < RTE_DIM(inset_table); i++) {
12335                 if (!strcmp(string, inset_table[i].str))
12336                         return inset_table[i].inset;
12337         }
12338
12339         return RTE_ETH_INPUT_SET_UNKNOWN;
12340 }
12341
12342 static void
12343 cmd_set_hash_input_set_parsed(void *parsed_result,
12344                               __rte_unused struct cmdline *cl,
12345                               __rte_unused void *data)
12346 {
12347         struct cmd_set_hash_input_set_result *res = parsed_result;
12348         struct rte_eth_hash_filter_info info;
12349
12350         memset(&info, 0, sizeof(info));
12351         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12352         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12353         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12354         info.info.input_set_conf.inset_size = 1;
12355         if (!strcmp(res->select, "select"))
12356                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12357         else if (!strcmp(res->select, "add"))
12358                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12359         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12360                                 RTE_ETH_FILTER_SET, &info);
12361 }
12362
12363 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12364         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12365                 set_hash_input_set, "set_hash_input_set");
12366 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12367         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12368                 port_id, UINT16);
12369 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12370         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12371                 flow_type, NULL);
12372 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12373         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12374                 inset_field,
12375                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12376                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12377                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12378                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12379                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12380                 "fld-8th#none");
12381 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12382         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12383                 select, "select#add");
12384
12385 cmdline_parse_inst_t cmd_set_hash_input_set = {
12386         .f = cmd_set_hash_input_set_parsed,
12387         .data = NULL,
12388         .help_str = "set_hash_input_set <port_id> "
12389         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12390         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12391         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12392         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12393         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12394         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12395         "fld-7th|fld-8th|none select|add",
12396         .tokens = {
12397                 (void *)&cmd_set_hash_input_set_cmd,
12398                 (void *)&cmd_set_hash_input_set_port_id,
12399                 (void *)&cmd_set_hash_input_set_flow_type,
12400                 (void *)&cmd_set_hash_input_set_field,
12401                 (void *)&cmd_set_hash_input_set_select,
12402                 NULL,
12403         },
12404 };
12405
12406 /* Set flow director input set */
12407 struct cmd_set_fdir_input_set_result {
12408         cmdline_fixed_string_t set_fdir_input_set;
12409         portid_t port_id;
12410         cmdline_fixed_string_t flow_type;
12411         cmdline_fixed_string_t inset_field;
12412         cmdline_fixed_string_t select;
12413 };
12414
12415 static void
12416 cmd_set_fdir_input_set_parsed(void *parsed_result,
12417         __rte_unused struct cmdline *cl,
12418         __rte_unused void *data)
12419 {
12420         struct cmd_set_fdir_input_set_result *res = parsed_result;
12421         struct rte_eth_fdir_filter_info info;
12422
12423         memset(&info, 0, sizeof(info));
12424         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12425         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12426         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12427         info.info.input_set_conf.inset_size = 1;
12428         if (!strcmp(res->select, "select"))
12429                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12430         else if (!strcmp(res->select, "add"))
12431                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12432         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12433                 RTE_ETH_FILTER_SET, &info);
12434 }
12435
12436 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12437         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12438         set_fdir_input_set, "set_fdir_input_set");
12439 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12440         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12441         port_id, UINT16);
12442 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12443         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12444         flow_type,
12445         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12446         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12447 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12448         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12449         inset_field,
12450         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12451         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12452         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12453         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12454         "sctp-veri-tag#none");
12455 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12456         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12457         select, "select#add");
12458
12459 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12460         .f = cmd_set_fdir_input_set_parsed,
12461         .data = NULL,
12462         .help_str = "set_fdir_input_set <port_id> "
12463         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12464         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12465         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12466         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12467         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12468         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12469         "sctp-veri-tag|none select|add",
12470         .tokens = {
12471                 (void *)&cmd_set_fdir_input_set_cmd,
12472                 (void *)&cmd_set_fdir_input_set_port_id,
12473                 (void *)&cmd_set_fdir_input_set_flow_type,
12474                 (void *)&cmd_set_fdir_input_set_field,
12475                 (void *)&cmd_set_fdir_input_set_select,
12476                 NULL,
12477         },
12478 };
12479
12480 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12481 struct cmd_mcast_addr_result {
12482         cmdline_fixed_string_t mcast_addr_cmd;
12483         cmdline_fixed_string_t what;
12484         uint16_t port_num;
12485         struct rte_ether_addr mc_addr;
12486 };
12487
12488 static void cmd_mcast_addr_parsed(void *parsed_result,
12489                 __attribute__((unused)) struct cmdline *cl,
12490                 __attribute__((unused)) void *data)
12491 {
12492         struct cmd_mcast_addr_result *res = parsed_result;
12493
12494         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12495                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12496                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12497                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12498                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12499                 return;
12500         }
12501         if (strcmp(res->what, "add") == 0)
12502                 mcast_addr_add(res->port_num, &res->mc_addr);
12503         else
12504                 mcast_addr_remove(res->port_num, &res->mc_addr);
12505 }
12506
12507 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12508         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12509                                  mcast_addr_cmd, "mcast_addr");
12510 cmdline_parse_token_string_t cmd_mcast_addr_what =
12511         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12512                                  "add#remove");
12513 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12514         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12515 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12516         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12517
12518 cmdline_parse_inst_t cmd_mcast_addr = {
12519         .f = cmd_mcast_addr_parsed,
12520         .data = (void *)0,
12521         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12522                 "Add/Remove multicast MAC address on port_id",
12523         .tokens = {
12524                 (void *)&cmd_mcast_addr_cmd,
12525                 (void *)&cmd_mcast_addr_what,
12526                 (void *)&cmd_mcast_addr_portnum,
12527                 (void *)&cmd_mcast_addr_addr,
12528                 NULL,
12529         },
12530 };
12531
12532 /* l2 tunnel config
12533  * only support E-tag now.
12534  */
12535
12536 /* Ether type config */
12537 struct cmd_config_l2_tunnel_eth_type_result {
12538         cmdline_fixed_string_t port;
12539         cmdline_fixed_string_t config;
12540         cmdline_fixed_string_t all;
12541         portid_t id;
12542         cmdline_fixed_string_t l2_tunnel;
12543         cmdline_fixed_string_t l2_tunnel_type;
12544         cmdline_fixed_string_t eth_type;
12545         uint16_t eth_type_val;
12546 };
12547
12548 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12549         TOKEN_STRING_INITIALIZER
12550                 (struct cmd_config_l2_tunnel_eth_type_result,
12551                  port, "port");
12552 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12553         TOKEN_STRING_INITIALIZER
12554                 (struct cmd_config_l2_tunnel_eth_type_result,
12555                  config, "config");
12556 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12557         TOKEN_STRING_INITIALIZER
12558                 (struct cmd_config_l2_tunnel_eth_type_result,
12559                  all, "all");
12560 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12561         TOKEN_NUM_INITIALIZER
12562                 (struct cmd_config_l2_tunnel_eth_type_result,
12563                  id, UINT16);
12564 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12565         TOKEN_STRING_INITIALIZER
12566                 (struct cmd_config_l2_tunnel_eth_type_result,
12567                  l2_tunnel, "l2-tunnel");
12568 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12569         TOKEN_STRING_INITIALIZER
12570                 (struct cmd_config_l2_tunnel_eth_type_result,
12571                  l2_tunnel_type, "E-tag");
12572 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12573         TOKEN_STRING_INITIALIZER
12574                 (struct cmd_config_l2_tunnel_eth_type_result,
12575                  eth_type, "ether-type");
12576 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12577         TOKEN_NUM_INITIALIZER
12578                 (struct cmd_config_l2_tunnel_eth_type_result,
12579                  eth_type_val, UINT16);
12580
12581 static enum rte_eth_tunnel_type
12582 str2fdir_l2_tunnel_type(char *string)
12583 {
12584         uint32_t i = 0;
12585
12586         static const struct {
12587                 char str[32];
12588                 enum rte_eth_tunnel_type type;
12589         } l2_tunnel_type_str[] = {
12590                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12591         };
12592
12593         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12594                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12595                         return l2_tunnel_type_str[i].type;
12596         }
12597         return RTE_TUNNEL_TYPE_NONE;
12598 }
12599
12600 /* ether type config for all ports */
12601 static void
12602 cmd_config_l2_tunnel_eth_type_all_parsed
12603         (void *parsed_result,
12604          __attribute__((unused)) struct cmdline *cl,
12605          __attribute__((unused)) void *data)
12606 {
12607         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12608         struct rte_eth_l2_tunnel_conf entry;
12609         portid_t pid;
12610
12611         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12612         entry.ether_type = res->eth_type_val;
12613
12614         RTE_ETH_FOREACH_DEV(pid) {
12615                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12616         }
12617 }
12618
12619 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12620         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12621         .data = NULL,
12622         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12623         .tokens = {
12624                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12625                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12626                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12627                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12628                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12629                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12630                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12631                 NULL,
12632         },
12633 };
12634
12635 /* ether type config for a specific port */
12636 static void
12637 cmd_config_l2_tunnel_eth_type_specific_parsed(
12638         void *parsed_result,
12639         __attribute__((unused)) struct cmdline *cl,
12640         __attribute__((unused)) void *data)
12641 {
12642         struct cmd_config_l2_tunnel_eth_type_result *res =
12643                  parsed_result;
12644         struct rte_eth_l2_tunnel_conf entry;
12645
12646         if (port_id_is_invalid(res->id, ENABLED_WARN))
12647                 return;
12648
12649         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12650         entry.ether_type = res->eth_type_val;
12651
12652         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12653 }
12654
12655 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12656         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12657         .data = NULL,
12658         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12659         .tokens = {
12660                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12661                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12662                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12663                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12664                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12665                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12666                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12667                 NULL,
12668         },
12669 };
12670
12671 /* Enable/disable l2 tunnel */
12672 struct cmd_config_l2_tunnel_en_dis_result {
12673         cmdline_fixed_string_t port;
12674         cmdline_fixed_string_t config;
12675         cmdline_fixed_string_t all;
12676         portid_t id;
12677         cmdline_fixed_string_t l2_tunnel;
12678         cmdline_fixed_string_t l2_tunnel_type;
12679         cmdline_fixed_string_t en_dis;
12680 };
12681
12682 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12683         TOKEN_STRING_INITIALIZER
12684                 (struct cmd_config_l2_tunnel_en_dis_result,
12685                  port, "port");
12686 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12687         TOKEN_STRING_INITIALIZER
12688                 (struct cmd_config_l2_tunnel_en_dis_result,
12689                  config, "config");
12690 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12691         TOKEN_STRING_INITIALIZER
12692                 (struct cmd_config_l2_tunnel_en_dis_result,
12693                  all, "all");
12694 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12695         TOKEN_NUM_INITIALIZER
12696                 (struct cmd_config_l2_tunnel_en_dis_result,
12697                  id, UINT16);
12698 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12699         TOKEN_STRING_INITIALIZER
12700                 (struct cmd_config_l2_tunnel_en_dis_result,
12701                  l2_tunnel, "l2-tunnel");
12702 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12703         TOKEN_STRING_INITIALIZER
12704                 (struct cmd_config_l2_tunnel_en_dis_result,
12705                  l2_tunnel_type, "E-tag");
12706 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12707         TOKEN_STRING_INITIALIZER
12708                 (struct cmd_config_l2_tunnel_en_dis_result,
12709                  en_dis, "enable#disable");
12710
12711 /* enable/disable l2 tunnel for all ports */
12712 static void
12713 cmd_config_l2_tunnel_en_dis_all_parsed(
12714         void *parsed_result,
12715         __attribute__((unused)) struct cmdline *cl,
12716         __attribute__((unused)) void *data)
12717 {
12718         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12719         struct rte_eth_l2_tunnel_conf entry;
12720         portid_t pid;
12721         uint8_t en;
12722
12723         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12724
12725         if (!strcmp("enable", res->en_dis))
12726                 en = 1;
12727         else
12728                 en = 0;
12729
12730         RTE_ETH_FOREACH_DEV(pid) {
12731                 rte_eth_dev_l2_tunnel_offload_set(pid,
12732                                                   &entry,
12733                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12734                                                   en);
12735         }
12736 }
12737
12738 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12739         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12740         .data = NULL,
12741         .help_str = "port config all l2-tunnel E-tag enable|disable",
12742         .tokens = {
12743                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12744                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12745                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12746                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12747                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12748                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12749                 NULL,
12750         },
12751 };
12752
12753 /* enable/disable l2 tunnel for a port */
12754 static void
12755 cmd_config_l2_tunnel_en_dis_specific_parsed(
12756         void *parsed_result,
12757         __attribute__((unused)) struct cmdline *cl,
12758         __attribute__((unused)) void *data)
12759 {
12760         struct cmd_config_l2_tunnel_en_dis_result *res =
12761                 parsed_result;
12762         struct rte_eth_l2_tunnel_conf entry;
12763
12764         if (port_id_is_invalid(res->id, ENABLED_WARN))
12765                 return;
12766
12767         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12768
12769         if (!strcmp("enable", res->en_dis))
12770                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12771                                                   &entry,
12772                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12773                                                   1);
12774         else
12775                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12776                                                   &entry,
12777                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12778                                                   0);
12779 }
12780
12781 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12782         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12783         .data = NULL,
12784         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12785         .tokens = {
12786                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12787                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12788                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12789                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12790                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12791                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12792                 NULL,
12793         },
12794 };
12795
12796 /* E-tag configuration */
12797
12798 /* Common result structure for all E-tag configuration */
12799 struct cmd_config_e_tag_result {
12800         cmdline_fixed_string_t e_tag;
12801         cmdline_fixed_string_t set;
12802         cmdline_fixed_string_t insertion;
12803         cmdline_fixed_string_t stripping;
12804         cmdline_fixed_string_t forwarding;
12805         cmdline_fixed_string_t filter;
12806         cmdline_fixed_string_t add;
12807         cmdline_fixed_string_t del;
12808         cmdline_fixed_string_t on;
12809         cmdline_fixed_string_t off;
12810         cmdline_fixed_string_t on_off;
12811         cmdline_fixed_string_t port_tag_id;
12812         uint32_t port_tag_id_val;
12813         cmdline_fixed_string_t e_tag_id;
12814         uint16_t e_tag_id_val;
12815         cmdline_fixed_string_t dst_pool;
12816         uint8_t dst_pool_val;
12817         cmdline_fixed_string_t port;
12818         portid_t port_id;
12819         cmdline_fixed_string_t vf;
12820         uint8_t vf_id;
12821 };
12822
12823 /* Common CLI fields for all E-tag configuration */
12824 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12825         TOKEN_STRING_INITIALIZER
12826                 (struct cmd_config_e_tag_result,
12827                  e_tag, "E-tag");
12828 cmdline_parse_token_string_t cmd_config_e_tag_set =
12829         TOKEN_STRING_INITIALIZER
12830                 (struct cmd_config_e_tag_result,
12831                  set, "set");
12832 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12833         TOKEN_STRING_INITIALIZER
12834                 (struct cmd_config_e_tag_result,
12835                  insertion, "insertion");
12836 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12837         TOKEN_STRING_INITIALIZER
12838                 (struct cmd_config_e_tag_result,
12839                  stripping, "stripping");
12840 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12841         TOKEN_STRING_INITIALIZER
12842                 (struct cmd_config_e_tag_result,
12843                  forwarding, "forwarding");
12844 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12845         TOKEN_STRING_INITIALIZER
12846                 (struct cmd_config_e_tag_result,
12847                  filter, "filter");
12848 cmdline_parse_token_string_t cmd_config_e_tag_add =
12849         TOKEN_STRING_INITIALIZER
12850                 (struct cmd_config_e_tag_result,
12851                  add, "add");
12852 cmdline_parse_token_string_t cmd_config_e_tag_del =
12853         TOKEN_STRING_INITIALIZER
12854                 (struct cmd_config_e_tag_result,
12855                  del, "del");
12856 cmdline_parse_token_string_t cmd_config_e_tag_on =
12857         TOKEN_STRING_INITIALIZER
12858                 (struct cmd_config_e_tag_result,
12859                  on, "on");
12860 cmdline_parse_token_string_t cmd_config_e_tag_off =
12861         TOKEN_STRING_INITIALIZER
12862                 (struct cmd_config_e_tag_result,
12863                  off, "off");
12864 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12865         TOKEN_STRING_INITIALIZER
12866                 (struct cmd_config_e_tag_result,
12867                  on_off, "on#off");
12868 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12869         TOKEN_STRING_INITIALIZER
12870                 (struct cmd_config_e_tag_result,
12871                  port_tag_id, "port-tag-id");
12872 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12873         TOKEN_NUM_INITIALIZER
12874                 (struct cmd_config_e_tag_result,
12875                  port_tag_id_val, UINT32);
12876 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_config_e_tag_result,
12879                  e_tag_id, "e-tag-id");
12880 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12881         TOKEN_NUM_INITIALIZER
12882                 (struct cmd_config_e_tag_result,
12883                  e_tag_id_val, UINT16);
12884 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_config_e_tag_result,
12887                  dst_pool, "dst-pool");
12888 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12889         TOKEN_NUM_INITIALIZER
12890                 (struct cmd_config_e_tag_result,
12891                  dst_pool_val, UINT8);
12892 cmdline_parse_token_string_t cmd_config_e_tag_port =
12893         TOKEN_STRING_INITIALIZER
12894                 (struct cmd_config_e_tag_result,
12895                  port, "port");
12896 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12897         TOKEN_NUM_INITIALIZER
12898                 (struct cmd_config_e_tag_result,
12899                  port_id, UINT16);
12900 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12901         TOKEN_STRING_INITIALIZER
12902                 (struct cmd_config_e_tag_result,
12903                  vf, "vf");
12904 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12905         TOKEN_NUM_INITIALIZER
12906                 (struct cmd_config_e_tag_result,
12907                  vf_id, UINT8);
12908
12909 /* E-tag insertion configuration */
12910 static void
12911 cmd_config_e_tag_insertion_en_parsed(
12912         void *parsed_result,
12913         __attribute__((unused)) struct cmdline *cl,
12914         __attribute__((unused)) void *data)
12915 {
12916         struct cmd_config_e_tag_result *res =
12917                 parsed_result;
12918         struct rte_eth_l2_tunnel_conf entry;
12919
12920         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12921                 return;
12922
12923         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12924         entry.tunnel_id = res->port_tag_id_val;
12925         entry.vf_id = res->vf_id;
12926         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12927                                           &entry,
12928                                           ETH_L2_TUNNEL_INSERTION_MASK,
12929                                           1);
12930 }
12931
12932 static void
12933 cmd_config_e_tag_insertion_dis_parsed(
12934         void *parsed_result,
12935         __attribute__((unused)) struct cmdline *cl,
12936         __attribute__((unused)) void *data)
12937 {
12938         struct cmd_config_e_tag_result *res =
12939                 parsed_result;
12940         struct rte_eth_l2_tunnel_conf entry;
12941
12942         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12943                 return;
12944
12945         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12946         entry.vf_id = res->vf_id;
12947
12948         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12949                                           &entry,
12950                                           ETH_L2_TUNNEL_INSERTION_MASK,
12951                                           0);
12952 }
12953
12954 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12955         .f = cmd_config_e_tag_insertion_en_parsed,
12956         .data = NULL,
12957         .help_str = "E-tag ... : E-tag insertion enable",
12958         .tokens = {
12959                 (void *)&cmd_config_e_tag_e_tag,
12960                 (void *)&cmd_config_e_tag_set,
12961                 (void *)&cmd_config_e_tag_insertion,
12962                 (void *)&cmd_config_e_tag_on,
12963                 (void *)&cmd_config_e_tag_port_tag_id,
12964                 (void *)&cmd_config_e_tag_port_tag_id_val,
12965                 (void *)&cmd_config_e_tag_port,
12966                 (void *)&cmd_config_e_tag_port_id,
12967                 (void *)&cmd_config_e_tag_vf,
12968                 (void *)&cmd_config_e_tag_vf_id,
12969                 NULL,
12970         },
12971 };
12972
12973 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12974         .f = cmd_config_e_tag_insertion_dis_parsed,
12975         .data = NULL,
12976         .help_str = "E-tag ... : E-tag insertion disable",
12977         .tokens = {
12978                 (void *)&cmd_config_e_tag_e_tag,
12979                 (void *)&cmd_config_e_tag_set,
12980                 (void *)&cmd_config_e_tag_insertion,
12981                 (void *)&cmd_config_e_tag_off,
12982                 (void *)&cmd_config_e_tag_port,
12983                 (void *)&cmd_config_e_tag_port_id,
12984                 (void *)&cmd_config_e_tag_vf,
12985                 (void *)&cmd_config_e_tag_vf_id,
12986                 NULL,
12987         },
12988 };
12989
12990 /* E-tag stripping configuration */
12991 static void
12992 cmd_config_e_tag_stripping_parsed(
12993         void *parsed_result,
12994         __attribute__((unused)) struct cmdline *cl,
12995         __attribute__((unused)) void *data)
12996 {
12997         struct cmd_config_e_tag_result *res =
12998                 parsed_result;
12999         struct rte_eth_l2_tunnel_conf entry;
13000
13001         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13002                 return;
13003
13004         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13005
13006         if (!strcmp(res->on_off, "on"))
13007                 rte_eth_dev_l2_tunnel_offload_set
13008                         (res->port_id,
13009                          &entry,
13010                          ETH_L2_TUNNEL_STRIPPING_MASK,
13011                          1);
13012         else
13013                 rte_eth_dev_l2_tunnel_offload_set
13014                         (res->port_id,
13015                          &entry,
13016                          ETH_L2_TUNNEL_STRIPPING_MASK,
13017                          0);
13018 }
13019
13020 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13021         .f = cmd_config_e_tag_stripping_parsed,
13022         .data = NULL,
13023         .help_str = "E-tag ... : E-tag stripping enable/disable",
13024         .tokens = {
13025                 (void *)&cmd_config_e_tag_e_tag,
13026                 (void *)&cmd_config_e_tag_set,
13027                 (void *)&cmd_config_e_tag_stripping,
13028                 (void *)&cmd_config_e_tag_on_off,
13029                 (void *)&cmd_config_e_tag_port,
13030                 (void *)&cmd_config_e_tag_port_id,
13031                 NULL,
13032         },
13033 };
13034
13035 /* E-tag forwarding configuration */
13036 static void
13037 cmd_config_e_tag_forwarding_parsed(
13038         void *parsed_result,
13039         __attribute__((unused)) struct cmdline *cl,
13040         __attribute__((unused)) void *data)
13041 {
13042         struct cmd_config_e_tag_result *res = parsed_result;
13043         struct rte_eth_l2_tunnel_conf entry;
13044
13045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13046                 return;
13047
13048         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13049
13050         if (!strcmp(res->on_off, "on"))
13051                 rte_eth_dev_l2_tunnel_offload_set
13052                         (res->port_id,
13053                          &entry,
13054                          ETH_L2_TUNNEL_FORWARDING_MASK,
13055                          1);
13056         else
13057                 rte_eth_dev_l2_tunnel_offload_set
13058                         (res->port_id,
13059                          &entry,
13060                          ETH_L2_TUNNEL_FORWARDING_MASK,
13061                          0);
13062 }
13063
13064 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13065         .f = cmd_config_e_tag_forwarding_parsed,
13066         .data = NULL,
13067         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13068         .tokens = {
13069                 (void *)&cmd_config_e_tag_e_tag,
13070                 (void *)&cmd_config_e_tag_set,
13071                 (void *)&cmd_config_e_tag_forwarding,
13072                 (void *)&cmd_config_e_tag_on_off,
13073                 (void *)&cmd_config_e_tag_port,
13074                 (void *)&cmd_config_e_tag_port_id,
13075                 NULL,
13076         },
13077 };
13078
13079 /* E-tag filter configuration */
13080 static void
13081 cmd_config_e_tag_filter_add_parsed(
13082         void *parsed_result,
13083         __attribute__((unused)) struct cmdline *cl,
13084         __attribute__((unused)) void *data)
13085 {
13086         struct cmd_config_e_tag_result *res = parsed_result;
13087         struct rte_eth_l2_tunnel_conf entry;
13088         int ret = 0;
13089
13090         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13091                 return;
13092
13093         if (res->e_tag_id_val > 0x3fff) {
13094                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13095                 return;
13096         }
13097
13098         ret = rte_eth_dev_filter_supported(res->port_id,
13099                                            RTE_ETH_FILTER_L2_TUNNEL);
13100         if (ret < 0) {
13101                 printf("E-tag filter is not supported on port %u.\n",
13102                        res->port_id);
13103                 return;
13104         }
13105
13106         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13107         entry.tunnel_id = res->e_tag_id_val;
13108         entry.pool = res->dst_pool_val;
13109
13110         ret = rte_eth_dev_filter_ctrl(res->port_id,
13111                                       RTE_ETH_FILTER_L2_TUNNEL,
13112                                       RTE_ETH_FILTER_ADD,
13113                                       &entry);
13114         if (ret < 0)
13115                 printf("E-tag filter programming error: (%s)\n",
13116                        strerror(-ret));
13117 }
13118
13119 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13120         .f = cmd_config_e_tag_filter_add_parsed,
13121         .data = NULL,
13122         .help_str = "E-tag ... : E-tag filter add",
13123         .tokens = {
13124                 (void *)&cmd_config_e_tag_e_tag,
13125                 (void *)&cmd_config_e_tag_set,
13126                 (void *)&cmd_config_e_tag_filter,
13127                 (void *)&cmd_config_e_tag_add,
13128                 (void *)&cmd_config_e_tag_e_tag_id,
13129                 (void *)&cmd_config_e_tag_e_tag_id_val,
13130                 (void *)&cmd_config_e_tag_dst_pool,
13131                 (void *)&cmd_config_e_tag_dst_pool_val,
13132                 (void *)&cmd_config_e_tag_port,
13133                 (void *)&cmd_config_e_tag_port_id,
13134                 NULL,
13135         },
13136 };
13137
13138 static void
13139 cmd_config_e_tag_filter_del_parsed(
13140         void *parsed_result,
13141         __attribute__((unused)) struct cmdline *cl,
13142         __attribute__((unused)) void *data)
13143 {
13144         struct cmd_config_e_tag_result *res = parsed_result;
13145         struct rte_eth_l2_tunnel_conf entry;
13146         int ret = 0;
13147
13148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13149                 return;
13150
13151         if (res->e_tag_id_val > 0x3fff) {
13152                 printf("e-tag-id must be less than 0x3fff.\n");
13153                 return;
13154         }
13155
13156         ret = rte_eth_dev_filter_supported(res->port_id,
13157                                            RTE_ETH_FILTER_L2_TUNNEL);
13158         if (ret < 0) {
13159                 printf("E-tag filter is not supported on port %u.\n",
13160                        res->port_id);
13161                 return;
13162         }
13163
13164         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13165         entry.tunnel_id = res->e_tag_id_val;
13166
13167         ret = rte_eth_dev_filter_ctrl(res->port_id,
13168                                       RTE_ETH_FILTER_L2_TUNNEL,
13169                                       RTE_ETH_FILTER_DELETE,
13170                                       &entry);
13171         if (ret < 0)
13172                 printf("E-tag filter programming error: (%s)\n",
13173                        strerror(-ret));
13174 }
13175
13176 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13177         .f = cmd_config_e_tag_filter_del_parsed,
13178         .data = NULL,
13179         .help_str = "E-tag ... : E-tag filter delete",
13180         .tokens = {
13181                 (void *)&cmd_config_e_tag_e_tag,
13182                 (void *)&cmd_config_e_tag_set,
13183                 (void *)&cmd_config_e_tag_filter,
13184                 (void *)&cmd_config_e_tag_del,
13185                 (void *)&cmd_config_e_tag_e_tag_id,
13186                 (void *)&cmd_config_e_tag_e_tag_id_val,
13187                 (void *)&cmd_config_e_tag_port,
13188                 (void *)&cmd_config_e_tag_port_id,
13189                 NULL,
13190         },
13191 };
13192
13193 /* vf vlan anti spoof configuration */
13194
13195 /* Common result structure for vf vlan anti spoof */
13196 struct cmd_vf_vlan_anti_spoof_result {
13197         cmdline_fixed_string_t set;
13198         cmdline_fixed_string_t vf;
13199         cmdline_fixed_string_t vlan;
13200         cmdline_fixed_string_t antispoof;
13201         portid_t port_id;
13202         uint32_t vf_id;
13203         cmdline_fixed_string_t on_off;
13204 };
13205
13206 /* Common CLI fields for vf vlan anti spoof enable disable */
13207 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13208         TOKEN_STRING_INITIALIZER
13209                 (struct cmd_vf_vlan_anti_spoof_result,
13210                  set, "set");
13211 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13212         TOKEN_STRING_INITIALIZER
13213                 (struct cmd_vf_vlan_anti_spoof_result,
13214                  vf, "vf");
13215 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13216         TOKEN_STRING_INITIALIZER
13217                 (struct cmd_vf_vlan_anti_spoof_result,
13218                  vlan, "vlan");
13219 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13220         TOKEN_STRING_INITIALIZER
13221                 (struct cmd_vf_vlan_anti_spoof_result,
13222                  antispoof, "antispoof");
13223 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13224         TOKEN_NUM_INITIALIZER
13225                 (struct cmd_vf_vlan_anti_spoof_result,
13226                  port_id, UINT16);
13227 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13228         TOKEN_NUM_INITIALIZER
13229                 (struct cmd_vf_vlan_anti_spoof_result,
13230                  vf_id, UINT32);
13231 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13232         TOKEN_STRING_INITIALIZER
13233                 (struct cmd_vf_vlan_anti_spoof_result,
13234                  on_off, "on#off");
13235
13236 static void
13237 cmd_set_vf_vlan_anti_spoof_parsed(
13238         void *parsed_result,
13239         __attribute__((unused)) struct cmdline *cl,
13240         __attribute__((unused)) void *data)
13241 {
13242         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13243         int ret = -ENOTSUP;
13244
13245         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13246
13247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13248                 return;
13249
13250 #ifdef RTE_LIBRTE_IXGBE_PMD
13251         if (ret == -ENOTSUP)
13252                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13253                                 res->vf_id, is_on);
13254 #endif
13255 #ifdef RTE_LIBRTE_I40E_PMD
13256         if (ret == -ENOTSUP)
13257                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13258                                 res->vf_id, is_on);
13259 #endif
13260 #ifdef RTE_LIBRTE_BNXT_PMD
13261         if (ret == -ENOTSUP)
13262                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13263                                 res->vf_id, is_on);
13264 #endif
13265
13266         switch (ret) {
13267         case 0:
13268                 break;
13269         case -EINVAL:
13270                 printf("invalid vf_id %d\n", res->vf_id);
13271                 break;
13272         case -ENODEV:
13273                 printf("invalid port_id %d\n", res->port_id);
13274                 break;
13275         case -ENOTSUP:
13276                 printf("function not implemented\n");
13277                 break;
13278         default:
13279                 printf("programming error: (%s)\n", strerror(-ret));
13280         }
13281 }
13282
13283 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13284         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13285         .data = NULL,
13286         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13287         .tokens = {
13288                 (void *)&cmd_vf_vlan_anti_spoof_set,
13289                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13290                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13291                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13292                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13293                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13294                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13295                 NULL,
13296         },
13297 };
13298
13299 /* vf mac anti spoof configuration */
13300
13301 /* Common result structure for vf mac anti spoof */
13302 struct cmd_vf_mac_anti_spoof_result {
13303         cmdline_fixed_string_t set;
13304         cmdline_fixed_string_t vf;
13305         cmdline_fixed_string_t mac;
13306         cmdline_fixed_string_t antispoof;
13307         portid_t port_id;
13308         uint32_t vf_id;
13309         cmdline_fixed_string_t on_off;
13310 };
13311
13312 /* Common CLI fields for vf mac anti spoof enable disable */
13313 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13314         TOKEN_STRING_INITIALIZER
13315                 (struct cmd_vf_mac_anti_spoof_result,
13316                  set, "set");
13317 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13318         TOKEN_STRING_INITIALIZER
13319                 (struct cmd_vf_mac_anti_spoof_result,
13320                  vf, "vf");
13321 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13322         TOKEN_STRING_INITIALIZER
13323                 (struct cmd_vf_mac_anti_spoof_result,
13324                  mac, "mac");
13325 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13326         TOKEN_STRING_INITIALIZER
13327                 (struct cmd_vf_mac_anti_spoof_result,
13328                  antispoof, "antispoof");
13329 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13330         TOKEN_NUM_INITIALIZER
13331                 (struct cmd_vf_mac_anti_spoof_result,
13332                  port_id, UINT16);
13333 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13334         TOKEN_NUM_INITIALIZER
13335                 (struct cmd_vf_mac_anti_spoof_result,
13336                  vf_id, UINT32);
13337 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13338         TOKEN_STRING_INITIALIZER
13339                 (struct cmd_vf_mac_anti_spoof_result,
13340                  on_off, "on#off");
13341
13342 static void
13343 cmd_set_vf_mac_anti_spoof_parsed(
13344         void *parsed_result,
13345         __attribute__((unused)) struct cmdline *cl,
13346         __attribute__((unused)) void *data)
13347 {
13348         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13349         int ret = -ENOTSUP;
13350
13351         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13352
13353         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13354                 return;
13355
13356 #ifdef RTE_LIBRTE_IXGBE_PMD
13357         if (ret == -ENOTSUP)
13358                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13359                         res->vf_id, is_on);
13360 #endif
13361 #ifdef RTE_LIBRTE_I40E_PMD
13362         if (ret == -ENOTSUP)
13363                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13364                         res->vf_id, is_on);
13365 #endif
13366 #ifdef RTE_LIBRTE_BNXT_PMD
13367         if (ret == -ENOTSUP)
13368                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13369                         res->vf_id, is_on);
13370 #endif
13371
13372         switch (ret) {
13373         case 0:
13374                 break;
13375         case -EINVAL:
13376                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13377                 break;
13378         case -ENODEV:
13379                 printf("invalid port_id %d\n", res->port_id);
13380                 break;
13381         case -ENOTSUP:
13382                 printf("function not implemented\n");
13383                 break;
13384         default:
13385                 printf("programming error: (%s)\n", strerror(-ret));
13386         }
13387 }
13388
13389 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13390         .f = cmd_set_vf_mac_anti_spoof_parsed,
13391         .data = NULL,
13392         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13393         .tokens = {
13394                 (void *)&cmd_vf_mac_anti_spoof_set,
13395                 (void *)&cmd_vf_mac_anti_spoof_vf,
13396                 (void *)&cmd_vf_mac_anti_spoof_mac,
13397                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13398                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13399                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13400                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13401                 NULL,
13402         },
13403 };
13404
13405 /* vf vlan strip queue configuration */
13406
13407 /* Common result structure for vf mac anti spoof */
13408 struct cmd_vf_vlan_stripq_result {
13409         cmdline_fixed_string_t set;
13410         cmdline_fixed_string_t vf;
13411         cmdline_fixed_string_t vlan;
13412         cmdline_fixed_string_t stripq;
13413         portid_t port_id;
13414         uint16_t vf_id;
13415         cmdline_fixed_string_t on_off;
13416 };
13417
13418 /* Common CLI fields for vf vlan strip enable disable */
13419 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13420         TOKEN_STRING_INITIALIZER
13421                 (struct cmd_vf_vlan_stripq_result,
13422                  set, "set");
13423 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13424         TOKEN_STRING_INITIALIZER
13425                 (struct cmd_vf_vlan_stripq_result,
13426                  vf, "vf");
13427 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13428         TOKEN_STRING_INITIALIZER
13429                 (struct cmd_vf_vlan_stripq_result,
13430                  vlan, "vlan");
13431 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_vf_vlan_stripq_result,
13434                  stripq, "stripq");
13435 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13436         TOKEN_NUM_INITIALIZER
13437                 (struct cmd_vf_vlan_stripq_result,
13438                  port_id, UINT16);
13439 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13440         TOKEN_NUM_INITIALIZER
13441                 (struct cmd_vf_vlan_stripq_result,
13442                  vf_id, UINT16);
13443 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_vf_vlan_stripq_result,
13446                  on_off, "on#off");
13447
13448 static void
13449 cmd_set_vf_vlan_stripq_parsed(
13450         void *parsed_result,
13451         __attribute__((unused)) struct cmdline *cl,
13452         __attribute__((unused)) void *data)
13453 {
13454         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13455         int ret = -ENOTSUP;
13456
13457         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13458
13459         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13460                 return;
13461
13462 #ifdef RTE_LIBRTE_IXGBE_PMD
13463         if (ret == -ENOTSUP)
13464                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13465                         res->vf_id, is_on);
13466 #endif
13467 #ifdef RTE_LIBRTE_I40E_PMD
13468         if (ret == -ENOTSUP)
13469                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13470                         res->vf_id, is_on);
13471 #endif
13472 #ifdef RTE_LIBRTE_BNXT_PMD
13473         if (ret == -ENOTSUP)
13474                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13475                         res->vf_id, is_on);
13476 #endif
13477
13478         switch (ret) {
13479         case 0:
13480                 break;
13481         case -EINVAL:
13482                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13483                 break;
13484         case -ENODEV:
13485                 printf("invalid port_id %d\n", res->port_id);
13486                 break;
13487         case -ENOTSUP:
13488                 printf("function not implemented\n");
13489                 break;
13490         default:
13491                 printf("programming error: (%s)\n", strerror(-ret));
13492         }
13493 }
13494
13495 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13496         .f = cmd_set_vf_vlan_stripq_parsed,
13497         .data = NULL,
13498         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13499         .tokens = {
13500                 (void *)&cmd_vf_vlan_stripq_set,
13501                 (void *)&cmd_vf_vlan_stripq_vf,
13502                 (void *)&cmd_vf_vlan_stripq_vlan,
13503                 (void *)&cmd_vf_vlan_stripq_stripq,
13504                 (void *)&cmd_vf_vlan_stripq_port_id,
13505                 (void *)&cmd_vf_vlan_stripq_vf_id,
13506                 (void *)&cmd_vf_vlan_stripq_on_off,
13507                 NULL,
13508         },
13509 };
13510
13511 /* vf vlan insert configuration */
13512
13513 /* Common result structure for vf vlan insert */
13514 struct cmd_vf_vlan_insert_result {
13515         cmdline_fixed_string_t set;
13516         cmdline_fixed_string_t vf;
13517         cmdline_fixed_string_t vlan;
13518         cmdline_fixed_string_t insert;
13519         portid_t port_id;
13520         uint16_t vf_id;
13521         uint16_t vlan_id;
13522 };
13523
13524 /* Common CLI fields for vf vlan insert enable disable */
13525 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13526         TOKEN_STRING_INITIALIZER
13527                 (struct cmd_vf_vlan_insert_result,
13528                  set, "set");
13529 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13530         TOKEN_STRING_INITIALIZER
13531                 (struct cmd_vf_vlan_insert_result,
13532                  vf, "vf");
13533 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13534         TOKEN_STRING_INITIALIZER
13535                 (struct cmd_vf_vlan_insert_result,
13536                  vlan, "vlan");
13537 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_vf_vlan_insert_result,
13540                  insert, "insert");
13541 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13542         TOKEN_NUM_INITIALIZER
13543                 (struct cmd_vf_vlan_insert_result,
13544                  port_id, UINT16);
13545 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13546         TOKEN_NUM_INITIALIZER
13547                 (struct cmd_vf_vlan_insert_result,
13548                  vf_id, UINT16);
13549 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13550         TOKEN_NUM_INITIALIZER
13551                 (struct cmd_vf_vlan_insert_result,
13552                  vlan_id, UINT16);
13553
13554 static void
13555 cmd_set_vf_vlan_insert_parsed(
13556         void *parsed_result,
13557         __attribute__((unused)) struct cmdline *cl,
13558         __attribute__((unused)) void *data)
13559 {
13560         struct cmd_vf_vlan_insert_result *res = parsed_result;
13561         int ret = -ENOTSUP;
13562
13563         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13564                 return;
13565
13566 #ifdef RTE_LIBRTE_IXGBE_PMD
13567         if (ret == -ENOTSUP)
13568                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13569                         res->vlan_id);
13570 #endif
13571 #ifdef RTE_LIBRTE_I40E_PMD
13572         if (ret == -ENOTSUP)
13573                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13574                         res->vlan_id);
13575 #endif
13576 #ifdef RTE_LIBRTE_BNXT_PMD
13577         if (ret == -ENOTSUP)
13578                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13579                         res->vlan_id);
13580 #endif
13581
13582         switch (ret) {
13583         case 0:
13584                 break;
13585         case -EINVAL:
13586                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13587                 break;
13588         case -ENODEV:
13589                 printf("invalid port_id %d\n", res->port_id);
13590                 break;
13591         case -ENOTSUP:
13592                 printf("function not implemented\n");
13593                 break;
13594         default:
13595                 printf("programming error: (%s)\n", strerror(-ret));
13596         }
13597 }
13598
13599 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13600         .f = cmd_set_vf_vlan_insert_parsed,
13601         .data = NULL,
13602         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13603         .tokens = {
13604                 (void *)&cmd_vf_vlan_insert_set,
13605                 (void *)&cmd_vf_vlan_insert_vf,
13606                 (void *)&cmd_vf_vlan_insert_vlan,
13607                 (void *)&cmd_vf_vlan_insert_insert,
13608                 (void *)&cmd_vf_vlan_insert_port_id,
13609                 (void *)&cmd_vf_vlan_insert_vf_id,
13610                 (void *)&cmd_vf_vlan_insert_vlan_id,
13611                 NULL,
13612         },
13613 };
13614
13615 /* tx loopback configuration */
13616
13617 /* Common result structure for tx loopback */
13618 struct cmd_tx_loopback_result {
13619         cmdline_fixed_string_t set;
13620         cmdline_fixed_string_t tx;
13621         cmdline_fixed_string_t loopback;
13622         portid_t port_id;
13623         cmdline_fixed_string_t on_off;
13624 };
13625
13626 /* Common CLI fields for tx loopback enable disable */
13627 cmdline_parse_token_string_t cmd_tx_loopback_set =
13628         TOKEN_STRING_INITIALIZER
13629                 (struct cmd_tx_loopback_result,
13630                  set, "set");
13631 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_tx_loopback_result,
13634                  tx, "tx");
13635 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13636         TOKEN_STRING_INITIALIZER
13637                 (struct cmd_tx_loopback_result,
13638                  loopback, "loopback");
13639 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13640         TOKEN_NUM_INITIALIZER
13641                 (struct cmd_tx_loopback_result,
13642                  port_id, UINT16);
13643 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_tx_loopback_result,
13646                  on_off, "on#off");
13647
13648 static void
13649 cmd_set_tx_loopback_parsed(
13650         void *parsed_result,
13651         __attribute__((unused)) struct cmdline *cl,
13652         __attribute__((unused)) void *data)
13653 {
13654         struct cmd_tx_loopback_result *res = parsed_result;
13655         int ret = -ENOTSUP;
13656
13657         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13658
13659         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13660                 return;
13661
13662 #ifdef RTE_LIBRTE_IXGBE_PMD
13663         if (ret == -ENOTSUP)
13664                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13665 #endif
13666 #ifdef RTE_LIBRTE_I40E_PMD
13667         if (ret == -ENOTSUP)
13668                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13669 #endif
13670 #ifdef RTE_LIBRTE_BNXT_PMD
13671         if (ret == -ENOTSUP)
13672                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13673 #endif
13674 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13675         if (ret == -ENOTSUP)
13676                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13677 #endif
13678
13679         switch (ret) {
13680         case 0:
13681                 break;
13682         case -EINVAL:
13683                 printf("invalid is_on %d\n", is_on);
13684                 break;
13685         case -ENODEV:
13686                 printf("invalid port_id %d\n", res->port_id);
13687                 break;
13688         case -ENOTSUP:
13689                 printf("function not implemented\n");
13690                 break;
13691         default:
13692                 printf("programming error: (%s)\n", strerror(-ret));
13693         }
13694 }
13695
13696 cmdline_parse_inst_t cmd_set_tx_loopback = {
13697         .f = cmd_set_tx_loopback_parsed,
13698         .data = NULL,
13699         .help_str = "set tx loopback <port_id> on|off",
13700         .tokens = {
13701                 (void *)&cmd_tx_loopback_set,
13702                 (void *)&cmd_tx_loopback_tx,
13703                 (void *)&cmd_tx_loopback_loopback,
13704                 (void *)&cmd_tx_loopback_port_id,
13705                 (void *)&cmd_tx_loopback_on_off,
13706                 NULL,
13707         },
13708 };
13709
13710 /* all queues drop enable configuration */
13711
13712 /* Common result structure for all queues drop enable */
13713 struct cmd_all_queues_drop_en_result {
13714         cmdline_fixed_string_t set;
13715         cmdline_fixed_string_t all;
13716         cmdline_fixed_string_t queues;
13717         cmdline_fixed_string_t drop;
13718         portid_t port_id;
13719         cmdline_fixed_string_t on_off;
13720 };
13721
13722 /* Common CLI fields for tx loopback enable disable */
13723 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13724         TOKEN_STRING_INITIALIZER
13725                 (struct cmd_all_queues_drop_en_result,
13726                  set, "set");
13727 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13728         TOKEN_STRING_INITIALIZER
13729                 (struct cmd_all_queues_drop_en_result,
13730                  all, "all");
13731 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13732         TOKEN_STRING_INITIALIZER
13733                 (struct cmd_all_queues_drop_en_result,
13734                  queues, "queues");
13735 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13736         TOKEN_STRING_INITIALIZER
13737                 (struct cmd_all_queues_drop_en_result,
13738                  drop, "drop");
13739 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13740         TOKEN_NUM_INITIALIZER
13741                 (struct cmd_all_queues_drop_en_result,
13742                  port_id, UINT16);
13743 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_all_queues_drop_en_result,
13746                  on_off, "on#off");
13747
13748 static void
13749 cmd_set_all_queues_drop_en_parsed(
13750         void *parsed_result,
13751         __attribute__((unused)) struct cmdline *cl,
13752         __attribute__((unused)) void *data)
13753 {
13754         struct cmd_all_queues_drop_en_result *res = parsed_result;
13755         int ret = -ENOTSUP;
13756         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13757
13758         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13759                 return;
13760
13761 #ifdef RTE_LIBRTE_IXGBE_PMD
13762         if (ret == -ENOTSUP)
13763                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13764 #endif
13765 #ifdef RTE_LIBRTE_BNXT_PMD
13766         if (ret == -ENOTSUP)
13767                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13768 #endif
13769         switch (ret) {
13770         case 0:
13771                 break;
13772         case -EINVAL:
13773                 printf("invalid is_on %d\n", is_on);
13774                 break;
13775         case -ENODEV:
13776                 printf("invalid port_id %d\n", res->port_id);
13777                 break;
13778         case -ENOTSUP:
13779                 printf("function not implemented\n");
13780                 break;
13781         default:
13782                 printf("programming error: (%s)\n", strerror(-ret));
13783         }
13784 }
13785
13786 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13787         .f = cmd_set_all_queues_drop_en_parsed,
13788         .data = NULL,
13789         .help_str = "set all queues drop <port_id> on|off",
13790         .tokens = {
13791                 (void *)&cmd_all_queues_drop_en_set,
13792                 (void *)&cmd_all_queues_drop_en_all,
13793                 (void *)&cmd_all_queues_drop_en_queues,
13794                 (void *)&cmd_all_queues_drop_en_drop,
13795                 (void *)&cmd_all_queues_drop_en_port_id,
13796                 (void *)&cmd_all_queues_drop_en_on_off,
13797                 NULL,
13798         },
13799 };
13800
13801 /* vf split drop enable configuration */
13802
13803 /* Common result structure for vf split drop enable */
13804 struct cmd_vf_split_drop_en_result {
13805         cmdline_fixed_string_t set;
13806         cmdline_fixed_string_t vf;
13807         cmdline_fixed_string_t split;
13808         cmdline_fixed_string_t drop;
13809         portid_t port_id;
13810         uint16_t vf_id;
13811         cmdline_fixed_string_t on_off;
13812 };
13813
13814 /* Common CLI fields for vf split drop enable disable */
13815 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13816         TOKEN_STRING_INITIALIZER
13817                 (struct cmd_vf_split_drop_en_result,
13818                  set, "set");
13819 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13820         TOKEN_STRING_INITIALIZER
13821                 (struct cmd_vf_split_drop_en_result,
13822                  vf, "vf");
13823 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13824         TOKEN_STRING_INITIALIZER
13825                 (struct cmd_vf_split_drop_en_result,
13826                  split, "split");
13827 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13828         TOKEN_STRING_INITIALIZER
13829                 (struct cmd_vf_split_drop_en_result,
13830                  drop, "drop");
13831 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13832         TOKEN_NUM_INITIALIZER
13833                 (struct cmd_vf_split_drop_en_result,
13834                  port_id, UINT16);
13835 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13836         TOKEN_NUM_INITIALIZER
13837                 (struct cmd_vf_split_drop_en_result,
13838                  vf_id, UINT16);
13839 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13840         TOKEN_STRING_INITIALIZER
13841                 (struct cmd_vf_split_drop_en_result,
13842                  on_off, "on#off");
13843
13844 static void
13845 cmd_set_vf_split_drop_en_parsed(
13846         void *parsed_result,
13847         __attribute__((unused)) struct cmdline *cl,
13848         __attribute__((unused)) void *data)
13849 {
13850         struct cmd_vf_split_drop_en_result *res = parsed_result;
13851         int ret = -ENOTSUP;
13852         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13853
13854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13855                 return;
13856
13857 #ifdef RTE_LIBRTE_IXGBE_PMD
13858         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13859                         is_on);
13860 #endif
13861         switch (ret) {
13862         case 0:
13863                 break;
13864         case -EINVAL:
13865                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13866                 break;
13867         case -ENODEV:
13868                 printf("invalid port_id %d\n", res->port_id);
13869                 break;
13870         case -ENOTSUP:
13871                 printf("not supported on port %d\n", res->port_id);
13872                 break;
13873         default:
13874                 printf("programming error: (%s)\n", strerror(-ret));
13875         }
13876 }
13877
13878 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13879         .f = cmd_set_vf_split_drop_en_parsed,
13880         .data = NULL,
13881         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13882         .tokens = {
13883                 (void *)&cmd_vf_split_drop_en_set,
13884                 (void *)&cmd_vf_split_drop_en_vf,
13885                 (void *)&cmd_vf_split_drop_en_split,
13886                 (void *)&cmd_vf_split_drop_en_drop,
13887                 (void *)&cmd_vf_split_drop_en_port_id,
13888                 (void *)&cmd_vf_split_drop_en_vf_id,
13889                 (void *)&cmd_vf_split_drop_en_on_off,
13890                 NULL,
13891         },
13892 };
13893
13894 /* vf mac address configuration */
13895
13896 /* Common result structure for vf mac address */
13897 struct cmd_set_vf_mac_addr_result {
13898         cmdline_fixed_string_t set;
13899         cmdline_fixed_string_t vf;
13900         cmdline_fixed_string_t mac;
13901         cmdline_fixed_string_t addr;
13902         portid_t port_id;
13903         uint16_t vf_id;
13904         struct rte_ether_addr mac_addr;
13905
13906 };
13907
13908 /* Common CLI fields for vf split drop enable disable */
13909 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13910         TOKEN_STRING_INITIALIZER
13911                 (struct cmd_set_vf_mac_addr_result,
13912                  set, "set");
13913 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13914         TOKEN_STRING_INITIALIZER
13915                 (struct cmd_set_vf_mac_addr_result,
13916                  vf, "vf");
13917 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13918         TOKEN_STRING_INITIALIZER
13919                 (struct cmd_set_vf_mac_addr_result,
13920                  mac, "mac");
13921 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13922         TOKEN_STRING_INITIALIZER
13923                 (struct cmd_set_vf_mac_addr_result,
13924                  addr, "addr");
13925 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13926         TOKEN_NUM_INITIALIZER
13927                 (struct cmd_set_vf_mac_addr_result,
13928                  port_id, UINT16);
13929 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13930         TOKEN_NUM_INITIALIZER
13931                 (struct cmd_set_vf_mac_addr_result,
13932                  vf_id, UINT16);
13933 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13934         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13935                  mac_addr);
13936
13937 static void
13938 cmd_set_vf_mac_addr_parsed(
13939         void *parsed_result,
13940         __attribute__((unused)) struct cmdline *cl,
13941         __attribute__((unused)) void *data)
13942 {
13943         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13944         int ret = -ENOTSUP;
13945
13946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13947                 return;
13948
13949 #ifdef RTE_LIBRTE_IXGBE_PMD
13950         if (ret == -ENOTSUP)
13951                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13952                                 &res->mac_addr);
13953 #endif
13954 #ifdef RTE_LIBRTE_I40E_PMD
13955         if (ret == -ENOTSUP)
13956                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13957                                 &res->mac_addr);
13958 #endif
13959 #ifdef RTE_LIBRTE_BNXT_PMD
13960         if (ret == -ENOTSUP)
13961                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13962                                 &res->mac_addr);
13963 #endif
13964
13965         switch (ret) {
13966         case 0:
13967                 break;
13968         case -EINVAL:
13969                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13970                 break;
13971         case -ENODEV:
13972                 printf("invalid port_id %d\n", res->port_id);
13973                 break;
13974         case -ENOTSUP:
13975                 printf("function not implemented\n");
13976                 break;
13977         default:
13978                 printf("programming error: (%s)\n", strerror(-ret));
13979         }
13980 }
13981
13982 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13983         .f = cmd_set_vf_mac_addr_parsed,
13984         .data = NULL,
13985         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13986         .tokens = {
13987                 (void *)&cmd_set_vf_mac_addr_set,
13988                 (void *)&cmd_set_vf_mac_addr_vf,
13989                 (void *)&cmd_set_vf_mac_addr_mac,
13990                 (void *)&cmd_set_vf_mac_addr_addr,
13991                 (void *)&cmd_set_vf_mac_addr_port_id,
13992                 (void *)&cmd_set_vf_mac_addr_vf_id,
13993                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13994                 NULL,
13995         },
13996 };
13997
13998 /* MACsec configuration */
13999
14000 /* Common result structure for MACsec offload enable */
14001 struct cmd_macsec_offload_on_result {
14002         cmdline_fixed_string_t set;
14003         cmdline_fixed_string_t macsec;
14004         cmdline_fixed_string_t offload;
14005         portid_t port_id;
14006         cmdline_fixed_string_t on;
14007         cmdline_fixed_string_t encrypt;
14008         cmdline_fixed_string_t en_on_off;
14009         cmdline_fixed_string_t replay_protect;
14010         cmdline_fixed_string_t rp_on_off;
14011 };
14012
14013 /* Common CLI fields for MACsec offload disable */
14014 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14015         TOKEN_STRING_INITIALIZER
14016                 (struct cmd_macsec_offload_on_result,
14017                  set, "set");
14018 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14019         TOKEN_STRING_INITIALIZER
14020                 (struct cmd_macsec_offload_on_result,
14021                  macsec, "macsec");
14022 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14023         TOKEN_STRING_INITIALIZER
14024                 (struct cmd_macsec_offload_on_result,
14025                  offload, "offload");
14026 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14027         TOKEN_NUM_INITIALIZER
14028                 (struct cmd_macsec_offload_on_result,
14029                  port_id, UINT16);
14030 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14031         TOKEN_STRING_INITIALIZER
14032                 (struct cmd_macsec_offload_on_result,
14033                  on, "on");
14034 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14035         TOKEN_STRING_INITIALIZER
14036                 (struct cmd_macsec_offload_on_result,
14037                  encrypt, "encrypt");
14038 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14039         TOKEN_STRING_INITIALIZER
14040                 (struct cmd_macsec_offload_on_result,
14041                  en_on_off, "on#off");
14042 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14043         TOKEN_STRING_INITIALIZER
14044                 (struct cmd_macsec_offload_on_result,
14045                  replay_protect, "replay-protect");
14046 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14047         TOKEN_STRING_INITIALIZER
14048                 (struct cmd_macsec_offload_on_result,
14049                  rp_on_off, "on#off");
14050
14051 static void
14052 cmd_set_macsec_offload_on_parsed(
14053         void *parsed_result,
14054         __attribute__((unused)) struct cmdline *cl,
14055         __attribute__((unused)) void *data)
14056 {
14057         struct cmd_macsec_offload_on_result *res = parsed_result;
14058         int ret = -ENOTSUP;
14059         portid_t port_id = res->port_id;
14060         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14061         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14062         struct rte_eth_dev_info dev_info;
14063
14064         if (port_id_is_invalid(port_id, ENABLED_WARN))
14065                 return;
14066         if (!port_is_stopped(port_id)) {
14067                 printf("Please stop port %d first\n", port_id);
14068                 return;
14069         }
14070
14071         rte_eth_dev_info_get(port_id, &dev_info);
14072         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14073 #ifdef RTE_LIBRTE_IXGBE_PMD
14074                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14075 #endif
14076         }
14077         RTE_SET_USED(en);
14078         RTE_SET_USED(rp);
14079
14080         switch (ret) {
14081         case 0:
14082                 ports[port_id].dev_conf.txmode.offloads |=
14083                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14084                 cmd_reconfig_device_queue(port_id, 1, 1);
14085                 break;
14086         case -ENODEV:
14087                 printf("invalid port_id %d\n", port_id);
14088                 break;
14089         case -ENOTSUP:
14090                 printf("not supported on port %d\n", port_id);
14091                 break;
14092         default:
14093                 printf("programming error: (%s)\n", strerror(-ret));
14094         }
14095 }
14096
14097 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14098         .f = cmd_set_macsec_offload_on_parsed,
14099         .data = NULL,
14100         .help_str = "set macsec offload <port_id> on "
14101                 "encrypt on|off replay-protect on|off",
14102         .tokens = {
14103                 (void *)&cmd_macsec_offload_on_set,
14104                 (void *)&cmd_macsec_offload_on_macsec,
14105                 (void *)&cmd_macsec_offload_on_offload,
14106                 (void *)&cmd_macsec_offload_on_port_id,
14107                 (void *)&cmd_macsec_offload_on_on,
14108                 (void *)&cmd_macsec_offload_on_encrypt,
14109                 (void *)&cmd_macsec_offload_on_en_on_off,
14110                 (void *)&cmd_macsec_offload_on_replay_protect,
14111                 (void *)&cmd_macsec_offload_on_rp_on_off,
14112                 NULL,
14113         },
14114 };
14115
14116 /* Common result structure for MACsec offload disable */
14117 struct cmd_macsec_offload_off_result {
14118         cmdline_fixed_string_t set;
14119         cmdline_fixed_string_t macsec;
14120         cmdline_fixed_string_t offload;
14121         portid_t port_id;
14122         cmdline_fixed_string_t off;
14123 };
14124
14125 /* Common CLI fields for MACsec offload disable */
14126 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14127         TOKEN_STRING_INITIALIZER
14128                 (struct cmd_macsec_offload_off_result,
14129                  set, "set");
14130 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14131         TOKEN_STRING_INITIALIZER
14132                 (struct cmd_macsec_offload_off_result,
14133                  macsec, "macsec");
14134 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14135         TOKEN_STRING_INITIALIZER
14136                 (struct cmd_macsec_offload_off_result,
14137                  offload, "offload");
14138 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14139         TOKEN_NUM_INITIALIZER
14140                 (struct cmd_macsec_offload_off_result,
14141                  port_id, UINT16);
14142 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14143         TOKEN_STRING_INITIALIZER
14144                 (struct cmd_macsec_offload_off_result,
14145                  off, "off");
14146
14147 static void
14148 cmd_set_macsec_offload_off_parsed(
14149         void *parsed_result,
14150         __attribute__((unused)) struct cmdline *cl,
14151         __attribute__((unused)) void *data)
14152 {
14153         struct cmd_macsec_offload_off_result *res = parsed_result;
14154         int ret = -ENOTSUP;
14155         struct rte_eth_dev_info dev_info;
14156         portid_t port_id = res->port_id;
14157
14158         if (port_id_is_invalid(port_id, ENABLED_WARN))
14159                 return;
14160         if (!port_is_stopped(port_id)) {
14161                 printf("Please stop port %d first\n", port_id);
14162                 return;
14163         }
14164
14165         rte_eth_dev_info_get(port_id, &dev_info);
14166         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14167 #ifdef RTE_LIBRTE_IXGBE_PMD
14168                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14169 #endif
14170         }
14171         switch (ret) {
14172         case 0:
14173                 ports[port_id].dev_conf.txmode.offloads &=
14174                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14175                 cmd_reconfig_device_queue(port_id, 1, 1);
14176                 break;
14177         case -ENODEV:
14178                 printf("invalid port_id %d\n", port_id);
14179                 break;
14180         case -ENOTSUP:
14181                 printf("not supported on port %d\n", port_id);
14182                 break;
14183         default:
14184                 printf("programming error: (%s)\n", strerror(-ret));
14185         }
14186 }
14187
14188 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14189         .f = cmd_set_macsec_offload_off_parsed,
14190         .data = NULL,
14191         .help_str = "set macsec offload <port_id> off",
14192         .tokens = {
14193                 (void *)&cmd_macsec_offload_off_set,
14194                 (void *)&cmd_macsec_offload_off_macsec,
14195                 (void *)&cmd_macsec_offload_off_offload,
14196                 (void *)&cmd_macsec_offload_off_port_id,
14197                 (void *)&cmd_macsec_offload_off_off,
14198                 NULL,
14199         },
14200 };
14201
14202 /* Common result structure for MACsec secure connection configure */
14203 struct cmd_macsec_sc_result {
14204         cmdline_fixed_string_t set;
14205         cmdline_fixed_string_t macsec;
14206         cmdline_fixed_string_t sc;
14207         cmdline_fixed_string_t tx_rx;
14208         portid_t port_id;
14209         struct rte_ether_addr mac;
14210         uint16_t pi;
14211 };
14212
14213 /* Common CLI fields for MACsec secure connection configure */
14214 cmdline_parse_token_string_t cmd_macsec_sc_set =
14215         TOKEN_STRING_INITIALIZER
14216                 (struct cmd_macsec_sc_result,
14217                  set, "set");
14218 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14219         TOKEN_STRING_INITIALIZER
14220                 (struct cmd_macsec_sc_result,
14221                  macsec, "macsec");
14222 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14223         TOKEN_STRING_INITIALIZER
14224                 (struct cmd_macsec_sc_result,
14225                  sc, "sc");
14226 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14227         TOKEN_STRING_INITIALIZER
14228                 (struct cmd_macsec_sc_result,
14229                  tx_rx, "tx#rx");
14230 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14231         TOKEN_NUM_INITIALIZER
14232                 (struct cmd_macsec_sc_result,
14233                  port_id, UINT16);
14234 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14235         TOKEN_ETHERADDR_INITIALIZER
14236                 (struct cmd_macsec_sc_result,
14237                  mac);
14238 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14239         TOKEN_NUM_INITIALIZER
14240                 (struct cmd_macsec_sc_result,
14241                  pi, UINT16);
14242
14243 static void
14244 cmd_set_macsec_sc_parsed(
14245         void *parsed_result,
14246         __attribute__((unused)) struct cmdline *cl,
14247         __attribute__((unused)) void *data)
14248 {
14249         struct cmd_macsec_sc_result *res = parsed_result;
14250         int ret = -ENOTSUP;
14251         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14252
14253 #ifdef RTE_LIBRTE_IXGBE_PMD
14254         ret = is_tx ?
14255                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14256                                 res->mac.addr_bytes) :
14257                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14258                                 res->mac.addr_bytes, res->pi);
14259 #endif
14260         RTE_SET_USED(is_tx);
14261
14262         switch (ret) {
14263         case 0:
14264                 break;
14265         case -ENODEV:
14266                 printf("invalid port_id %d\n", res->port_id);
14267                 break;
14268         case -ENOTSUP:
14269                 printf("not supported on port %d\n", res->port_id);
14270                 break;
14271         default:
14272                 printf("programming error: (%s)\n", strerror(-ret));
14273         }
14274 }
14275
14276 cmdline_parse_inst_t cmd_set_macsec_sc = {
14277         .f = cmd_set_macsec_sc_parsed,
14278         .data = NULL,
14279         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14280         .tokens = {
14281                 (void *)&cmd_macsec_sc_set,
14282                 (void *)&cmd_macsec_sc_macsec,
14283                 (void *)&cmd_macsec_sc_sc,
14284                 (void *)&cmd_macsec_sc_tx_rx,
14285                 (void *)&cmd_macsec_sc_port_id,
14286                 (void *)&cmd_macsec_sc_mac,
14287                 (void *)&cmd_macsec_sc_pi,
14288                 NULL,
14289         },
14290 };
14291
14292 /* Common result structure for MACsec secure connection configure */
14293 struct cmd_macsec_sa_result {
14294         cmdline_fixed_string_t set;
14295         cmdline_fixed_string_t macsec;
14296         cmdline_fixed_string_t sa;
14297         cmdline_fixed_string_t tx_rx;
14298         portid_t port_id;
14299         uint8_t idx;
14300         uint8_t an;
14301         uint32_t pn;
14302         cmdline_fixed_string_t key;
14303 };
14304
14305 /* Common CLI fields for MACsec secure connection configure */
14306 cmdline_parse_token_string_t cmd_macsec_sa_set =
14307         TOKEN_STRING_INITIALIZER
14308                 (struct cmd_macsec_sa_result,
14309                  set, "set");
14310 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14311         TOKEN_STRING_INITIALIZER
14312                 (struct cmd_macsec_sa_result,
14313                  macsec, "macsec");
14314 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14315         TOKEN_STRING_INITIALIZER
14316                 (struct cmd_macsec_sa_result,
14317                  sa, "sa");
14318 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14319         TOKEN_STRING_INITIALIZER
14320                 (struct cmd_macsec_sa_result,
14321                  tx_rx, "tx#rx");
14322 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14323         TOKEN_NUM_INITIALIZER
14324                 (struct cmd_macsec_sa_result,
14325                  port_id, UINT16);
14326 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14327         TOKEN_NUM_INITIALIZER
14328                 (struct cmd_macsec_sa_result,
14329                  idx, UINT8);
14330 cmdline_parse_token_num_t cmd_macsec_sa_an =
14331         TOKEN_NUM_INITIALIZER
14332                 (struct cmd_macsec_sa_result,
14333                  an, UINT8);
14334 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14335         TOKEN_NUM_INITIALIZER
14336                 (struct cmd_macsec_sa_result,
14337                  pn, UINT32);
14338 cmdline_parse_token_string_t cmd_macsec_sa_key =
14339         TOKEN_STRING_INITIALIZER
14340                 (struct cmd_macsec_sa_result,
14341                  key, NULL);
14342
14343 static void
14344 cmd_set_macsec_sa_parsed(
14345         void *parsed_result,
14346         __attribute__((unused)) struct cmdline *cl,
14347         __attribute__((unused)) void *data)
14348 {
14349         struct cmd_macsec_sa_result *res = parsed_result;
14350         int ret = -ENOTSUP;
14351         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14352         uint8_t key[16] = { 0 };
14353         uint8_t xdgt0;
14354         uint8_t xdgt1;
14355         int key_len;
14356         int i;
14357
14358         key_len = strlen(res->key) / 2;
14359         if (key_len > 16)
14360                 key_len = 16;
14361
14362         for (i = 0; i < key_len; i++) {
14363                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14364                 if (xdgt0 == 0xFF)
14365                         return;
14366                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14367                 if (xdgt1 == 0xFF)
14368                         return;
14369                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14370         }
14371
14372 #ifdef RTE_LIBRTE_IXGBE_PMD
14373         ret = is_tx ?
14374                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14375                         res->idx, res->an, res->pn, key) :
14376                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14377                         res->idx, res->an, res->pn, key);
14378 #endif
14379         RTE_SET_USED(is_tx);
14380         RTE_SET_USED(key);
14381
14382         switch (ret) {
14383         case 0:
14384                 break;
14385         case -EINVAL:
14386                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14387                 break;
14388         case -ENODEV:
14389                 printf("invalid port_id %d\n", res->port_id);
14390                 break;
14391         case -ENOTSUP:
14392                 printf("not supported on port %d\n", res->port_id);
14393                 break;
14394         default:
14395                 printf("programming error: (%s)\n", strerror(-ret));
14396         }
14397 }
14398
14399 cmdline_parse_inst_t cmd_set_macsec_sa = {
14400         .f = cmd_set_macsec_sa_parsed,
14401         .data = NULL,
14402         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14403         .tokens = {
14404                 (void *)&cmd_macsec_sa_set,
14405                 (void *)&cmd_macsec_sa_macsec,
14406                 (void *)&cmd_macsec_sa_sa,
14407                 (void *)&cmd_macsec_sa_tx_rx,
14408                 (void *)&cmd_macsec_sa_port_id,
14409                 (void *)&cmd_macsec_sa_idx,
14410                 (void *)&cmd_macsec_sa_an,
14411                 (void *)&cmd_macsec_sa_pn,
14412                 (void *)&cmd_macsec_sa_key,
14413                 NULL,
14414         },
14415 };
14416
14417 /* VF unicast promiscuous mode configuration */
14418
14419 /* Common result structure for VF unicast promiscuous mode */
14420 struct cmd_vf_promisc_result {
14421         cmdline_fixed_string_t set;
14422         cmdline_fixed_string_t vf;
14423         cmdline_fixed_string_t promisc;
14424         portid_t port_id;
14425         uint32_t vf_id;
14426         cmdline_fixed_string_t on_off;
14427 };
14428
14429 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14430 cmdline_parse_token_string_t cmd_vf_promisc_set =
14431         TOKEN_STRING_INITIALIZER
14432                 (struct cmd_vf_promisc_result,
14433                  set, "set");
14434 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14435         TOKEN_STRING_INITIALIZER
14436                 (struct cmd_vf_promisc_result,
14437                  vf, "vf");
14438 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14439         TOKEN_STRING_INITIALIZER
14440                 (struct cmd_vf_promisc_result,
14441                  promisc, "promisc");
14442 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14443         TOKEN_NUM_INITIALIZER
14444                 (struct cmd_vf_promisc_result,
14445                  port_id, UINT16);
14446 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14447         TOKEN_NUM_INITIALIZER
14448                 (struct cmd_vf_promisc_result,
14449                  vf_id, UINT32);
14450 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_vf_promisc_result,
14453                  on_off, "on#off");
14454
14455 static void
14456 cmd_set_vf_promisc_parsed(
14457         void *parsed_result,
14458         __attribute__((unused)) struct cmdline *cl,
14459         __attribute__((unused)) void *data)
14460 {
14461         struct cmd_vf_promisc_result *res = parsed_result;
14462         int ret = -ENOTSUP;
14463
14464         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14465
14466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14467                 return;
14468
14469 #ifdef RTE_LIBRTE_I40E_PMD
14470         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14471                                                   res->vf_id, is_on);
14472 #endif
14473
14474         switch (ret) {
14475         case 0:
14476                 break;
14477         case -EINVAL:
14478                 printf("invalid vf_id %d\n", res->vf_id);
14479                 break;
14480         case -ENODEV:
14481                 printf("invalid port_id %d\n", res->port_id);
14482                 break;
14483         case -ENOTSUP:
14484                 printf("function not implemented\n");
14485                 break;
14486         default:
14487                 printf("programming error: (%s)\n", strerror(-ret));
14488         }
14489 }
14490
14491 cmdline_parse_inst_t cmd_set_vf_promisc = {
14492         .f = cmd_set_vf_promisc_parsed,
14493         .data = NULL,
14494         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14495                 "Set unicast promiscuous mode for a VF from the PF",
14496         .tokens = {
14497                 (void *)&cmd_vf_promisc_set,
14498                 (void *)&cmd_vf_promisc_vf,
14499                 (void *)&cmd_vf_promisc_promisc,
14500                 (void *)&cmd_vf_promisc_port_id,
14501                 (void *)&cmd_vf_promisc_vf_id,
14502                 (void *)&cmd_vf_promisc_on_off,
14503                 NULL,
14504         },
14505 };
14506
14507 /* VF multicast promiscuous mode configuration */
14508
14509 /* Common result structure for VF multicast promiscuous mode */
14510 struct cmd_vf_allmulti_result {
14511         cmdline_fixed_string_t set;
14512         cmdline_fixed_string_t vf;
14513         cmdline_fixed_string_t allmulti;
14514         portid_t port_id;
14515         uint32_t vf_id;
14516         cmdline_fixed_string_t on_off;
14517 };
14518
14519 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14520 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14521         TOKEN_STRING_INITIALIZER
14522                 (struct cmd_vf_allmulti_result,
14523                  set, "set");
14524 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14525         TOKEN_STRING_INITIALIZER
14526                 (struct cmd_vf_allmulti_result,
14527                  vf, "vf");
14528 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14529         TOKEN_STRING_INITIALIZER
14530                 (struct cmd_vf_allmulti_result,
14531                  allmulti, "allmulti");
14532 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14533         TOKEN_NUM_INITIALIZER
14534                 (struct cmd_vf_allmulti_result,
14535                  port_id, UINT16);
14536 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14537         TOKEN_NUM_INITIALIZER
14538                 (struct cmd_vf_allmulti_result,
14539                  vf_id, UINT32);
14540 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14541         TOKEN_STRING_INITIALIZER
14542                 (struct cmd_vf_allmulti_result,
14543                  on_off, "on#off");
14544
14545 static void
14546 cmd_set_vf_allmulti_parsed(
14547         void *parsed_result,
14548         __attribute__((unused)) struct cmdline *cl,
14549         __attribute__((unused)) void *data)
14550 {
14551         struct cmd_vf_allmulti_result *res = parsed_result;
14552         int ret = -ENOTSUP;
14553
14554         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14555
14556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14557                 return;
14558
14559 #ifdef RTE_LIBRTE_I40E_PMD
14560         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14561                                                     res->vf_id, is_on);
14562 #endif
14563
14564         switch (ret) {
14565         case 0:
14566                 break;
14567         case -EINVAL:
14568                 printf("invalid vf_id %d\n", res->vf_id);
14569                 break;
14570         case -ENODEV:
14571                 printf("invalid port_id %d\n", res->port_id);
14572                 break;
14573         case -ENOTSUP:
14574                 printf("function not implemented\n");
14575                 break;
14576         default:
14577                 printf("programming error: (%s)\n", strerror(-ret));
14578         }
14579 }
14580
14581 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14582         .f = cmd_set_vf_allmulti_parsed,
14583         .data = NULL,
14584         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14585                 "Set multicast promiscuous mode for a VF from the PF",
14586         .tokens = {
14587                 (void *)&cmd_vf_allmulti_set,
14588                 (void *)&cmd_vf_allmulti_vf,
14589                 (void *)&cmd_vf_allmulti_allmulti,
14590                 (void *)&cmd_vf_allmulti_port_id,
14591                 (void *)&cmd_vf_allmulti_vf_id,
14592                 (void *)&cmd_vf_allmulti_on_off,
14593                 NULL,
14594         },
14595 };
14596
14597 /* vf broadcast mode configuration */
14598
14599 /* Common result structure for vf broadcast */
14600 struct cmd_set_vf_broadcast_result {
14601         cmdline_fixed_string_t set;
14602         cmdline_fixed_string_t vf;
14603         cmdline_fixed_string_t broadcast;
14604         portid_t port_id;
14605         uint16_t vf_id;
14606         cmdline_fixed_string_t on_off;
14607 };
14608
14609 /* Common CLI fields for vf broadcast enable disable */
14610 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14611         TOKEN_STRING_INITIALIZER
14612                 (struct cmd_set_vf_broadcast_result,
14613                  set, "set");
14614 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14615         TOKEN_STRING_INITIALIZER
14616                 (struct cmd_set_vf_broadcast_result,
14617                  vf, "vf");
14618 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14619         TOKEN_STRING_INITIALIZER
14620                 (struct cmd_set_vf_broadcast_result,
14621                  broadcast, "broadcast");
14622 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14623         TOKEN_NUM_INITIALIZER
14624                 (struct cmd_set_vf_broadcast_result,
14625                  port_id, UINT16);
14626 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14627         TOKEN_NUM_INITIALIZER
14628                 (struct cmd_set_vf_broadcast_result,
14629                  vf_id, UINT16);
14630 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14631         TOKEN_STRING_INITIALIZER
14632                 (struct cmd_set_vf_broadcast_result,
14633                  on_off, "on#off");
14634
14635 static void
14636 cmd_set_vf_broadcast_parsed(
14637         void *parsed_result,
14638         __attribute__((unused)) struct cmdline *cl,
14639         __attribute__((unused)) void *data)
14640 {
14641         struct cmd_set_vf_broadcast_result *res = parsed_result;
14642         int ret = -ENOTSUP;
14643
14644         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14645
14646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14647                 return;
14648
14649 #ifdef RTE_LIBRTE_I40E_PMD
14650         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14651                                             res->vf_id, is_on);
14652 #endif
14653
14654         switch (ret) {
14655         case 0:
14656                 break;
14657         case -EINVAL:
14658                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14659                 break;
14660         case -ENODEV:
14661                 printf("invalid port_id %d\n", res->port_id);
14662                 break;
14663         case -ENOTSUP:
14664                 printf("function not implemented\n");
14665                 break;
14666         default:
14667                 printf("programming error: (%s)\n", strerror(-ret));
14668         }
14669 }
14670
14671 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14672         .f = cmd_set_vf_broadcast_parsed,
14673         .data = NULL,
14674         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14675         .tokens = {
14676                 (void *)&cmd_set_vf_broadcast_set,
14677                 (void *)&cmd_set_vf_broadcast_vf,
14678                 (void *)&cmd_set_vf_broadcast_broadcast,
14679                 (void *)&cmd_set_vf_broadcast_port_id,
14680                 (void *)&cmd_set_vf_broadcast_vf_id,
14681                 (void *)&cmd_set_vf_broadcast_on_off,
14682                 NULL,
14683         },
14684 };
14685
14686 /* vf vlan tag configuration */
14687
14688 /* Common result structure for vf vlan tag */
14689 struct cmd_set_vf_vlan_tag_result {
14690         cmdline_fixed_string_t set;
14691         cmdline_fixed_string_t vf;
14692         cmdline_fixed_string_t vlan;
14693         cmdline_fixed_string_t tag;
14694         portid_t port_id;
14695         uint16_t vf_id;
14696         cmdline_fixed_string_t on_off;
14697 };
14698
14699 /* Common CLI fields for vf vlan tag enable disable */
14700 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14701         TOKEN_STRING_INITIALIZER
14702                 (struct cmd_set_vf_vlan_tag_result,
14703                  set, "set");
14704 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14705         TOKEN_STRING_INITIALIZER
14706                 (struct cmd_set_vf_vlan_tag_result,
14707                  vf, "vf");
14708 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14709         TOKEN_STRING_INITIALIZER
14710                 (struct cmd_set_vf_vlan_tag_result,
14711                  vlan, "vlan");
14712 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14713         TOKEN_STRING_INITIALIZER
14714                 (struct cmd_set_vf_vlan_tag_result,
14715                  tag, "tag");
14716 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14717         TOKEN_NUM_INITIALIZER
14718                 (struct cmd_set_vf_vlan_tag_result,
14719                  port_id, UINT16);
14720 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14721         TOKEN_NUM_INITIALIZER
14722                 (struct cmd_set_vf_vlan_tag_result,
14723                  vf_id, UINT16);
14724 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14725         TOKEN_STRING_INITIALIZER
14726                 (struct cmd_set_vf_vlan_tag_result,
14727                  on_off, "on#off");
14728
14729 static void
14730 cmd_set_vf_vlan_tag_parsed(
14731         void *parsed_result,
14732         __attribute__((unused)) struct cmdline *cl,
14733         __attribute__((unused)) void *data)
14734 {
14735         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14736         int ret = -ENOTSUP;
14737
14738         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14739
14740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14741                 return;
14742
14743 #ifdef RTE_LIBRTE_I40E_PMD
14744         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14745                                            res->vf_id, is_on);
14746 #endif
14747
14748         switch (ret) {
14749         case 0:
14750                 break;
14751         case -EINVAL:
14752                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14753                 break;
14754         case -ENODEV:
14755                 printf("invalid port_id %d\n", res->port_id);
14756                 break;
14757         case -ENOTSUP:
14758                 printf("function not implemented\n");
14759                 break;
14760         default:
14761                 printf("programming error: (%s)\n", strerror(-ret));
14762         }
14763 }
14764
14765 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14766         .f = cmd_set_vf_vlan_tag_parsed,
14767         .data = NULL,
14768         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14769         .tokens = {
14770                 (void *)&cmd_set_vf_vlan_tag_set,
14771                 (void *)&cmd_set_vf_vlan_tag_vf,
14772                 (void *)&cmd_set_vf_vlan_tag_vlan,
14773                 (void *)&cmd_set_vf_vlan_tag_tag,
14774                 (void *)&cmd_set_vf_vlan_tag_port_id,
14775                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14776                 (void *)&cmd_set_vf_vlan_tag_on_off,
14777                 NULL,
14778         },
14779 };
14780
14781 /* Common definition of VF and TC TX bandwidth configuration */
14782 struct cmd_vf_tc_bw_result {
14783         cmdline_fixed_string_t set;
14784         cmdline_fixed_string_t vf;
14785         cmdline_fixed_string_t tc;
14786         cmdline_fixed_string_t tx;
14787         cmdline_fixed_string_t min_bw;
14788         cmdline_fixed_string_t max_bw;
14789         cmdline_fixed_string_t strict_link_prio;
14790         portid_t port_id;
14791         uint16_t vf_id;
14792         uint8_t tc_no;
14793         uint32_t bw;
14794         cmdline_fixed_string_t bw_list;
14795         uint8_t tc_map;
14796 };
14797
14798 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14799         TOKEN_STRING_INITIALIZER
14800                 (struct cmd_vf_tc_bw_result,
14801                  set, "set");
14802 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14803         TOKEN_STRING_INITIALIZER
14804                 (struct cmd_vf_tc_bw_result,
14805                  vf, "vf");
14806 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14807         TOKEN_STRING_INITIALIZER
14808                 (struct cmd_vf_tc_bw_result,
14809                  tc, "tc");
14810 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14811         TOKEN_STRING_INITIALIZER
14812                 (struct cmd_vf_tc_bw_result,
14813                  tx, "tx");
14814 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14815         TOKEN_STRING_INITIALIZER
14816                 (struct cmd_vf_tc_bw_result,
14817                  strict_link_prio, "strict-link-priority");
14818 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14819         TOKEN_STRING_INITIALIZER
14820                 (struct cmd_vf_tc_bw_result,
14821                  min_bw, "min-bandwidth");
14822 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14823         TOKEN_STRING_INITIALIZER
14824                 (struct cmd_vf_tc_bw_result,
14825                  max_bw, "max-bandwidth");
14826 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14827         TOKEN_NUM_INITIALIZER
14828                 (struct cmd_vf_tc_bw_result,
14829                  port_id, UINT16);
14830 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14831         TOKEN_NUM_INITIALIZER
14832                 (struct cmd_vf_tc_bw_result,
14833                  vf_id, UINT16);
14834 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14835         TOKEN_NUM_INITIALIZER
14836                 (struct cmd_vf_tc_bw_result,
14837                  tc_no, UINT8);
14838 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14839         TOKEN_NUM_INITIALIZER
14840                 (struct cmd_vf_tc_bw_result,
14841                  bw, UINT32);
14842 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14843         TOKEN_STRING_INITIALIZER
14844                 (struct cmd_vf_tc_bw_result,
14845                  bw_list, NULL);
14846 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14847         TOKEN_NUM_INITIALIZER
14848                 (struct cmd_vf_tc_bw_result,
14849                  tc_map, UINT8);
14850
14851 /* VF max bandwidth setting */
14852 static void
14853 cmd_vf_max_bw_parsed(
14854         void *parsed_result,
14855         __attribute__((unused)) struct cmdline *cl,
14856         __attribute__((unused)) void *data)
14857 {
14858         struct cmd_vf_tc_bw_result *res = parsed_result;
14859         int ret = -ENOTSUP;
14860
14861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14862                 return;
14863
14864 #ifdef RTE_LIBRTE_I40E_PMD
14865         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14866                                          res->vf_id, res->bw);
14867 #endif
14868
14869         switch (ret) {
14870         case 0:
14871                 break;
14872         case -EINVAL:
14873                 printf("invalid vf_id %d or bandwidth %d\n",
14874                        res->vf_id, res->bw);
14875                 break;
14876         case -ENODEV:
14877                 printf("invalid port_id %d\n", res->port_id);
14878                 break;
14879         case -ENOTSUP:
14880                 printf("function not implemented\n");
14881                 break;
14882         default:
14883                 printf("programming error: (%s)\n", strerror(-ret));
14884         }
14885 }
14886
14887 cmdline_parse_inst_t cmd_vf_max_bw = {
14888         .f = cmd_vf_max_bw_parsed,
14889         .data = NULL,
14890         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14891         .tokens = {
14892                 (void *)&cmd_vf_tc_bw_set,
14893                 (void *)&cmd_vf_tc_bw_vf,
14894                 (void *)&cmd_vf_tc_bw_tx,
14895                 (void *)&cmd_vf_tc_bw_max_bw,
14896                 (void *)&cmd_vf_tc_bw_port_id,
14897                 (void *)&cmd_vf_tc_bw_vf_id,
14898                 (void *)&cmd_vf_tc_bw_bw,
14899                 NULL,
14900         },
14901 };
14902
14903 static int
14904 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14905                            uint8_t *tc_num,
14906                            char *str)
14907 {
14908         uint32_t size;
14909         const char *p, *p0 = str;
14910         char s[256];
14911         char *end;
14912         char *str_fld[16];
14913         uint16_t i;
14914         int ret;
14915
14916         p = strchr(p0, '(');
14917         if (p == NULL) {
14918                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14919                 return -1;
14920         }
14921         p++;
14922         p0 = strchr(p, ')');
14923         if (p0 == NULL) {
14924                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14925                 return -1;
14926         }
14927         size = p0 - p;
14928         if (size >= sizeof(s)) {
14929                 printf("The string size exceeds the internal buffer size\n");
14930                 return -1;
14931         }
14932         snprintf(s, sizeof(s), "%.*s", size, p);
14933         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14934         if (ret <= 0) {
14935                 printf("Failed to get the bandwidth list. ");
14936                 return -1;
14937         }
14938         *tc_num = ret;
14939         for (i = 0; i < ret; i++)
14940                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14941
14942         return 0;
14943 }
14944
14945 /* TC min bandwidth setting */
14946 static void
14947 cmd_vf_tc_min_bw_parsed(
14948         void *parsed_result,
14949         __attribute__((unused)) struct cmdline *cl,
14950         __attribute__((unused)) void *data)
14951 {
14952         struct cmd_vf_tc_bw_result *res = parsed_result;
14953         uint8_t tc_num;
14954         uint8_t bw[16];
14955         int ret = -ENOTSUP;
14956
14957         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14958                 return;
14959
14960         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14961         if (ret)
14962                 return;
14963
14964 #ifdef RTE_LIBRTE_I40E_PMD
14965         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14966                                               tc_num, bw);
14967 #endif
14968
14969         switch (ret) {
14970         case 0:
14971                 break;
14972         case -EINVAL:
14973                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14974                 break;
14975         case -ENODEV:
14976                 printf("invalid port_id %d\n", res->port_id);
14977                 break;
14978         case -ENOTSUP:
14979                 printf("function not implemented\n");
14980                 break;
14981         default:
14982                 printf("programming error: (%s)\n", strerror(-ret));
14983         }
14984 }
14985
14986 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14987         .f = cmd_vf_tc_min_bw_parsed,
14988         .data = NULL,
14989         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14990                     " <bw1, bw2, ...>",
14991         .tokens = {
14992                 (void *)&cmd_vf_tc_bw_set,
14993                 (void *)&cmd_vf_tc_bw_vf,
14994                 (void *)&cmd_vf_tc_bw_tc,
14995                 (void *)&cmd_vf_tc_bw_tx,
14996                 (void *)&cmd_vf_tc_bw_min_bw,
14997                 (void *)&cmd_vf_tc_bw_port_id,
14998                 (void *)&cmd_vf_tc_bw_vf_id,
14999                 (void *)&cmd_vf_tc_bw_bw_list,
15000                 NULL,
15001         },
15002 };
15003
15004 static void
15005 cmd_tc_min_bw_parsed(
15006         void *parsed_result,
15007         __attribute__((unused)) struct cmdline *cl,
15008         __attribute__((unused)) void *data)
15009 {
15010         struct cmd_vf_tc_bw_result *res = parsed_result;
15011         struct rte_port *port;
15012         uint8_t tc_num;
15013         uint8_t bw[16];
15014         int ret = -ENOTSUP;
15015
15016         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15017                 return;
15018
15019         port = &ports[res->port_id];
15020         /** Check if the port is not started **/
15021         if (port->port_status != RTE_PORT_STOPPED) {
15022                 printf("Please stop port %d first\n", res->port_id);
15023                 return;
15024         }
15025
15026         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15027         if (ret)
15028                 return;
15029
15030 #ifdef RTE_LIBRTE_IXGBE_PMD
15031         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15032 #endif
15033
15034         switch (ret) {
15035         case 0:
15036                 break;
15037         case -EINVAL:
15038                 printf("invalid bandwidth\n");
15039                 break;
15040         case -ENODEV:
15041                 printf("invalid port_id %d\n", res->port_id);
15042                 break;
15043         case -ENOTSUP:
15044                 printf("function not implemented\n");
15045                 break;
15046         default:
15047                 printf("programming error: (%s)\n", strerror(-ret));
15048         }
15049 }
15050
15051 cmdline_parse_inst_t cmd_tc_min_bw = {
15052         .f = cmd_tc_min_bw_parsed,
15053         .data = NULL,
15054         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15055         .tokens = {
15056                 (void *)&cmd_vf_tc_bw_set,
15057                 (void *)&cmd_vf_tc_bw_tc,
15058                 (void *)&cmd_vf_tc_bw_tx,
15059                 (void *)&cmd_vf_tc_bw_min_bw,
15060                 (void *)&cmd_vf_tc_bw_port_id,
15061                 (void *)&cmd_vf_tc_bw_bw_list,
15062                 NULL,
15063         },
15064 };
15065
15066 /* TC max bandwidth setting */
15067 static void
15068 cmd_vf_tc_max_bw_parsed(
15069         void *parsed_result,
15070         __attribute__((unused)) struct cmdline *cl,
15071         __attribute__((unused)) void *data)
15072 {
15073         struct cmd_vf_tc_bw_result *res = parsed_result;
15074         int ret = -ENOTSUP;
15075
15076         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15077                 return;
15078
15079 #ifdef RTE_LIBRTE_I40E_PMD
15080         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15081                                             res->tc_no, res->bw);
15082 #endif
15083
15084         switch (ret) {
15085         case 0:
15086                 break;
15087         case -EINVAL:
15088                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15089                        res->vf_id, res->tc_no, res->bw);
15090                 break;
15091         case -ENODEV:
15092                 printf("invalid port_id %d\n", res->port_id);
15093                 break;
15094         case -ENOTSUP:
15095                 printf("function not implemented\n");
15096                 break;
15097         default:
15098                 printf("programming error: (%s)\n", strerror(-ret));
15099         }
15100 }
15101
15102 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15103         .f = cmd_vf_tc_max_bw_parsed,
15104         .data = NULL,
15105         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15106                     " <bandwidth>",
15107         .tokens = {
15108                 (void *)&cmd_vf_tc_bw_set,
15109                 (void *)&cmd_vf_tc_bw_vf,
15110                 (void *)&cmd_vf_tc_bw_tc,
15111                 (void *)&cmd_vf_tc_bw_tx,
15112                 (void *)&cmd_vf_tc_bw_max_bw,
15113                 (void *)&cmd_vf_tc_bw_port_id,
15114                 (void *)&cmd_vf_tc_bw_vf_id,
15115                 (void *)&cmd_vf_tc_bw_tc_no,
15116                 (void *)&cmd_vf_tc_bw_bw,
15117                 NULL,
15118         },
15119 };
15120
15121
15122 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15123
15124 /* *** Set Port default Traffic Management Hierarchy *** */
15125 struct cmd_set_port_tm_hierarchy_default_result {
15126         cmdline_fixed_string_t set;
15127         cmdline_fixed_string_t port;
15128         cmdline_fixed_string_t tm;
15129         cmdline_fixed_string_t hierarchy;
15130         cmdline_fixed_string_t def;
15131         portid_t port_id;
15132 };
15133
15134 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15135         TOKEN_STRING_INITIALIZER(
15136                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15137 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15138         TOKEN_STRING_INITIALIZER(
15139                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15140 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15141         TOKEN_STRING_INITIALIZER(
15142                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15143 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15144         TOKEN_STRING_INITIALIZER(
15145                 struct cmd_set_port_tm_hierarchy_default_result,
15146                         hierarchy, "hierarchy");
15147 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15148         TOKEN_STRING_INITIALIZER(
15149                 struct cmd_set_port_tm_hierarchy_default_result,
15150                         def, "default");
15151 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15152         TOKEN_NUM_INITIALIZER(
15153                 struct cmd_set_port_tm_hierarchy_default_result,
15154                         port_id, UINT16);
15155
15156 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15157         __attribute__((unused)) struct cmdline *cl,
15158         __attribute__((unused)) void *data)
15159 {
15160         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15161         struct rte_port *p;
15162         portid_t port_id = res->port_id;
15163
15164         if (port_id_is_invalid(port_id, ENABLED_WARN))
15165                 return;
15166
15167         p = &ports[port_id];
15168
15169         /* Forward mode: tm */
15170         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15171                 printf("  softnicfwd mode not enabled(error)\n");
15172                 return;
15173         }
15174
15175         /* Set the default tm hierarchy */
15176         p->softport.default_tm_hierarchy_enable = 1;
15177 }
15178
15179 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15180         .f = cmd_set_port_tm_hierarchy_default_parsed,
15181         .data = NULL,
15182         .help_str = "set port tm hierarchy default <port_id>",
15183         .tokens = {
15184                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15185                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15186                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15187                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15188                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15189                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15190                 NULL,
15191         },
15192 };
15193 #endif
15194
15195 /** Set VXLAN encapsulation details */
15196 struct cmd_set_vxlan_result {
15197         cmdline_fixed_string_t set;
15198         cmdline_fixed_string_t vxlan;
15199         cmdline_fixed_string_t pos_token;
15200         cmdline_fixed_string_t ip_version;
15201         uint32_t vlan_present:1;
15202         uint32_t vni;
15203         uint16_t udp_src;
15204         uint16_t udp_dst;
15205         cmdline_ipaddr_t ip_src;
15206         cmdline_ipaddr_t ip_dst;
15207         uint16_t tci;
15208         uint8_t tos;
15209         uint8_t ttl;
15210         struct rte_ether_addr eth_src;
15211         struct rte_ether_addr eth_dst;
15212 };
15213
15214 cmdline_parse_token_string_t cmd_set_vxlan_set =
15215         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15216 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15217         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15218 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15219         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15220                                  "vxlan-tos-ttl");
15221 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15222         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15223                                  "vxlan-with-vlan");
15224 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15225         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15226                                  "ip-version");
15227 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15228         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15229                                  "ipv4#ipv6");
15230 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15231         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15232                                  "vni");
15233 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15234         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15235 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15236         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15237                                  "udp-src");
15238 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15239         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15240 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15241         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15242                                  "udp-dst");
15243 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15244         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15245 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15246         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15247                                  "ip-tos");
15248 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15249         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15250 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15251         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15252                                  "ip-ttl");
15253 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15254         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15255 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15256         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15257                                  "ip-src");
15258 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15259         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15260 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15261         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15262                                  "ip-dst");
15263 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15264         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15265 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15266         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15267                                  "vlan-tci");
15268 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15269         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15270 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15271         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15272                                  "eth-src");
15273 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15274         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15275 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15276         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15277                                  "eth-dst");
15278 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15279         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15280
15281 static void cmd_set_vxlan_parsed(void *parsed_result,
15282         __attribute__((unused)) struct cmdline *cl,
15283         __attribute__((unused)) void *data)
15284 {
15285         struct cmd_set_vxlan_result *res = parsed_result;
15286         union {
15287                 uint32_t vxlan_id;
15288                 uint8_t vni[4];
15289         } id = {
15290                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15291         };
15292
15293         vxlan_encap_conf.select_tos_ttl = 0;
15294         if (strcmp(res->vxlan, "vxlan") == 0)
15295                 vxlan_encap_conf.select_vlan = 0;
15296         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15297                 vxlan_encap_conf.select_vlan = 1;
15298         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15299                 vxlan_encap_conf.select_vlan = 0;
15300                 vxlan_encap_conf.select_tos_ttl = 1;
15301         }
15302         if (strcmp(res->ip_version, "ipv4") == 0)
15303                 vxlan_encap_conf.select_ipv4 = 1;
15304         else if (strcmp(res->ip_version, "ipv6") == 0)
15305                 vxlan_encap_conf.select_ipv4 = 0;
15306         else
15307                 return;
15308         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15309         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15310         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15311         vxlan_encap_conf.ip_tos = res->tos;
15312         vxlan_encap_conf.ip_ttl = res->ttl;
15313         if (vxlan_encap_conf.select_ipv4) {
15314                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15315                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15316         } else {
15317                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15318                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15319         }
15320         if (vxlan_encap_conf.select_vlan)
15321                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15322         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15323                    RTE_ETHER_ADDR_LEN);
15324         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15325                    RTE_ETHER_ADDR_LEN);
15326 }
15327
15328 cmdline_parse_inst_t cmd_set_vxlan = {
15329         .f = cmd_set_vxlan_parsed,
15330         .data = NULL,
15331         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15332                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15333                 " eth-src <eth-src> eth-dst <eth-dst>",
15334         .tokens = {
15335                 (void *)&cmd_set_vxlan_set,
15336                 (void *)&cmd_set_vxlan_vxlan,
15337                 (void *)&cmd_set_vxlan_ip_version,
15338                 (void *)&cmd_set_vxlan_ip_version_value,
15339                 (void *)&cmd_set_vxlan_vni,
15340                 (void *)&cmd_set_vxlan_vni_value,
15341                 (void *)&cmd_set_vxlan_udp_src,
15342                 (void *)&cmd_set_vxlan_udp_src_value,
15343                 (void *)&cmd_set_vxlan_udp_dst,
15344                 (void *)&cmd_set_vxlan_udp_dst_value,
15345                 (void *)&cmd_set_vxlan_ip_src,
15346                 (void *)&cmd_set_vxlan_ip_src_value,
15347                 (void *)&cmd_set_vxlan_ip_dst,
15348                 (void *)&cmd_set_vxlan_ip_dst_value,
15349                 (void *)&cmd_set_vxlan_eth_src,
15350                 (void *)&cmd_set_vxlan_eth_src_value,
15351                 (void *)&cmd_set_vxlan_eth_dst,
15352                 (void *)&cmd_set_vxlan_eth_dst_value,
15353                 NULL,
15354         },
15355 };
15356
15357 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15358         .f = cmd_set_vxlan_parsed,
15359         .data = NULL,
15360         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15361                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15362                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15363                 " eth-dst <eth-dst>",
15364         .tokens = {
15365                 (void *)&cmd_set_vxlan_set,
15366                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15367                 (void *)&cmd_set_vxlan_ip_version,
15368                 (void *)&cmd_set_vxlan_ip_version_value,
15369                 (void *)&cmd_set_vxlan_vni,
15370                 (void *)&cmd_set_vxlan_vni_value,
15371                 (void *)&cmd_set_vxlan_udp_src,
15372                 (void *)&cmd_set_vxlan_udp_src_value,
15373                 (void *)&cmd_set_vxlan_udp_dst,
15374                 (void *)&cmd_set_vxlan_udp_dst_value,
15375                 (void *)&cmd_set_vxlan_ip_tos,
15376                 (void *)&cmd_set_vxlan_ip_tos_value,
15377                 (void *)&cmd_set_vxlan_ip_ttl,
15378                 (void *)&cmd_set_vxlan_ip_ttl_value,
15379                 (void *)&cmd_set_vxlan_ip_src,
15380                 (void *)&cmd_set_vxlan_ip_src_value,
15381                 (void *)&cmd_set_vxlan_ip_dst,
15382                 (void *)&cmd_set_vxlan_ip_dst_value,
15383                 (void *)&cmd_set_vxlan_eth_src,
15384                 (void *)&cmd_set_vxlan_eth_src_value,
15385                 (void *)&cmd_set_vxlan_eth_dst,
15386                 (void *)&cmd_set_vxlan_eth_dst_value,
15387                 NULL,
15388         },
15389 };
15390
15391 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15392         .f = cmd_set_vxlan_parsed,
15393         .data = NULL,
15394         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15395                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15396                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15397                 " <eth-dst>",
15398         .tokens = {
15399                 (void *)&cmd_set_vxlan_set,
15400                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15401                 (void *)&cmd_set_vxlan_ip_version,
15402                 (void *)&cmd_set_vxlan_ip_version_value,
15403                 (void *)&cmd_set_vxlan_vni,
15404                 (void *)&cmd_set_vxlan_vni_value,
15405                 (void *)&cmd_set_vxlan_udp_src,
15406                 (void *)&cmd_set_vxlan_udp_src_value,
15407                 (void *)&cmd_set_vxlan_udp_dst,
15408                 (void *)&cmd_set_vxlan_udp_dst_value,
15409                 (void *)&cmd_set_vxlan_ip_src,
15410                 (void *)&cmd_set_vxlan_ip_src_value,
15411                 (void *)&cmd_set_vxlan_ip_dst,
15412                 (void *)&cmd_set_vxlan_ip_dst_value,
15413                 (void *)&cmd_set_vxlan_vlan,
15414                 (void *)&cmd_set_vxlan_vlan_value,
15415                 (void *)&cmd_set_vxlan_eth_src,
15416                 (void *)&cmd_set_vxlan_eth_src_value,
15417                 (void *)&cmd_set_vxlan_eth_dst,
15418                 (void *)&cmd_set_vxlan_eth_dst_value,
15419                 NULL,
15420         },
15421 };
15422
15423 /** Set NVGRE encapsulation details */
15424 struct cmd_set_nvgre_result {
15425         cmdline_fixed_string_t set;
15426         cmdline_fixed_string_t nvgre;
15427         cmdline_fixed_string_t pos_token;
15428         cmdline_fixed_string_t ip_version;
15429         uint32_t tni;
15430         cmdline_ipaddr_t ip_src;
15431         cmdline_ipaddr_t ip_dst;
15432         uint16_t tci;
15433         struct rte_ether_addr eth_src;
15434         struct rte_ether_addr eth_dst;
15435 };
15436
15437 cmdline_parse_token_string_t cmd_set_nvgre_set =
15438         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15439 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15440         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15441 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15442         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15443                                  "nvgre-with-vlan");
15444 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15445         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15446                                  "ip-version");
15447 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15448         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15449                                  "ipv4#ipv6");
15450 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15451         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15452                                  "tni");
15453 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15454         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15455 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15457                                  "ip-src");
15458 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15459         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15460 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15462                                  "ip-dst");
15463 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15464         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15465 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15466         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15467                                  "vlan-tci");
15468 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15469         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15470 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15471         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15472                                  "eth-src");
15473 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15474         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15475 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15476         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15477                                  "eth-dst");
15478 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15479         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15480
15481 static void cmd_set_nvgre_parsed(void *parsed_result,
15482         __attribute__((unused)) struct cmdline *cl,
15483         __attribute__((unused)) void *data)
15484 {
15485         struct cmd_set_nvgre_result *res = parsed_result;
15486         union {
15487                 uint32_t nvgre_tni;
15488                 uint8_t tni[4];
15489         } id = {
15490                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15491         };
15492
15493         if (strcmp(res->nvgre, "nvgre") == 0)
15494                 nvgre_encap_conf.select_vlan = 0;
15495         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15496                 nvgre_encap_conf.select_vlan = 1;
15497         if (strcmp(res->ip_version, "ipv4") == 0)
15498                 nvgre_encap_conf.select_ipv4 = 1;
15499         else if (strcmp(res->ip_version, "ipv6") == 0)
15500                 nvgre_encap_conf.select_ipv4 = 0;
15501         else
15502                 return;
15503         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15504         if (nvgre_encap_conf.select_ipv4) {
15505                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15506                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15507         } else {
15508                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15509                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15510         }
15511         if (nvgre_encap_conf.select_vlan)
15512                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15513         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15514                    RTE_ETHER_ADDR_LEN);
15515         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15516                    RTE_ETHER_ADDR_LEN);
15517 }
15518
15519 cmdline_parse_inst_t cmd_set_nvgre = {
15520         .f = cmd_set_nvgre_parsed,
15521         .data = NULL,
15522         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15523                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15524                 " eth-dst <eth-dst>",
15525         .tokens = {
15526                 (void *)&cmd_set_nvgre_set,
15527                 (void *)&cmd_set_nvgre_nvgre,
15528                 (void *)&cmd_set_nvgre_ip_version,
15529                 (void *)&cmd_set_nvgre_ip_version_value,
15530                 (void *)&cmd_set_nvgre_tni,
15531                 (void *)&cmd_set_nvgre_tni_value,
15532                 (void *)&cmd_set_nvgre_ip_src,
15533                 (void *)&cmd_set_nvgre_ip_src_value,
15534                 (void *)&cmd_set_nvgre_ip_dst,
15535                 (void *)&cmd_set_nvgre_ip_dst_value,
15536                 (void *)&cmd_set_nvgre_eth_src,
15537                 (void *)&cmd_set_nvgre_eth_src_value,
15538                 (void *)&cmd_set_nvgre_eth_dst,
15539                 (void *)&cmd_set_nvgre_eth_dst_value,
15540                 NULL,
15541         },
15542 };
15543
15544 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15545         .f = cmd_set_nvgre_parsed,
15546         .data = NULL,
15547         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15548                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15549                 " eth-src <eth-src> eth-dst <eth-dst>",
15550         .tokens = {
15551                 (void *)&cmd_set_nvgre_set,
15552                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15553                 (void *)&cmd_set_nvgre_ip_version,
15554                 (void *)&cmd_set_nvgre_ip_version_value,
15555                 (void *)&cmd_set_nvgre_tni,
15556                 (void *)&cmd_set_nvgre_tni_value,
15557                 (void *)&cmd_set_nvgre_ip_src,
15558                 (void *)&cmd_set_nvgre_ip_src_value,
15559                 (void *)&cmd_set_nvgre_ip_dst,
15560                 (void *)&cmd_set_nvgre_ip_dst_value,
15561                 (void *)&cmd_set_nvgre_vlan,
15562                 (void *)&cmd_set_nvgre_vlan_value,
15563                 (void *)&cmd_set_nvgre_eth_src,
15564                 (void *)&cmd_set_nvgre_eth_src_value,
15565                 (void *)&cmd_set_nvgre_eth_dst,
15566                 (void *)&cmd_set_nvgre_eth_dst_value,
15567                 NULL,
15568         },
15569 };
15570
15571 /** Set L2 encapsulation details */
15572 struct cmd_set_l2_encap_result {
15573         cmdline_fixed_string_t set;
15574         cmdline_fixed_string_t l2_encap;
15575         cmdline_fixed_string_t pos_token;
15576         cmdline_fixed_string_t ip_version;
15577         uint32_t vlan_present:1;
15578         uint16_t tci;
15579         struct rte_ether_addr eth_src;
15580         struct rte_ether_addr eth_dst;
15581 };
15582
15583 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15584         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15585 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15586         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15587 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15588         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15589                                  "l2_encap-with-vlan");
15590 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15591         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15592                                  "ip-version");
15593 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15594         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15595                                  "ipv4#ipv6");
15596 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15597         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15598                                  "vlan-tci");
15599 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15600         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15601 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15602         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15603                                  "eth-src");
15604 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15605         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15606 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15607         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15608                                  "eth-dst");
15609 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15610         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15611
15612 static void cmd_set_l2_encap_parsed(void *parsed_result,
15613         __attribute__((unused)) struct cmdline *cl,
15614         __attribute__((unused)) void *data)
15615 {
15616         struct cmd_set_l2_encap_result *res = parsed_result;
15617
15618         if (strcmp(res->l2_encap, "l2_encap") == 0)
15619                 l2_encap_conf.select_vlan = 0;
15620         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15621                 l2_encap_conf.select_vlan = 1;
15622         if (strcmp(res->ip_version, "ipv4") == 0)
15623                 l2_encap_conf.select_ipv4 = 1;
15624         else if (strcmp(res->ip_version, "ipv6") == 0)
15625                 l2_encap_conf.select_ipv4 = 0;
15626         else
15627                 return;
15628         if (l2_encap_conf.select_vlan)
15629                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15630         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15631                    RTE_ETHER_ADDR_LEN);
15632         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15633                    RTE_ETHER_ADDR_LEN);
15634 }
15635
15636 cmdline_parse_inst_t cmd_set_l2_encap = {
15637         .f = cmd_set_l2_encap_parsed,
15638         .data = NULL,
15639         .help_str = "set l2_encap ip-version ipv4|ipv6"
15640                 " eth-src <eth-src> eth-dst <eth-dst>",
15641         .tokens = {
15642                 (void *)&cmd_set_l2_encap_set,
15643                 (void *)&cmd_set_l2_encap_l2_encap,
15644                 (void *)&cmd_set_l2_encap_ip_version,
15645                 (void *)&cmd_set_l2_encap_ip_version_value,
15646                 (void *)&cmd_set_l2_encap_eth_src,
15647                 (void *)&cmd_set_l2_encap_eth_src_value,
15648                 (void *)&cmd_set_l2_encap_eth_dst,
15649                 (void *)&cmd_set_l2_encap_eth_dst_value,
15650                 NULL,
15651         },
15652 };
15653
15654 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15655         .f = cmd_set_l2_encap_parsed,
15656         .data = NULL,
15657         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15658                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15659         .tokens = {
15660                 (void *)&cmd_set_l2_encap_set,
15661                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15662                 (void *)&cmd_set_l2_encap_ip_version,
15663                 (void *)&cmd_set_l2_encap_ip_version_value,
15664                 (void *)&cmd_set_l2_encap_vlan,
15665                 (void *)&cmd_set_l2_encap_vlan_value,
15666                 (void *)&cmd_set_l2_encap_eth_src,
15667                 (void *)&cmd_set_l2_encap_eth_src_value,
15668                 (void *)&cmd_set_l2_encap_eth_dst,
15669                 (void *)&cmd_set_l2_encap_eth_dst_value,
15670                 NULL,
15671         },
15672 };
15673
15674 /** Set L2 decapsulation details */
15675 struct cmd_set_l2_decap_result {
15676         cmdline_fixed_string_t set;
15677         cmdline_fixed_string_t l2_decap;
15678         cmdline_fixed_string_t pos_token;
15679         uint32_t vlan_present:1;
15680 };
15681
15682 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15683         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15684 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15685         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15686                                  "l2_decap");
15687 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15688         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15689                                  "l2_decap-with-vlan");
15690
15691 static void cmd_set_l2_decap_parsed(void *parsed_result,
15692         __attribute__((unused)) struct cmdline *cl,
15693         __attribute__((unused)) void *data)
15694 {
15695         struct cmd_set_l2_decap_result *res = parsed_result;
15696
15697         if (strcmp(res->l2_decap, "l2_decap") == 0)
15698                 l2_decap_conf.select_vlan = 0;
15699         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15700                 l2_decap_conf.select_vlan = 1;
15701 }
15702
15703 cmdline_parse_inst_t cmd_set_l2_decap = {
15704         .f = cmd_set_l2_decap_parsed,
15705         .data = NULL,
15706         .help_str = "set l2_decap",
15707         .tokens = {
15708                 (void *)&cmd_set_l2_decap_set,
15709                 (void *)&cmd_set_l2_decap_l2_decap,
15710                 NULL,
15711         },
15712 };
15713
15714 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15715         .f = cmd_set_l2_decap_parsed,
15716         .data = NULL,
15717         .help_str = "set l2_decap-with-vlan",
15718         .tokens = {
15719                 (void *)&cmd_set_l2_decap_set,
15720                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15721                 NULL,
15722         },
15723 };
15724
15725 /** Set MPLSoGRE encapsulation details */
15726 struct cmd_set_mplsogre_encap_result {
15727         cmdline_fixed_string_t set;
15728         cmdline_fixed_string_t mplsogre;
15729         cmdline_fixed_string_t pos_token;
15730         cmdline_fixed_string_t ip_version;
15731         uint32_t vlan_present:1;
15732         uint32_t label;
15733         cmdline_ipaddr_t ip_src;
15734         cmdline_ipaddr_t ip_dst;
15735         uint16_t tci;
15736         struct rte_ether_addr eth_src;
15737         struct rte_ether_addr eth_dst;
15738 };
15739
15740 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15741         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15742                                  "set");
15743 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15744         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15745                                  "mplsogre_encap");
15746 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15747         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15748                                  mplsogre, "mplsogre_encap-with-vlan");
15749 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15750         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15751                                  pos_token, "ip-version");
15752 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15753         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15754                                  ip_version, "ipv4#ipv6");
15755 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15757                                  pos_token, "label");
15758 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15759         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15760                               UINT32);
15761 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15762         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15763                                  pos_token, "ip-src");
15764 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15765         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15766 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15767         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15768                                  pos_token, "ip-dst");
15769 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15770         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15771 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15772         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15773                                  pos_token, "vlan-tci");
15774 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15775         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15776                               UINT16);
15777 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15778         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15779                                  pos_token, "eth-src");
15780 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15781         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15782                                     eth_src);
15783 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15784         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15785                                  pos_token, "eth-dst");
15786 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15787         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15788                                     eth_dst);
15789
15790 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15791         __attribute__((unused)) struct cmdline *cl,
15792         __attribute__((unused)) void *data)
15793 {
15794         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15795         union {
15796                 uint32_t mplsogre_label;
15797                 uint8_t label[4];
15798         } id = {
15799                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15800         };
15801
15802         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15803                 mplsogre_encap_conf.select_vlan = 0;
15804         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15805                 mplsogre_encap_conf.select_vlan = 1;
15806         if (strcmp(res->ip_version, "ipv4") == 0)
15807                 mplsogre_encap_conf.select_ipv4 = 1;
15808         else if (strcmp(res->ip_version, "ipv6") == 0)
15809                 mplsogre_encap_conf.select_ipv4 = 0;
15810         else
15811                 return;
15812         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15813         if (mplsogre_encap_conf.select_ipv4) {
15814                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15815                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15816         } else {
15817                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15818                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15819         }
15820         if (mplsogre_encap_conf.select_vlan)
15821                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15822         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15823                    RTE_ETHER_ADDR_LEN);
15824         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15825                    RTE_ETHER_ADDR_LEN);
15826 }
15827
15828 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15829         .f = cmd_set_mplsogre_encap_parsed,
15830         .data = NULL,
15831         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15832                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15833                 " eth-dst <eth-dst>",
15834         .tokens = {
15835                 (void *)&cmd_set_mplsogre_encap_set,
15836                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15837                 (void *)&cmd_set_mplsogre_encap_ip_version,
15838                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15839                 (void *)&cmd_set_mplsogre_encap_label,
15840                 (void *)&cmd_set_mplsogre_encap_label_value,
15841                 (void *)&cmd_set_mplsogre_encap_ip_src,
15842                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15843                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15844                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15845                 (void *)&cmd_set_mplsogre_encap_eth_src,
15846                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15847                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15848                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15849                 NULL,
15850         },
15851 };
15852
15853 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15854         .f = cmd_set_mplsogre_encap_parsed,
15855         .data = NULL,
15856         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15857                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15858                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15859         .tokens = {
15860                 (void *)&cmd_set_mplsogre_encap_set,
15861                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15862                 (void *)&cmd_set_mplsogre_encap_ip_version,
15863                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15864                 (void *)&cmd_set_mplsogre_encap_label,
15865                 (void *)&cmd_set_mplsogre_encap_label_value,
15866                 (void *)&cmd_set_mplsogre_encap_ip_src,
15867                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15868                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15869                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15870                 (void *)&cmd_set_mplsogre_encap_vlan,
15871                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15872                 (void *)&cmd_set_mplsogre_encap_eth_src,
15873                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15874                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15875                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15876                 NULL,
15877         },
15878 };
15879
15880 /** Set MPLSoGRE decapsulation details */
15881 struct cmd_set_mplsogre_decap_result {
15882         cmdline_fixed_string_t set;
15883         cmdline_fixed_string_t mplsogre;
15884         cmdline_fixed_string_t pos_token;
15885         cmdline_fixed_string_t ip_version;
15886         uint32_t vlan_present:1;
15887 };
15888
15889 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15890         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15891                                  "set");
15892 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15893         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15894                                  "mplsogre_decap");
15895 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15896         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15897                                  mplsogre, "mplsogre_decap-with-vlan");
15898 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15899         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15900                                  pos_token, "ip-version");
15901 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15903                                  ip_version, "ipv4#ipv6");
15904
15905 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15906         __attribute__((unused)) struct cmdline *cl,
15907         __attribute__((unused)) void *data)
15908 {
15909         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15910
15911         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15912                 mplsogre_decap_conf.select_vlan = 0;
15913         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15914                 mplsogre_decap_conf.select_vlan = 1;
15915         if (strcmp(res->ip_version, "ipv4") == 0)
15916                 mplsogre_decap_conf.select_ipv4 = 1;
15917         else if (strcmp(res->ip_version, "ipv6") == 0)
15918                 mplsogre_decap_conf.select_ipv4 = 0;
15919 }
15920
15921 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15922         .f = cmd_set_mplsogre_decap_parsed,
15923         .data = NULL,
15924         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15925         .tokens = {
15926                 (void *)&cmd_set_mplsogre_decap_set,
15927                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15928                 (void *)&cmd_set_mplsogre_decap_ip_version,
15929                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15930                 NULL,
15931         },
15932 };
15933
15934 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15935         .f = cmd_set_mplsogre_decap_parsed,
15936         .data = NULL,
15937         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15938         .tokens = {
15939                 (void *)&cmd_set_mplsogre_decap_set,
15940                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15941                 (void *)&cmd_set_mplsogre_decap_ip_version,
15942                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15943                 NULL,
15944         },
15945 };
15946
15947 /** Set MPLSoUDP encapsulation details */
15948 struct cmd_set_mplsoudp_encap_result {
15949         cmdline_fixed_string_t set;
15950         cmdline_fixed_string_t mplsoudp;
15951         cmdline_fixed_string_t pos_token;
15952         cmdline_fixed_string_t ip_version;
15953         uint32_t vlan_present:1;
15954         uint32_t label;
15955         uint16_t udp_src;
15956         uint16_t udp_dst;
15957         cmdline_ipaddr_t ip_src;
15958         cmdline_ipaddr_t ip_dst;
15959         uint16_t tci;
15960         struct rte_ether_addr eth_src;
15961         struct rte_ether_addr eth_dst;
15962 };
15963
15964 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15965         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15966                                  "set");
15967 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15968         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15969                                  "mplsoudp_encap");
15970 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15971         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15972                                  mplsoudp, "mplsoudp_encap-with-vlan");
15973 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15974         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15975                                  pos_token, "ip-version");
15976 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15977         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15978                                  ip_version, "ipv4#ipv6");
15979 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15981                                  pos_token, "label");
15982 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15983         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15984                               UINT32);
15985 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15987                                  pos_token, "udp-src");
15988 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15989         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15990                               UINT16);
15991 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15993                                  pos_token, "udp-dst");
15994 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15995         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15996                               UINT16);
15997 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15999                                  pos_token, "ip-src");
16000 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16001         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16002 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16003         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16004                                  pos_token, "ip-dst");
16005 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16006         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16007 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16008         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16009                                  pos_token, "vlan-tci");
16010 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16011         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16012                               UINT16);
16013 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16014         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16015                                  pos_token, "eth-src");
16016 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16017         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16018                                     eth_src);
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16021                                  pos_token, "eth-dst");
16022 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16023         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16024                                     eth_dst);
16025
16026 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16027         __attribute__((unused)) struct cmdline *cl,
16028         __attribute__((unused)) void *data)
16029 {
16030         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16031         union {
16032                 uint32_t mplsoudp_label;
16033                 uint8_t label[4];
16034         } id = {
16035                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16036         };
16037
16038         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16039                 mplsoudp_encap_conf.select_vlan = 0;
16040         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16041                 mplsoudp_encap_conf.select_vlan = 1;
16042         if (strcmp(res->ip_version, "ipv4") == 0)
16043                 mplsoudp_encap_conf.select_ipv4 = 1;
16044         else if (strcmp(res->ip_version, "ipv6") == 0)
16045                 mplsoudp_encap_conf.select_ipv4 = 0;
16046         else
16047                 return;
16048         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16049         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16050         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16051         if (mplsoudp_encap_conf.select_ipv4) {
16052                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16053                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16054         } else {
16055                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16056                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16057         }
16058         if (mplsoudp_encap_conf.select_vlan)
16059                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16060         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16061                    RTE_ETHER_ADDR_LEN);
16062         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16063                    RTE_ETHER_ADDR_LEN);
16064 }
16065
16066 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16067         .f = cmd_set_mplsoudp_encap_parsed,
16068         .data = NULL,
16069         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16070                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16071                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16072         .tokens = {
16073                 (void *)&cmd_set_mplsoudp_encap_set,
16074                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16075                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16076                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16077                 (void *)&cmd_set_mplsoudp_encap_label,
16078                 (void *)&cmd_set_mplsoudp_encap_label_value,
16079                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16080                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16081                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16082                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16083                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16084                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16085                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16086                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16087                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16088                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16089                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16090                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16091                 NULL,
16092         },
16093 };
16094
16095 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16096         .f = cmd_set_mplsoudp_encap_parsed,
16097         .data = NULL,
16098         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16099                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16100                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16101                 " eth-src <eth-src> eth-dst <eth-dst>",
16102         .tokens = {
16103                 (void *)&cmd_set_mplsoudp_encap_set,
16104                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16105                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16106                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16107                 (void *)&cmd_set_mplsoudp_encap_label,
16108                 (void *)&cmd_set_mplsoudp_encap_label_value,
16109                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16110                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16111                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16112                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16113                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16114                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16115                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16116                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16117                 (void *)&cmd_set_mplsoudp_encap_vlan,
16118                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16119                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16120                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16121                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16122                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16123                 NULL,
16124         },
16125 };
16126
16127 /** Set MPLSoUDP decapsulation details */
16128 struct cmd_set_mplsoudp_decap_result {
16129         cmdline_fixed_string_t set;
16130         cmdline_fixed_string_t mplsoudp;
16131         cmdline_fixed_string_t pos_token;
16132         cmdline_fixed_string_t ip_version;
16133         uint32_t vlan_present:1;
16134 };
16135
16136 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16137         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16138                                  "set");
16139 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16140         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16141                                  "mplsoudp_decap");
16142 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16143         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16144                                  mplsoudp, "mplsoudp_decap-with-vlan");
16145 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16146         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16147                                  pos_token, "ip-version");
16148 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16149         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16150                                  ip_version, "ipv4#ipv6");
16151
16152 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16153         __attribute__((unused)) struct cmdline *cl,
16154         __attribute__((unused)) void *data)
16155 {
16156         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16157
16158         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16159                 mplsoudp_decap_conf.select_vlan = 0;
16160         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16161                 mplsoudp_decap_conf.select_vlan = 1;
16162         if (strcmp(res->ip_version, "ipv4") == 0)
16163                 mplsoudp_decap_conf.select_ipv4 = 1;
16164         else if (strcmp(res->ip_version, "ipv6") == 0)
16165                 mplsoudp_decap_conf.select_ipv4 = 0;
16166 }
16167
16168 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16169         .f = cmd_set_mplsoudp_decap_parsed,
16170         .data = NULL,
16171         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16172         .tokens = {
16173                 (void *)&cmd_set_mplsoudp_decap_set,
16174                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16175                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16176                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16177                 NULL,
16178         },
16179 };
16180
16181 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16182         .f = cmd_set_mplsoudp_decap_parsed,
16183         .data = NULL,
16184         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16185         .tokens = {
16186                 (void *)&cmd_set_mplsoudp_decap_set,
16187                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16188                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16189                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16190                 NULL,
16191         },
16192 };
16193
16194 /* Strict link priority scheduling mode setting */
16195 static void
16196 cmd_strict_link_prio_parsed(
16197         void *parsed_result,
16198         __attribute__((unused)) struct cmdline *cl,
16199         __attribute__((unused)) void *data)
16200 {
16201         struct cmd_vf_tc_bw_result *res = parsed_result;
16202         int ret = -ENOTSUP;
16203
16204         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16205                 return;
16206
16207 #ifdef RTE_LIBRTE_I40E_PMD
16208         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16209 #endif
16210
16211         switch (ret) {
16212         case 0:
16213                 break;
16214         case -EINVAL:
16215                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16216                 break;
16217         case -ENODEV:
16218                 printf("invalid port_id %d\n", res->port_id);
16219                 break;
16220         case -ENOTSUP:
16221                 printf("function not implemented\n");
16222                 break;
16223         default:
16224                 printf("programming error: (%s)\n", strerror(-ret));
16225         }
16226 }
16227
16228 cmdline_parse_inst_t cmd_strict_link_prio = {
16229         .f = cmd_strict_link_prio_parsed,
16230         .data = NULL,
16231         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16232         .tokens = {
16233                 (void *)&cmd_vf_tc_bw_set,
16234                 (void *)&cmd_vf_tc_bw_tx,
16235                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16236                 (void *)&cmd_vf_tc_bw_port_id,
16237                 (void *)&cmd_vf_tc_bw_tc_map,
16238                 NULL,
16239         },
16240 };
16241
16242 /* Load dynamic device personalization*/
16243 struct cmd_ddp_add_result {
16244         cmdline_fixed_string_t ddp;
16245         cmdline_fixed_string_t add;
16246         portid_t port_id;
16247         char filepath[];
16248 };
16249
16250 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16251         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16252 cmdline_parse_token_string_t cmd_ddp_add_add =
16253         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16254 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16255         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16256 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16257         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16258
16259 static void
16260 cmd_ddp_add_parsed(
16261         void *parsed_result,
16262         __attribute__((unused)) struct cmdline *cl,
16263         __attribute__((unused)) void *data)
16264 {
16265         struct cmd_ddp_add_result *res = parsed_result;
16266         uint8_t *buff;
16267         uint32_t size;
16268         char *filepath;
16269         char *file_fld[2];
16270         int file_num;
16271         int ret = -ENOTSUP;
16272
16273         if (!all_ports_stopped()) {
16274                 printf("Please stop all ports first\n");
16275                 return;
16276         }
16277
16278         filepath = strdup(res->filepath);
16279         if (filepath == NULL) {
16280                 printf("Failed to allocate memory\n");
16281                 return;
16282         }
16283         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16284
16285         buff = open_file(file_fld[0], &size);
16286         if (!buff) {
16287                 free((void *)filepath);
16288                 return;
16289         }
16290
16291 #ifdef RTE_LIBRTE_I40E_PMD
16292         if (ret == -ENOTSUP)
16293                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16294                                                buff, size,
16295                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16296 #endif
16297
16298         if (ret == -EEXIST)
16299                 printf("Profile has already existed.\n");
16300         else if (ret < 0)
16301                 printf("Failed to load profile.\n");
16302         else if (file_num == 2)
16303                 save_file(file_fld[1], buff, size);
16304
16305         close_file(buff);
16306         free((void *)filepath);
16307 }
16308
16309 cmdline_parse_inst_t cmd_ddp_add = {
16310         .f = cmd_ddp_add_parsed,
16311         .data = NULL,
16312         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16313         .tokens = {
16314                 (void *)&cmd_ddp_add_ddp,
16315                 (void *)&cmd_ddp_add_add,
16316                 (void *)&cmd_ddp_add_port_id,
16317                 (void *)&cmd_ddp_add_filepath,
16318                 NULL,
16319         },
16320 };
16321
16322 /* Delete dynamic device personalization*/
16323 struct cmd_ddp_del_result {
16324         cmdline_fixed_string_t ddp;
16325         cmdline_fixed_string_t del;
16326         portid_t port_id;
16327         char filepath[];
16328 };
16329
16330 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16331         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16332 cmdline_parse_token_string_t cmd_ddp_del_del =
16333         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16334 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16335         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16336 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16337         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16338
16339 static void
16340 cmd_ddp_del_parsed(
16341         void *parsed_result,
16342         __attribute__((unused)) struct cmdline *cl,
16343         __attribute__((unused)) void *data)
16344 {
16345         struct cmd_ddp_del_result *res = parsed_result;
16346         uint8_t *buff;
16347         uint32_t size;
16348         int ret = -ENOTSUP;
16349
16350         if (!all_ports_stopped()) {
16351                 printf("Please stop all ports first\n");
16352                 return;
16353         }
16354
16355         buff = open_file(res->filepath, &size);
16356         if (!buff)
16357                 return;
16358
16359 #ifdef RTE_LIBRTE_I40E_PMD
16360         if (ret == -ENOTSUP)
16361                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16362                                                buff, size,
16363                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16364 #endif
16365
16366         if (ret == -EACCES)
16367                 printf("Profile does not exist.\n");
16368         else if (ret < 0)
16369                 printf("Failed to delete profile.\n");
16370
16371         close_file(buff);
16372 }
16373
16374 cmdline_parse_inst_t cmd_ddp_del = {
16375         .f = cmd_ddp_del_parsed,
16376         .data = NULL,
16377         .help_str = "ddp del <port_id> <backup_profile_path>",
16378         .tokens = {
16379                 (void *)&cmd_ddp_del_ddp,
16380                 (void *)&cmd_ddp_del_del,
16381                 (void *)&cmd_ddp_del_port_id,
16382                 (void *)&cmd_ddp_del_filepath,
16383                 NULL,
16384         },
16385 };
16386
16387 /* Get dynamic device personalization profile info */
16388 struct cmd_ddp_info_result {
16389         cmdline_fixed_string_t ddp;
16390         cmdline_fixed_string_t get;
16391         cmdline_fixed_string_t info;
16392         char filepath[];
16393 };
16394
16395 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16396         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16397 cmdline_parse_token_string_t cmd_ddp_info_get =
16398         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16399 cmdline_parse_token_string_t cmd_ddp_info_info =
16400         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16401 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16402         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16403
16404 static void
16405 cmd_ddp_info_parsed(
16406         void *parsed_result,
16407         __attribute__((unused)) struct cmdline *cl,
16408         __attribute__((unused)) void *data)
16409 {
16410         struct cmd_ddp_info_result *res = parsed_result;
16411         uint8_t *pkg;
16412         uint32_t pkg_size;
16413         int ret = -ENOTSUP;
16414 #ifdef RTE_LIBRTE_I40E_PMD
16415         uint32_t i, j, n;
16416         uint8_t *buff;
16417         uint32_t buff_size = 0;
16418         struct rte_pmd_i40e_profile_info info;
16419         uint32_t dev_num = 0;
16420         struct rte_pmd_i40e_ddp_device_id *devs;
16421         uint32_t proto_num = 0;
16422         struct rte_pmd_i40e_proto_info *proto = NULL;
16423         uint32_t pctype_num = 0;
16424         struct rte_pmd_i40e_ptype_info *pctype;
16425         uint32_t ptype_num = 0;
16426         struct rte_pmd_i40e_ptype_info *ptype;
16427         uint8_t proto_id;
16428
16429 #endif
16430
16431         pkg = open_file(res->filepath, &pkg_size);
16432         if (!pkg)
16433                 return;
16434
16435 #ifdef RTE_LIBRTE_I40E_PMD
16436         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16437                                 (uint8_t *)&info, sizeof(info),
16438                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16439         if (!ret) {
16440                 printf("Global Track id:       0x%x\n", info.track_id);
16441                 printf("Global Version:        %d.%d.%d.%d\n",
16442                         info.version.major,
16443                         info.version.minor,
16444                         info.version.update,
16445                         info.version.draft);
16446                 printf("Global Package name:   %s\n\n", info.name);
16447         }
16448
16449         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16450                                 (uint8_t *)&info, sizeof(info),
16451                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16452         if (!ret) {
16453                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16454                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16455                         info.version.major,
16456                         info.version.minor,
16457                         info.version.update,
16458                         info.version.draft);
16459                 printf("i40e Profile name:     %s\n\n", info.name);
16460         }
16461
16462         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16463                                 (uint8_t *)&buff_size, sizeof(buff_size),
16464                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16465         if (!ret && buff_size) {
16466                 buff = (uint8_t *)malloc(buff_size);
16467                 if (buff) {
16468                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16469                                                 buff, buff_size,
16470                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16471                         if (!ret)
16472                                 printf("Package Notes:\n%s\n\n", buff);
16473                         free(buff);
16474                 }
16475         }
16476
16477         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16478                                 (uint8_t *)&dev_num, sizeof(dev_num),
16479                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16480         if (!ret && dev_num) {
16481                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16482                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16483                 if (devs) {
16484                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16485                                                 (uint8_t *)devs, buff_size,
16486                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16487                         if (!ret) {
16488                                 printf("List of supported devices:\n");
16489                                 for (i = 0; i < dev_num; i++) {
16490                                         printf("  %04X:%04X %04X:%04X\n",
16491                                                 devs[i].vendor_dev_id >> 16,
16492                                                 devs[i].vendor_dev_id & 0xFFFF,
16493                                                 devs[i].sub_vendor_dev_id >> 16,
16494                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16495                                 }
16496                                 printf("\n");
16497                         }
16498                         free(devs);
16499                 }
16500         }
16501
16502         /* get information about protocols and packet types */
16503         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16504                 (uint8_t *)&proto_num, sizeof(proto_num),
16505                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16506         if (ret || !proto_num)
16507                 goto no_print_return;
16508
16509         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16510         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16511         if (!proto)
16512                 goto no_print_return;
16513
16514         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16515                                         buff_size,
16516                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16517         if (!ret) {
16518                 printf("List of used protocols:\n");
16519                 for (i = 0; i < proto_num; i++)
16520                         printf("  %2u: %s\n", proto[i].proto_id,
16521                                proto[i].name);
16522                 printf("\n");
16523         }
16524         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16525                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16526                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16527         if (ret || !pctype_num)
16528                 goto no_print_pctypes;
16529
16530         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16531         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16532         if (!pctype)
16533                 goto no_print_pctypes;
16534
16535         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16536                                         buff_size,
16537                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16538         if (ret) {
16539                 free(pctype);
16540                 goto no_print_pctypes;
16541         }
16542
16543         printf("List of defined packet classification types:\n");
16544         for (i = 0; i < pctype_num; i++) {
16545                 printf("  %2u:", pctype[i].ptype_id);
16546                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16547                         proto_id = pctype[i].protocols[j];
16548                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16549                                 for (n = 0; n < proto_num; n++) {
16550                                         if (proto[n].proto_id == proto_id) {
16551                                                 printf(" %s", proto[n].name);
16552                                                 break;
16553                                         }
16554                                 }
16555                         }
16556                 }
16557                 printf("\n");
16558         }
16559         printf("\n");
16560         free(pctype);
16561
16562 no_print_pctypes:
16563
16564         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16565                                         sizeof(ptype_num),
16566                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16567         if (ret || !ptype_num)
16568                 goto no_print_return;
16569
16570         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16571         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16572         if (!ptype)
16573                 goto no_print_return;
16574
16575         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16576                                         buff_size,
16577                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16578         if (ret) {
16579                 free(ptype);
16580                 goto no_print_return;
16581         }
16582         printf("List of defined packet types:\n");
16583         for (i = 0; i < ptype_num; i++) {
16584                 printf("  %2u:", ptype[i].ptype_id);
16585                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16586                         proto_id = ptype[i].protocols[j];
16587                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16588                                 for (n = 0; n < proto_num; n++) {
16589                                         if (proto[n].proto_id == proto_id) {
16590                                                 printf(" %s", proto[n].name);
16591                                                 break;
16592                                         }
16593                                 }
16594                         }
16595                 }
16596                 printf("\n");
16597         }
16598         free(ptype);
16599         printf("\n");
16600
16601         ret = 0;
16602 no_print_return:
16603         if (proto)
16604                 free(proto);
16605 #endif
16606         if (ret == -ENOTSUP)
16607                 printf("Function not supported in PMD driver\n");
16608         close_file(pkg);
16609 }
16610
16611 cmdline_parse_inst_t cmd_ddp_get_info = {
16612         .f = cmd_ddp_info_parsed,
16613         .data = NULL,
16614         .help_str = "ddp get info <profile_path>",
16615         .tokens = {
16616                 (void *)&cmd_ddp_info_ddp,
16617                 (void *)&cmd_ddp_info_get,
16618                 (void *)&cmd_ddp_info_info,
16619                 (void *)&cmd_ddp_info_filepath,
16620                 NULL,
16621         },
16622 };
16623
16624 /* Get dynamic device personalization profile info list*/
16625 #define PROFILE_INFO_SIZE 48
16626 #define MAX_PROFILE_NUM 16
16627
16628 struct cmd_ddp_get_list_result {
16629         cmdline_fixed_string_t ddp;
16630         cmdline_fixed_string_t get;
16631         cmdline_fixed_string_t list;
16632         portid_t port_id;
16633 };
16634
16635 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16636         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16637 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16638         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16639 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16640         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16641 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16642         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16643
16644 static void
16645 cmd_ddp_get_list_parsed(
16646         __attribute__((unused)) void *parsed_result,
16647         __attribute__((unused)) struct cmdline *cl,
16648         __attribute__((unused)) void *data)
16649 {
16650 #ifdef RTE_LIBRTE_I40E_PMD
16651         struct cmd_ddp_get_list_result *res = parsed_result;
16652         struct rte_pmd_i40e_profile_list *p_list;
16653         struct rte_pmd_i40e_profile_info *p_info;
16654         uint32_t p_num;
16655         uint32_t size;
16656         uint32_t i;
16657 #endif
16658         int ret = -ENOTSUP;
16659
16660 #ifdef RTE_LIBRTE_I40E_PMD
16661         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16662         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16663         if (!p_list)
16664                 printf("%s: Failed to malloc buffer\n", __func__);
16665
16666         if (ret == -ENOTSUP)
16667                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16668                                                 (uint8_t *)p_list, size);
16669
16670         if (!ret) {
16671                 p_num = p_list->p_count;
16672                 printf("Profile number is: %d\n\n", p_num);
16673
16674                 for (i = 0; i < p_num; i++) {
16675                         p_info = &p_list->p_info[i];
16676                         printf("Profile %d:\n", i);
16677                         printf("Track id:     0x%x\n", p_info->track_id);
16678                         printf("Version:      %d.%d.%d.%d\n",
16679                                p_info->version.major,
16680                                p_info->version.minor,
16681                                p_info->version.update,
16682                                p_info->version.draft);
16683                         printf("Profile name: %s\n\n", p_info->name);
16684                 }
16685         }
16686
16687         free(p_list);
16688 #endif
16689
16690         if (ret < 0)
16691                 printf("Failed to get ddp list\n");
16692 }
16693
16694 cmdline_parse_inst_t cmd_ddp_get_list = {
16695         .f = cmd_ddp_get_list_parsed,
16696         .data = NULL,
16697         .help_str = "ddp get list <port_id>",
16698         .tokens = {
16699                 (void *)&cmd_ddp_get_list_ddp,
16700                 (void *)&cmd_ddp_get_list_get,
16701                 (void *)&cmd_ddp_get_list_list,
16702                 (void *)&cmd_ddp_get_list_port_id,
16703                 NULL,
16704         },
16705 };
16706
16707 /* Configure input set */
16708 struct cmd_cfg_input_set_result {
16709         cmdline_fixed_string_t port;
16710         cmdline_fixed_string_t cfg;
16711         portid_t port_id;
16712         cmdline_fixed_string_t pctype;
16713         uint8_t pctype_id;
16714         cmdline_fixed_string_t inset_type;
16715         cmdline_fixed_string_t opt;
16716         cmdline_fixed_string_t field;
16717         uint8_t field_idx;
16718 };
16719
16720 static void
16721 cmd_cfg_input_set_parsed(
16722         __attribute__((unused)) void *parsed_result,
16723         __attribute__((unused)) struct cmdline *cl,
16724         __attribute__((unused)) void *data)
16725 {
16726 #ifdef RTE_LIBRTE_I40E_PMD
16727         struct cmd_cfg_input_set_result *res = parsed_result;
16728         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16729         struct rte_pmd_i40e_inset inset;
16730 #endif
16731         int ret = -ENOTSUP;
16732
16733         if (!all_ports_stopped()) {
16734                 printf("Please stop all ports first\n");
16735                 return;
16736         }
16737
16738 #ifdef RTE_LIBRTE_I40E_PMD
16739         if (!strcmp(res->inset_type, "hash_inset"))
16740                 inset_type = INSET_HASH;
16741         else if (!strcmp(res->inset_type, "fdir_inset"))
16742                 inset_type = INSET_FDIR;
16743         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16744                 inset_type = INSET_FDIR_FLX;
16745         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16746                                      &inset, inset_type);
16747         if (ret) {
16748                 printf("Failed to get input set.\n");
16749                 return;
16750         }
16751
16752         if (!strcmp(res->opt, "get")) {
16753                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16754                                                    res->field_idx);
16755                 if (ret)
16756                         printf("Field index %d is enabled.\n", res->field_idx);
16757                 else
16758                         printf("Field index %d is disabled.\n", res->field_idx);
16759                 return;
16760         } else if (!strcmp(res->opt, "set"))
16761                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16762                                                    res->field_idx);
16763         else if (!strcmp(res->opt, "clear"))
16764                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16765                                                      res->field_idx);
16766         if (ret) {
16767                 printf("Failed to configure input set field.\n");
16768                 return;
16769         }
16770
16771         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16772                                      &inset, inset_type);
16773         if (ret) {
16774                 printf("Failed to set input set.\n");
16775                 return;
16776         }
16777 #endif
16778
16779         if (ret == -ENOTSUP)
16780                 printf("Function not supported\n");
16781 }
16782
16783 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16784         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16785                                  port, "port");
16786 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16787         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16788                                  cfg, "config");
16789 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16790         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16791                               port_id, UINT16);
16792 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16793         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16794                                  pctype, "pctype");
16795 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16796         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16797                               pctype_id, UINT8);
16798 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16799         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16800                                  inset_type,
16801                                  "hash_inset#fdir_inset#fdir_flx_inset");
16802 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16803         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16804                                  opt, "get#set#clear");
16805 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16806         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16807                                  field, "field");
16808 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16809         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16810                               field_idx, UINT8);
16811
16812 cmdline_parse_inst_t cmd_cfg_input_set = {
16813         .f = cmd_cfg_input_set_parsed,
16814         .data = NULL,
16815         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16816                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16817         .tokens = {
16818                 (void *)&cmd_cfg_input_set_port,
16819                 (void *)&cmd_cfg_input_set_cfg,
16820                 (void *)&cmd_cfg_input_set_port_id,
16821                 (void *)&cmd_cfg_input_set_pctype,
16822                 (void *)&cmd_cfg_input_set_pctype_id,
16823                 (void *)&cmd_cfg_input_set_inset_type,
16824                 (void *)&cmd_cfg_input_set_opt,
16825                 (void *)&cmd_cfg_input_set_field,
16826                 (void *)&cmd_cfg_input_set_field_idx,
16827                 NULL,
16828         },
16829 };
16830
16831 /* Clear input set */
16832 struct cmd_clear_input_set_result {
16833         cmdline_fixed_string_t port;
16834         cmdline_fixed_string_t cfg;
16835         portid_t port_id;
16836         cmdline_fixed_string_t pctype;
16837         uint8_t pctype_id;
16838         cmdline_fixed_string_t inset_type;
16839         cmdline_fixed_string_t clear;
16840         cmdline_fixed_string_t all;
16841 };
16842
16843 static void
16844 cmd_clear_input_set_parsed(
16845         __attribute__((unused)) void *parsed_result,
16846         __attribute__((unused)) struct cmdline *cl,
16847         __attribute__((unused)) void *data)
16848 {
16849 #ifdef RTE_LIBRTE_I40E_PMD
16850         struct cmd_clear_input_set_result *res = parsed_result;
16851         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16852         struct rte_pmd_i40e_inset inset;
16853 #endif
16854         int ret = -ENOTSUP;
16855
16856         if (!all_ports_stopped()) {
16857                 printf("Please stop all ports first\n");
16858                 return;
16859         }
16860
16861 #ifdef RTE_LIBRTE_I40E_PMD
16862         if (!strcmp(res->inset_type, "hash_inset"))
16863                 inset_type = INSET_HASH;
16864         else if (!strcmp(res->inset_type, "fdir_inset"))
16865                 inset_type = INSET_FDIR;
16866         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16867                 inset_type = INSET_FDIR_FLX;
16868
16869         memset(&inset, 0, sizeof(inset));
16870
16871         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16872                                      &inset, inset_type);
16873         if (ret) {
16874                 printf("Failed to clear input set.\n");
16875                 return;
16876         }
16877
16878 #endif
16879
16880         if (ret == -ENOTSUP)
16881                 printf("Function not supported\n");
16882 }
16883
16884 cmdline_parse_token_string_t cmd_clear_input_set_port =
16885         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16886                                  port, "port");
16887 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16888         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16889                                  cfg, "config");
16890 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16891         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16892                               port_id, UINT16);
16893 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16894         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16895                                  pctype, "pctype");
16896 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16897         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16898                               pctype_id, UINT8);
16899 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16900         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16901                                  inset_type,
16902                                  "hash_inset#fdir_inset#fdir_flx_inset");
16903 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16904         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16905                                  clear, "clear");
16906 cmdline_parse_token_string_t cmd_clear_input_set_all =
16907         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16908                                  all, "all");
16909
16910 cmdline_parse_inst_t cmd_clear_input_set = {
16911         .f = cmd_clear_input_set_parsed,
16912         .data = NULL,
16913         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16914                     "fdir_inset|fdir_flx_inset clear all",
16915         .tokens = {
16916                 (void *)&cmd_clear_input_set_port,
16917                 (void *)&cmd_clear_input_set_cfg,
16918                 (void *)&cmd_clear_input_set_port_id,
16919                 (void *)&cmd_clear_input_set_pctype,
16920                 (void *)&cmd_clear_input_set_pctype_id,
16921                 (void *)&cmd_clear_input_set_inset_type,
16922                 (void *)&cmd_clear_input_set_clear,
16923                 (void *)&cmd_clear_input_set_all,
16924                 NULL,
16925         },
16926 };
16927
16928 /* show vf stats */
16929
16930 /* Common result structure for show vf stats */
16931 struct cmd_show_vf_stats_result {
16932         cmdline_fixed_string_t show;
16933         cmdline_fixed_string_t vf;
16934         cmdline_fixed_string_t stats;
16935         portid_t port_id;
16936         uint16_t vf_id;
16937 };
16938
16939 /* Common CLI fields show vf stats*/
16940 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16941         TOKEN_STRING_INITIALIZER
16942                 (struct cmd_show_vf_stats_result,
16943                  show, "show");
16944 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16945         TOKEN_STRING_INITIALIZER
16946                 (struct cmd_show_vf_stats_result,
16947                  vf, "vf");
16948 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16949         TOKEN_STRING_INITIALIZER
16950                 (struct cmd_show_vf_stats_result,
16951                  stats, "stats");
16952 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16953         TOKEN_NUM_INITIALIZER
16954                 (struct cmd_show_vf_stats_result,
16955                  port_id, UINT16);
16956 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16957         TOKEN_NUM_INITIALIZER
16958                 (struct cmd_show_vf_stats_result,
16959                  vf_id, UINT16);
16960
16961 static void
16962 cmd_show_vf_stats_parsed(
16963         void *parsed_result,
16964         __attribute__((unused)) struct cmdline *cl,
16965         __attribute__((unused)) void *data)
16966 {
16967         struct cmd_show_vf_stats_result *res = parsed_result;
16968         struct rte_eth_stats stats;
16969         int ret = -ENOTSUP;
16970         static const char *nic_stats_border = "########################";
16971
16972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16973                 return;
16974
16975         memset(&stats, 0, sizeof(stats));
16976
16977 #ifdef RTE_LIBRTE_I40E_PMD
16978         if (ret == -ENOTSUP)
16979                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16980                                                 res->vf_id,
16981                                                 &stats);
16982 #endif
16983 #ifdef RTE_LIBRTE_BNXT_PMD
16984         if (ret == -ENOTSUP)
16985                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16986                                                 res->vf_id,
16987                                                 &stats);
16988 #endif
16989
16990         switch (ret) {
16991         case 0:
16992                 break;
16993         case -EINVAL:
16994                 printf("invalid vf_id %d\n", res->vf_id);
16995                 break;
16996         case -ENODEV:
16997                 printf("invalid port_id %d\n", res->port_id);
16998                 break;
16999         case -ENOTSUP:
17000                 printf("function not implemented\n");
17001                 break;
17002         default:
17003                 printf("programming error: (%s)\n", strerror(-ret));
17004         }
17005
17006         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17007                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17008
17009         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17010                "%-"PRIu64"\n",
17011                stats.ipackets, stats.imissed, stats.ibytes);
17012         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17013         printf("  RX-nombuf:  %-10"PRIu64"\n",
17014                stats.rx_nombuf);
17015         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17016                "%-"PRIu64"\n",
17017                stats.opackets, stats.oerrors, stats.obytes);
17018
17019         printf("  %s############################%s\n",
17020                                nic_stats_border, nic_stats_border);
17021 }
17022
17023 cmdline_parse_inst_t cmd_show_vf_stats = {
17024         .f = cmd_show_vf_stats_parsed,
17025         .data = NULL,
17026         .help_str = "show vf stats <port_id> <vf_id>",
17027         .tokens = {
17028                 (void *)&cmd_show_vf_stats_show,
17029                 (void *)&cmd_show_vf_stats_vf,
17030                 (void *)&cmd_show_vf_stats_stats,
17031                 (void *)&cmd_show_vf_stats_port_id,
17032                 (void *)&cmd_show_vf_stats_vf_id,
17033                 NULL,
17034         },
17035 };
17036
17037 /* clear vf stats */
17038
17039 /* Common result structure for clear vf stats */
17040 struct cmd_clear_vf_stats_result {
17041         cmdline_fixed_string_t clear;
17042         cmdline_fixed_string_t vf;
17043         cmdline_fixed_string_t stats;
17044         portid_t port_id;
17045         uint16_t vf_id;
17046 };
17047
17048 /* Common CLI fields clear vf stats*/
17049 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17050         TOKEN_STRING_INITIALIZER
17051                 (struct cmd_clear_vf_stats_result,
17052                  clear, "clear");
17053 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17054         TOKEN_STRING_INITIALIZER
17055                 (struct cmd_clear_vf_stats_result,
17056                  vf, "vf");
17057 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17058         TOKEN_STRING_INITIALIZER
17059                 (struct cmd_clear_vf_stats_result,
17060                  stats, "stats");
17061 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17062         TOKEN_NUM_INITIALIZER
17063                 (struct cmd_clear_vf_stats_result,
17064                  port_id, UINT16);
17065 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17066         TOKEN_NUM_INITIALIZER
17067                 (struct cmd_clear_vf_stats_result,
17068                  vf_id, UINT16);
17069
17070 static void
17071 cmd_clear_vf_stats_parsed(
17072         void *parsed_result,
17073         __attribute__((unused)) struct cmdline *cl,
17074         __attribute__((unused)) void *data)
17075 {
17076         struct cmd_clear_vf_stats_result *res = parsed_result;
17077         int ret = -ENOTSUP;
17078
17079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17080                 return;
17081
17082 #ifdef RTE_LIBRTE_I40E_PMD
17083         if (ret == -ENOTSUP)
17084                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17085                                                   res->vf_id);
17086 #endif
17087 #ifdef RTE_LIBRTE_BNXT_PMD
17088         if (ret == -ENOTSUP)
17089                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17090                                                   res->vf_id);
17091 #endif
17092
17093         switch (ret) {
17094         case 0:
17095                 break;
17096         case -EINVAL:
17097                 printf("invalid vf_id %d\n", res->vf_id);
17098                 break;
17099         case -ENODEV:
17100                 printf("invalid port_id %d\n", res->port_id);
17101                 break;
17102         case -ENOTSUP:
17103                 printf("function not implemented\n");
17104                 break;
17105         default:
17106                 printf("programming error: (%s)\n", strerror(-ret));
17107         }
17108 }
17109
17110 cmdline_parse_inst_t cmd_clear_vf_stats = {
17111         .f = cmd_clear_vf_stats_parsed,
17112         .data = NULL,
17113         .help_str = "clear vf stats <port_id> <vf_id>",
17114         .tokens = {
17115                 (void *)&cmd_clear_vf_stats_clear,
17116                 (void *)&cmd_clear_vf_stats_vf,
17117                 (void *)&cmd_clear_vf_stats_stats,
17118                 (void *)&cmd_clear_vf_stats_port_id,
17119                 (void *)&cmd_clear_vf_stats_vf_id,
17120                 NULL,
17121         },
17122 };
17123
17124 /* port config pctype mapping reset */
17125
17126 /* Common result structure for port config pctype mapping reset */
17127 struct cmd_pctype_mapping_reset_result {
17128         cmdline_fixed_string_t port;
17129         cmdline_fixed_string_t config;
17130         portid_t port_id;
17131         cmdline_fixed_string_t pctype;
17132         cmdline_fixed_string_t mapping;
17133         cmdline_fixed_string_t reset;
17134 };
17135
17136 /* Common CLI fields for port config pctype mapping reset*/
17137 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17138         TOKEN_STRING_INITIALIZER
17139                 (struct cmd_pctype_mapping_reset_result,
17140                  port, "port");
17141 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17142         TOKEN_STRING_INITIALIZER
17143                 (struct cmd_pctype_mapping_reset_result,
17144                  config, "config");
17145 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17146         TOKEN_NUM_INITIALIZER
17147                 (struct cmd_pctype_mapping_reset_result,
17148                  port_id, UINT16);
17149 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17150         TOKEN_STRING_INITIALIZER
17151                 (struct cmd_pctype_mapping_reset_result,
17152                  pctype, "pctype");
17153 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17154         TOKEN_STRING_INITIALIZER
17155                 (struct cmd_pctype_mapping_reset_result,
17156                  mapping, "mapping");
17157 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17158         TOKEN_STRING_INITIALIZER
17159                 (struct cmd_pctype_mapping_reset_result,
17160                  reset, "reset");
17161
17162 static void
17163 cmd_pctype_mapping_reset_parsed(
17164         void *parsed_result,
17165         __attribute__((unused)) struct cmdline *cl,
17166         __attribute__((unused)) void *data)
17167 {
17168         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17169         int ret = -ENOTSUP;
17170
17171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17172                 return;
17173
17174 #ifdef RTE_LIBRTE_I40E_PMD
17175         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17176 #endif
17177
17178         switch (ret) {
17179         case 0:
17180                 break;
17181         case -ENODEV:
17182                 printf("invalid port_id %d\n", res->port_id);
17183                 break;
17184         case -ENOTSUP:
17185                 printf("function not implemented\n");
17186                 break;
17187         default:
17188                 printf("programming error: (%s)\n", strerror(-ret));
17189         }
17190 }
17191
17192 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17193         .f = cmd_pctype_mapping_reset_parsed,
17194         .data = NULL,
17195         .help_str = "port config <port_id> pctype mapping reset",
17196         .tokens = {
17197                 (void *)&cmd_pctype_mapping_reset_port,
17198                 (void *)&cmd_pctype_mapping_reset_config,
17199                 (void *)&cmd_pctype_mapping_reset_port_id,
17200                 (void *)&cmd_pctype_mapping_reset_pctype,
17201                 (void *)&cmd_pctype_mapping_reset_mapping,
17202                 (void *)&cmd_pctype_mapping_reset_reset,
17203                 NULL,
17204         },
17205 };
17206
17207 /* show port pctype mapping */
17208
17209 /* Common result structure for show port pctype mapping */
17210 struct cmd_pctype_mapping_get_result {
17211         cmdline_fixed_string_t show;
17212         cmdline_fixed_string_t port;
17213         portid_t port_id;
17214         cmdline_fixed_string_t pctype;
17215         cmdline_fixed_string_t mapping;
17216 };
17217
17218 /* Common CLI fields for pctype mapping get */
17219 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17220         TOKEN_STRING_INITIALIZER
17221                 (struct cmd_pctype_mapping_get_result,
17222                  show, "show");
17223 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17224         TOKEN_STRING_INITIALIZER
17225                 (struct cmd_pctype_mapping_get_result,
17226                  port, "port");
17227 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17228         TOKEN_NUM_INITIALIZER
17229                 (struct cmd_pctype_mapping_get_result,
17230                  port_id, UINT16);
17231 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17232         TOKEN_STRING_INITIALIZER
17233                 (struct cmd_pctype_mapping_get_result,
17234                  pctype, "pctype");
17235 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17236         TOKEN_STRING_INITIALIZER
17237                 (struct cmd_pctype_mapping_get_result,
17238                  mapping, "mapping");
17239
17240 static void
17241 cmd_pctype_mapping_get_parsed(
17242         void *parsed_result,
17243         __attribute__((unused)) struct cmdline *cl,
17244         __attribute__((unused)) void *data)
17245 {
17246         struct cmd_pctype_mapping_get_result *res = parsed_result;
17247         int ret = -ENOTSUP;
17248 #ifdef RTE_LIBRTE_I40E_PMD
17249         struct rte_pmd_i40e_flow_type_mapping
17250                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17251         int i, j, first_pctype;
17252 #endif
17253
17254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17255                 return;
17256
17257 #ifdef RTE_LIBRTE_I40E_PMD
17258         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17259 #endif
17260
17261         switch (ret) {
17262         case 0:
17263                 break;
17264         case -ENODEV:
17265                 printf("invalid port_id %d\n", res->port_id);
17266                 return;
17267         case -ENOTSUP:
17268                 printf("function not implemented\n");
17269                 return;
17270         default:
17271                 printf("programming error: (%s)\n", strerror(-ret));
17272                 return;
17273         }
17274
17275 #ifdef RTE_LIBRTE_I40E_PMD
17276         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17277                 if (mapping[i].pctype != 0ULL) {
17278                         first_pctype = 1;
17279
17280                         printf("pctype: ");
17281                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17282                                 if (mapping[i].pctype & (1ULL << j)) {
17283                                         printf(first_pctype ?
17284                                                "%02d" : ",%02d", j);
17285                                         first_pctype = 0;
17286                                 }
17287                         }
17288                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17289                 }
17290         }
17291 #endif
17292 }
17293
17294 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17295         .f = cmd_pctype_mapping_get_parsed,
17296         .data = NULL,
17297         .help_str = "show port <port_id> pctype mapping",
17298         .tokens = {
17299                 (void *)&cmd_pctype_mapping_get_show,
17300                 (void *)&cmd_pctype_mapping_get_port,
17301                 (void *)&cmd_pctype_mapping_get_port_id,
17302                 (void *)&cmd_pctype_mapping_get_pctype,
17303                 (void *)&cmd_pctype_mapping_get_mapping,
17304                 NULL,
17305         },
17306 };
17307
17308 /* port config pctype mapping update */
17309
17310 /* Common result structure for port config pctype mapping update */
17311 struct cmd_pctype_mapping_update_result {
17312         cmdline_fixed_string_t port;
17313         cmdline_fixed_string_t config;
17314         portid_t port_id;
17315         cmdline_fixed_string_t pctype;
17316         cmdline_fixed_string_t mapping;
17317         cmdline_fixed_string_t update;
17318         cmdline_fixed_string_t pctype_list;
17319         uint16_t flow_type;
17320 };
17321
17322 /* Common CLI fields for pctype mapping update*/
17323 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17324         TOKEN_STRING_INITIALIZER
17325                 (struct cmd_pctype_mapping_update_result,
17326                  port, "port");
17327 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17328         TOKEN_STRING_INITIALIZER
17329                 (struct cmd_pctype_mapping_update_result,
17330                  config, "config");
17331 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17332         TOKEN_NUM_INITIALIZER
17333                 (struct cmd_pctype_mapping_update_result,
17334                  port_id, UINT16);
17335 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17336         TOKEN_STRING_INITIALIZER
17337                 (struct cmd_pctype_mapping_update_result,
17338                  pctype, "pctype");
17339 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17340         TOKEN_STRING_INITIALIZER
17341                 (struct cmd_pctype_mapping_update_result,
17342                  mapping, "mapping");
17343 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17344         TOKEN_STRING_INITIALIZER
17345                 (struct cmd_pctype_mapping_update_result,
17346                  update, "update");
17347 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17348         TOKEN_STRING_INITIALIZER
17349                 (struct cmd_pctype_mapping_update_result,
17350                  pctype_list, NULL);
17351 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17352         TOKEN_NUM_INITIALIZER
17353                 (struct cmd_pctype_mapping_update_result,
17354                  flow_type, UINT16);
17355
17356 static void
17357 cmd_pctype_mapping_update_parsed(
17358         void *parsed_result,
17359         __attribute__((unused)) struct cmdline *cl,
17360         __attribute__((unused)) void *data)
17361 {
17362         struct cmd_pctype_mapping_update_result *res = parsed_result;
17363         int ret = -ENOTSUP;
17364 #ifdef RTE_LIBRTE_I40E_PMD
17365         struct rte_pmd_i40e_flow_type_mapping mapping;
17366         unsigned int i;
17367         unsigned int nb_item;
17368         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17369 #endif
17370
17371         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17372                 return;
17373
17374 #ifdef RTE_LIBRTE_I40E_PMD
17375         nb_item = parse_item_list(res->pctype_list, "pctypes",
17376                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17377         mapping.flow_type = res->flow_type;
17378         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17379                 mapping.pctype |= (1ULL << pctype_list[i]);
17380         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17381                                                 &mapping,
17382                                                 1,
17383                                                 0);
17384 #endif
17385
17386         switch (ret) {
17387         case 0:
17388                 break;
17389         case -EINVAL:
17390                 printf("invalid pctype or flow type\n");
17391                 break;
17392         case -ENODEV:
17393                 printf("invalid port_id %d\n", res->port_id);
17394                 break;
17395         case -ENOTSUP:
17396                 printf("function not implemented\n");
17397                 break;
17398         default:
17399                 printf("programming error: (%s)\n", strerror(-ret));
17400         }
17401 }
17402
17403 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17404         .f = cmd_pctype_mapping_update_parsed,
17405         .data = NULL,
17406         .help_str = "port config <port_id> pctype mapping update"
17407         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17408         .tokens = {
17409                 (void *)&cmd_pctype_mapping_update_port,
17410                 (void *)&cmd_pctype_mapping_update_config,
17411                 (void *)&cmd_pctype_mapping_update_port_id,
17412                 (void *)&cmd_pctype_mapping_update_pctype,
17413                 (void *)&cmd_pctype_mapping_update_mapping,
17414                 (void *)&cmd_pctype_mapping_update_update,
17415                 (void *)&cmd_pctype_mapping_update_pc_type,
17416                 (void *)&cmd_pctype_mapping_update_flow_type,
17417                 NULL,
17418         },
17419 };
17420
17421 /* ptype mapping get */
17422
17423 /* Common result structure for ptype mapping get */
17424 struct cmd_ptype_mapping_get_result {
17425         cmdline_fixed_string_t ptype;
17426         cmdline_fixed_string_t mapping;
17427         cmdline_fixed_string_t get;
17428         portid_t port_id;
17429         uint8_t valid_only;
17430 };
17431
17432 /* Common CLI fields for ptype mapping get */
17433 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17434         TOKEN_STRING_INITIALIZER
17435                 (struct cmd_ptype_mapping_get_result,
17436                  ptype, "ptype");
17437 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17438         TOKEN_STRING_INITIALIZER
17439                 (struct cmd_ptype_mapping_get_result,
17440                  mapping, "mapping");
17441 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17442         TOKEN_STRING_INITIALIZER
17443                 (struct cmd_ptype_mapping_get_result,
17444                  get, "get");
17445 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17446         TOKEN_NUM_INITIALIZER
17447                 (struct cmd_ptype_mapping_get_result,
17448                  port_id, UINT16);
17449 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17450         TOKEN_NUM_INITIALIZER
17451                 (struct cmd_ptype_mapping_get_result,
17452                  valid_only, UINT8);
17453
17454 static void
17455 cmd_ptype_mapping_get_parsed(
17456         void *parsed_result,
17457         __attribute__((unused)) struct cmdline *cl,
17458         __attribute__((unused)) void *data)
17459 {
17460         struct cmd_ptype_mapping_get_result *res = parsed_result;
17461         int ret = -ENOTSUP;
17462 #ifdef RTE_LIBRTE_I40E_PMD
17463         int max_ptype_num = 256;
17464         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17465         uint16_t count;
17466         int i;
17467 #endif
17468
17469         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17470                 return;
17471
17472 #ifdef RTE_LIBRTE_I40E_PMD
17473         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17474                                         mapping,
17475                                         max_ptype_num,
17476                                         &count,
17477                                         res->valid_only);
17478 #endif
17479
17480         switch (ret) {
17481         case 0:
17482                 break;
17483         case -ENODEV:
17484                 printf("invalid port_id %d\n", res->port_id);
17485                 break;
17486         case -ENOTSUP:
17487                 printf("function not implemented\n");
17488                 break;
17489         default:
17490                 printf("programming error: (%s)\n", strerror(-ret));
17491         }
17492
17493 #ifdef RTE_LIBRTE_I40E_PMD
17494         if (!ret) {
17495                 for (i = 0; i < count; i++)
17496                         printf("%3d\t0x%08x\n",
17497                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17498         }
17499 #endif
17500 }
17501
17502 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17503         .f = cmd_ptype_mapping_get_parsed,
17504         .data = NULL,
17505         .help_str = "ptype mapping get <port_id> <valid_only>",
17506         .tokens = {
17507                 (void *)&cmd_ptype_mapping_get_ptype,
17508                 (void *)&cmd_ptype_mapping_get_mapping,
17509                 (void *)&cmd_ptype_mapping_get_get,
17510                 (void *)&cmd_ptype_mapping_get_port_id,
17511                 (void *)&cmd_ptype_mapping_get_valid_only,
17512                 NULL,
17513         },
17514 };
17515
17516 /* ptype mapping replace */
17517
17518 /* Common result structure for ptype mapping replace */
17519 struct cmd_ptype_mapping_replace_result {
17520         cmdline_fixed_string_t ptype;
17521         cmdline_fixed_string_t mapping;
17522         cmdline_fixed_string_t replace;
17523         portid_t port_id;
17524         uint32_t target;
17525         uint8_t mask;
17526         uint32_t pkt_type;
17527 };
17528
17529 /* Common CLI fields for ptype mapping replace */
17530 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17531         TOKEN_STRING_INITIALIZER
17532                 (struct cmd_ptype_mapping_replace_result,
17533                  ptype, "ptype");
17534 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17535         TOKEN_STRING_INITIALIZER
17536                 (struct cmd_ptype_mapping_replace_result,
17537                  mapping, "mapping");
17538 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17539         TOKEN_STRING_INITIALIZER
17540                 (struct cmd_ptype_mapping_replace_result,
17541                  replace, "replace");
17542 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17543         TOKEN_NUM_INITIALIZER
17544                 (struct cmd_ptype_mapping_replace_result,
17545                  port_id, UINT16);
17546 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17547         TOKEN_NUM_INITIALIZER
17548                 (struct cmd_ptype_mapping_replace_result,
17549                  target, UINT32);
17550 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17551         TOKEN_NUM_INITIALIZER
17552                 (struct cmd_ptype_mapping_replace_result,
17553                  mask, UINT8);
17554 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17555         TOKEN_NUM_INITIALIZER
17556                 (struct cmd_ptype_mapping_replace_result,
17557                  pkt_type, UINT32);
17558
17559 static void
17560 cmd_ptype_mapping_replace_parsed(
17561         void *parsed_result,
17562         __attribute__((unused)) struct cmdline *cl,
17563         __attribute__((unused)) void *data)
17564 {
17565         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17566         int ret = -ENOTSUP;
17567
17568         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17569                 return;
17570
17571 #ifdef RTE_LIBRTE_I40E_PMD
17572         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17573                                         res->target,
17574                                         res->mask,
17575                                         res->pkt_type);
17576 #endif
17577
17578         switch (ret) {
17579         case 0:
17580                 break;
17581         case -EINVAL:
17582                 printf("invalid ptype 0x%8x or 0x%8x\n",
17583                                 res->target, res->pkt_type);
17584                 break;
17585         case -ENODEV:
17586                 printf("invalid port_id %d\n", res->port_id);
17587                 break;
17588         case -ENOTSUP:
17589                 printf("function not implemented\n");
17590                 break;
17591         default:
17592                 printf("programming error: (%s)\n", strerror(-ret));
17593         }
17594 }
17595
17596 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17597         .f = cmd_ptype_mapping_replace_parsed,
17598         .data = NULL,
17599         .help_str =
17600                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17601         .tokens = {
17602                 (void *)&cmd_ptype_mapping_replace_ptype,
17603                 (void *)&cmd_ptype_mapping_replace_mapping,
17604                 (void *)&cmd_ptype_mapping_replace_replace,
17605                 (void *)&cmd_ptype_mapping_replace_port_id,
17606                 (void *)&cmd_ptype_mapping_replace_target,
17607                 (void *)&cmd_ptype_mapping_replace_mask,
17608                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17609                 NULL,
17610         },
17611 };
17612
17613 /* ptype mapping reset */
17614
17615 /* Common result structure for ptype mapping reset */
17616 struct cmd_ptype_mapping_reset_result {
17617         cmdline_fixed_string_t ptype;
17618         cmdline_fixed_string_t mapping;
17619         cmdline_fixed_string_t reset;
17620         portid_t port_id;
17621 };
17622
17623 /* Common CLI fields for ptype mapping reset*/
17624 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17625         TOKEN_STRING_INITIALIZER
17626                 (struct cmd_ptype_mapping_reset_result,
17627                  ptype, "ptype");
17628 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17629         TOKEN_STRING_INITIALIZER
17630                 (struct cmd_ptype_mapping_reset_result,
17631                  mapping, "mapping");
17632 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17633         TOKEN_STRING_INITIALIZER
17634                 (struct cmd_ptype_mapping_reset_result,
17635                  reset, "reset");
17636 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17637         TOKEN_NUM_INITIALIZER
17638                 (struct cmd_ptype_mapping_reset_result,
17639                  port_id, UINT16);
17640
17641 static void
17642 cmd_ptype_mapping_reset_parsed(
17643         void *parsed_result,
17644         __attribute__((unused)) struct cmdline *cl,
17645         __attribute__((unused)) void *data)
17646 {
17647         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17648         int ret = -ENOTSUP;
17649
17650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17651                 return;
17652
17653 #ifdef RTE_LIBRTE_I40E_PMD
17654         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17655 #endif
17656
17657         switch (ret) {
17658         case 0:
17659                 break;
17660         case -ENODEV:
17661                 printf("invalid port_id %d\n", res->port_id);
17662                 break;
17663         case -ENOTSUP:
17664                 printf("function not implemented\n");
17665                 break;
17666         default:
17667                 printf("programming error: (%s)\n", strerror(-ret));
17668         }
17669 }
17670
17671 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17672         .f = cmd_ptype_mapping_reset_parsed,
17673         .data = NULL,
17674         .help_str = "ptype mapping reset <port_id>",
17675         .tokens = {
17676                 (void *)&cmd_ptype_mapping_reset_ptype,
17677                 (void *)&cmd_ptype_mapping_reset_mapping,
17678                 (void *)&cmd_ptype_mapping_reset_reset,
17679                 (void *)&cmd_ptype_mapping_reset_port_id,
17680                 NULL,
17681         },
17682 };
17683
17684 /* ptype mapping update */
17685
17686 /* Common result structure for ptype mapping update */
17687 struct cmd_ptype_mapping_update_result {
17688         cmdline_fixed_string_t ptype;
17689         cmdline_fixed_string_t mapping;
17690         cmdline_fixed_string_t reset;
17691         portid_t port_id;
17692         uint8_t hw_ptype;
17693         uint32_t sw_ptype;
17694 };
17695
17696 /* Common CLI fields for ptype mapping update*/
17697 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17698         TOKEN_STRING_INITIALIZER
17699                 (struct cmd_ptype_mapping_update_result,
17700                  ptype, "ptype");
17701 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17702         TOKEN_STRING_INITIALIZER
17703                 (struct cmd_ptype_mapping_update_result,
17704                  mapping, "mapping");
17705 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17706         TOKEN_STRING_INITIALIZER
17707                 (struct cmd_ptype_mapping_update_result,
17708                  reset, "update");
17709 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17710         TOKEN_NUM_INITIALIZER
17711                 (struct cmd_ptype_mapping_update_result,
17712                  port_id, UINT16);
17713 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17714         TOKEN_NUM_INITIALIZER
17715                 (struct cmd_ptype_mapping_update_result,
17716                  hw_ptype, UINT8);
17717 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17718         TOKEN_NUM_INITIALIZER
17719                 (struct cmd_ptype_mapping_update_result,
17720                  sw_ptype, UINT32);
17721
17722 static void
17723 cmd_ptype_mapping_update_parsed(
17724         void *parsed_result,
17725         __attribute__((unused)) struct cmdline *cl,
17726         __attribute__((unused)) void *data)
17727 {
17728         struct cmd_ptype_mapping_update_result *res = parsed_result;
17729         int ret = -ENOTSUP;
17730 #ifdef RTE_LIBRTE_I40E_PMD
17731         struct rte_pmd_i40e_ptype_mapping mapping;
17732 #endif
17733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17734                 return;
17735
17736 #ifdef RTE_LIBRTE_I40E_PMD
17737         mapping.hw_ptype = res->hw_ptype;
17738         mapping.sw_ptype = res->sw_ptype;
17739         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17740                                                 &mapping,
17741                                                 1,
17742                                                 0);
17743 #endif
17744
17745         switch (ret) {
17746         case 0:
17747                 break;
17748         case -EINVAL:
17749                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17750                 break;
17751         case -ENODEV:
17752                 printf("invalid port_id %d\n", res->port_id);
17753                 break;
17754         case -ENOTSUP:
17755                 printf("function not implemented\n");
17756                 break;
17757         default:
17758                 printf("programming error: (%s)\n", strerror(-ret));
17759         }
17760 }
17761
17762 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17763         .f = cmd_ptype_mapping_update_parsed,
17764         .data = NULL,
17765         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17766         .tokens = {
17767                 (void *)&cmd_ptype_mapping_update_ptype,
17768                 (void *)&cmd_ptype_mapping_update_mapping,
17769                 (void *)&cmd_ptype_mapping_update_update,
17770                 (void *)&cmd_ptype_mapping_update_port_id,
17771                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17772                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17773                 NULL,
17774         },
17775 };
17776
17777 /* Common result structure for file commands */
17778 struct cmd_cmdfile_result {
17779         cmdline_fixed_string_t load;
17780         cmdline_fixed_string_t filename;
17781 };
17782
17783 /* Common CLI fields for file commands */
17784 cmdline_parse_token_string_t cmd_load_cmdfile =
17785         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17786 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17787         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17788
17789 static void
17790 cmd_load_from_file_parsed(
17791         void *parsed_result,
17792         __attribute__((unused)) struct cmdline *cl,
17793         __attribute__((unused)) void *data)
17794 {
17795         struct cmd_cmdfile_result *res = parsed_result;
17796
17797         cmdline_read_from_file(res->filename);
17798 }
17799
17800 cmdline_parse_inst_t cmd_load_from_file = {
17801         .f = cmd_load_from_file_parsed,
17802         .data = NULL,
17803         .help_str = "load <filename>",
17804         .tokens = {
17805                 (void *)&cmd_load_cmdfile,
17806                 (void *)&cmd_load_cmdfile_filename,
17807                 NULL,
17808         },
17809 };
17810
17811 /* Get Rx offloads capabilities */
17812 struct cmd_rx_offload_get_capa_result {
17813         cmdline_fixed_string_t show;
17814         cmdline_fixed_string_t port;
17815         portid_t port_id;
17816         cmdline_fixed_string_t rx_offload;
17817         cmdline_fixed_string_t capabilities;
17818 };
17819
17820 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17821         TOKEN_STRING_INITIALIZER
17822                 (struct cmd_rx_offload_get_capa_result,
17823                  show, "show");
17824 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17825         TOKEN_STRING_INITIALIZER
17826                 (struct cmd_rx_offload_get_capa_result,
17827                  port, "port");
17828 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17829         TOKEN_NUM_INITIALIZER
17830                 (struct cmd_rx_offload_get_capa_result,
17831                  port_id, UINT16);
17832 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17833         TOKEN_STRING_INITIALIZER
17834                 (struct cmd_rx_offload_get_capa_result,
17835                  rx_offload, "rx_offload");
17836 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17837         TOKEN_STRING_INITIALIZER
17838                 (struct cmd_rx_offload_get_capa_result,
17839                  capabilities, "capabilities");
17840
17841 static void
17842 print_rx_offloads(uint64_t offloads)
17843 {
17844         uint64_t single_offload;
17845         int begin;
17846         int end;
17847         int bit;
17848
17849         if (offloads == 0)
17850                 return;
17851
17852         begin = __builtin_ctzll(offloads);
17853         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17854
17855         single_offload = 1ULL << begin;
17856         for (bit = begin; bit < end; bit++) {
17857                 if (offloads & single_offload)
17858                         printf(" %s",
17859                                rte_eth_dev_rx_offload_name(single_offload));
17860                 single_offload <<= 1;
17861         }
17862 }
17863
17864 static void
17865 cmd_rx_offload_get_capa_parsed(
17866         void *parsed_result,
17867         __attribute__((unused)) struct cmdline *cl,
17868         __attribute__((unused)) void *data)
17869 {
17870         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17871         struct rte_eth_dev_info dev_info;
17872         portid_t port_id = res->port_id;
17873         uint64_t queue_offloads;
17874         uint64_t port_offloads;
17875
17876         rte_eth_dev_info_get(port_id, &dev_info);
17877         queue_offloads = dev_info.rx_queue_offload_capa;
17878         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17879
17880         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17881         printf("  Per Queue :");
17882         print_rx_offloads(queue_offloads);
17883
17884         printf("\n");
17885         printf("  Per Port  :");
17886         print_rx_offloads(port_offloads);
17887         printf("\n\n");
17888 }
17889
17890 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17891         .f = cmd_rx_offload_get_capa_parsed,
17892         .data = NULL,
17893         .help_str = "show port <port_id> rx_offload capabilities",
17894         .tokens = {
17895                 (void *)&cmd_rx_offload_get_capa_show,
17896                 (void *)&cmd_rx_offload_get_capa_port,
17897                 (void *)&cmd_rx_offload_get_capa_port_id,
17898                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17899                 (void *)&cmd_rx_offload_get_capa_capabilities,
17900                 NULL,
17901         }
17902 };
17903
17904 /* Get Rx offloads configuration */
17905 struct cmd_rx_offload_get_configuration_result {
17906         cmdline_fixed_string_t show;
17907         cmdline_fixed_string_t port;
17908         portid_t port_id;
17909         cmdline_fixed_string_t rx_offload;
17910         cmdline_fixed_string_t configuration;
17911 };
17912
17913 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17914         TOKEN_STRING_INITIALIZER
17915                 (struct cmd_rx_offload_get_configuration_result,
17916                  show, "show");
17917 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17918         TOKEN_STRING_INITIALIZER
17919                 (struct cmd_rx_offload_get_configuration_result,
17920                  port, "port");
17921 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17922         TOKEN_NUM_INITIALIZER
17923                 (struct cmd_rx_offload_get_configuration_result,
17924                  port_id, UINT16);
17925 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17926         TOKEN_STRING_INITIALIZER
17927                 (struct cmd_rx_offload_get_configuration_result,
17928                  rx_offload, "rx_offload");
17929 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17930         TOKEN_STRING_INITIALIZER
17931                 (struct cmd_rx_offload_get_configuration_result,
17932                  configuration, "configuration");
17933
17934 static void
17935 cmd_rx_offload_get_configuration_parsed(
17936         void *parsed_result,
17937         __attribute__((unused)) struct cmdline *cl,
17938         __attribute__((unused)) void *data)
17939 {
17940         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17941         struct rte_eth_dev_info dev_info;
17942         portid_t port_id = res->port_id;
17943         struct rte_port *port = &ports[port_id];
17944         uint64_t port_offloads;
17945         uint64_t queue_offloads;
17946         uint16_t nb_rx_queues;
17947         int q;
17948
17949         printf("Rx Offloading Configuration of port %d :\n", port_id);
17950
17951         port_offloads = port->dev_conf.rxmode.offloads;
17952         printf("  Port :");
17953         print_rx_offloads(port_offloads);
17954         printf("\n");
17955
17956         rte_eth_dev_info_get(port_id, &dev_info);
17957         nb_rx_queues = dev_info.nb_rx_queues;
17958         for (q = 0; q < nb_rx_queues; q++) {
17959                 queue_offloads = port->rx_conf[q].offloads;
17960                 printf("  Queue[%2d] :", q);
17961                 print_rx_offloads(queue_offloads);
17962                 printf("\n");
17963         }
17964         printf("\n");
17965 }
17966
17967 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17968         .f = cmd_rx_offload_get_configuration_parsed,
17969         .data = NULL,
17970         .help_str = "show port <port_id> rx_offload configuration",
17971         .tokens = {
17972                 (void *)&cmd_rx_offload_get_configuration_show,
17973                 (void *)&cmd_rx_offload_get_configuration_port,
17974                 (void *)&cmd_rx_offload_get_configuration_port_id,
17975                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17976                 (void *)&cmd_rx_offload_get_configuration_configuration,
17977                 NULL,
17978         }
17979 };
17980
17981 /* Enable/Disable a per port offloading */
17982 struct cmd_config_per_port_rx_offload_result {
17983         cmdline_fixed_string_t port;
17984         cmdline_fixed_string_t config;
17985         portid_t port_id;
17986         cmdline_fixed_string_t rx_offload;
17987         cmdline_fixed_string_t offload;
17988         cmdline_fixed_string_t on_off;
17989 };
17990
17991 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17992         TOKEN_STRING_INITIALIZER
17993                 (struct cmd_config_per_port_rx_offload_result,
17994                  port, "port");
17995 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17996         TOKEN_STRING_INITIALIZER
17997                 (struct cmd_config_per_port_rx_offload_result,
17998                  config, "config");
17999 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18000         TOKEN_NUM_INITIALIZER
18001                 (struct cmd_config_per_port_rx_offload_result,
18002                  port_id, UINT16);
18003 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18004         TOKEN_STRING_INITIALIZER
18005                 (struct cmd_config_per_port_rx_offload_result,
18006                  rx_offload, "rx_offload");
18007 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18008         TOKEN_STRING_INITIALIZER
18009                 (struct cmd_config_per_port_rx_offload_result,
18010                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18011                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18012                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18013                            "crc_strip#scatter#timestamp#security#keep_crc");
18014 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18015         TOKEN_STRING_INITIALIZER
18016                 (struct cmd_config_per_port_rx_offload_result,
18017                  on_off, "on#off");
18018
18019 static uint64_t
18020 search_rx_offload(const char *name)
18021 {
18022         uint64_t single_offload;
18023         const char *single_name;
18024         int found = 0;
18025         unsigned int bit;
18026
18027         single_offload = 1;
18028         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18029                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18030                 if (!strcasecmp(single_name, name)) {
18031                         found = 1;
18032                         break;
18033                 }
18034                 single_offload <<= 1;
18035         }
18036
18037         if (found)
18038                 return single_offload;
18039
18040         return 0;
18041 }
18042
18043 static void
18044 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18045                                 __attribute__((unused)) struct cmdline *cl,
18046                                 __attribute__((unused)) void *data)
18047 {
18048         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18049         portid_t port_id = res->port_id;
18050         struct rte_eth_dev_info dev_info;
18051         struct rte_port *port = &ports[port_id];
18052         uint64_t single_offload;
18053         uint16_t nb_rx_queues;
18054         int q;
18055
18056         if (port->port_status != RTE_PORT_STOPPED) {
18057                 printf("Error: Can't config offload when Port %d "
18058                        "is not stopped\n", port_id);
18059                 return;
18060         }
18061
18062         single_offload = search_rx_offload(res->offload);
18063         if (single_offload == 0) {
18064                 printf("Unknown offload name: %s\n", res->offload);
18065                 return;
18066         }
18067
18068         rte_eth_dev_info_get(port_id, &dev_info);
18069         nb_rx_queues = dev_info.nb_rx_queues;
18070         if (!strcmp(res->on_off, "on")) {
18071                 port->dev_conf.rxmode.offloads |= single_offload;
18072                 for (q = 0; q < nb_rx_queues; q++)
18073                         port->rx_conf[q].offloads |= single_offload;
18074         } else {
18075                 port->dev_conf.rxmode.offloads &= ~single_offload;
18076                 for (q = 0; q < nb_rx_queues; q++)
18077                         port->rx_conf[q].offloads &= ~single_offload;
18078         }
18079
18080         cmd_reconfig_device_queue(port_id, 1, 1);
18081 }
18082
18083 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18084         .f = cmd_config_per_port_rx_offload_parsed,
18085         .data = NULL,
18086         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18087                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18088                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18089                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18090                     "on|off",
18091         .tokens = {
18092                 (void *)&cmd_config_per_port_rx_offload_result_port,
18093                 (void *)&cmd_config_per_port_rx_offload_result_config,
18094                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18095                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18096                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18097                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18098                 NULL,
18099         }
18100 };
18101
18102 /* Enable/Disable a per queue offloading */
18103 struct cmd_config_per_queue_rx_offload_result {
18104         cmdline_fixed_string_t port;
18105         portid_t port_id;
18106         cmdline_fixed_string_t rxq;
18107         uint16_t queue_id;
18108         cmdline_fixed_string_t rx_offload;
18109         cmdline_fixed_string_t offload;
18110         cmdline_fixed_string_t on_off;
18111 };
18112
18113 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18114         TOKEN_STRING_INITIALIZER
18115                 (struct cmd_config_per_queue_rx_offload_result,
18116                  port, "port");
18117 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18118         TOKEN_NUM_INITIALIZER
18119                 (struct cmd_config_per_queue_rx_offload_result,
18120                  port_id, UINT16);
18121 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18122         TOKEN_STRING_INITIALIZER
18123                 (struct cmd_config_per_queue_rx_offload_result,
18124                  rxq, "rxq");
18125 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18126         TOKEN_NUM_INITIALIZER
18127                 (struct cmd_config_per_queue_rx_offload_result,
18128                  queue_id, UINT16);
18129 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18130         TOKEN_STRING_INITIALIZER
18131                 (struct cmd_config_per_queue_rx_offload_result,
18132                  rx_offload, "rx_offload");
18133 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18134         TOKEN_STRING_INITIALIZER
18135                 (struct cmd_config_per_queue_rx_offload_result,
18136                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18137                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18138                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18139                            "crc_strip#scatter#timestamp#security#keep_crc");
18140 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18141         TOKEN_STRING_INITIALIZER
18142                 (struct cmd_config_per_queue_rx_offload_result,
18143                  on_off, "on#off");
18144
18145 static void
18146 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18147                                 __attribute__((unused)) struct cmdline *cl,
18148                                 __attribute__((unused)) void *data)
18149 {
18150         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18151         struct rte_eth_dev_info dev_info;
18152         portid_t port_id = res->port_id;
18153         uint16_t queue_id = res->queue_id;
18154         struct rte_port *port = &ports[port_id];
18155         uint64_t single_offload;
18156
18157         if (port->port_status != RTE_PORT_STOPPED) {
18158                 printf("Error: Can't config offload when Port %d "
18159                        "is not stopped\n", port_id);
18160                 return;
18161         }
18162
18163         rte_eth_dev_info_get(port_id, &dev_info);
18164         if (queue_id >= dev_info.nb_rx_queues) {
18165                 printf("Error: input queue_id should be 0 ... "
18166                        "%d\n", dev_info.nb_rx_queues - 1);
18167                 return;
18168         }
18169
18170         single_offload = search_rx_offload(res->offload);
18171         if (single_offload == 0) {
18172                 printf("Unknown offload name: %s\n", res->offload);
18173                 return;
18174         }
18175
18176         if (!strcmp(res->on_off, "on"))
18177                 port->rx_conf[queue_id].offloads |= single_offload;
18178         else
18179                 port->rx_conf[queue_id].offloads &= ~single_offload;
18180
18181         cmd_reconfig_device_queue(port_id, 1, 1);
18182 }
18183
18184 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18185         .f = cmd_config_per_queue_rx_offload_parsed,
18186         .data = NULL,
18187         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18188                     "vlan_strip|ipv4_cksum|"
18189                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18190                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18191                     "jumbo_frame|crc_strip|scatter|timestamp|security|keep_crc "
18192                     "on|off",
18193         .tokens = {
18194                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18195                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18196                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18197                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18198                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18199                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18200                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18201                 NULL,
18202         }
18203 };
18204
18205 /* Get Tx offloads capabilities */
18206 struct cmd_tx_offload_get_capa_result {
18207         cmdline_fixed_string_t show;
18208         cmdline_fixed_string_t port;
18209         portid_t port_id;
18210         cmdline_fixed_string_t tx_offload;
18211         cmdline_fixed_string_t capabilities;
18212 };
18213
18214 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18215         TOKEN_STRING_INITIALIZER
18216                 (struct cmd_tx_offload_get_capa_result,
18217                  show, "show");
18218 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18219         TOKEN_STRING_INITIALIZER
18220                 (struct cmd_tx_offload_get_capa_result,
18221                  port, "port");
18222 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18223         TOKEN_NUM_INITIALIZER
18224                 (struct cmd_tx_offload_get_capa_result,
18225                  port_id, UINT16);
18226 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18227         TOKEN_STRING_INITIALIZER
18228                 (struct cmd_tx_offload_get_capa_result,
18229                  tx_offload, "tx_offload");
18230 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18231         TOKEN_STRING_INITIALIZER
18232                 (struct cmd_tx_offload_get_capa_result,
18233                  capabilities, "capabilities");
18234
18235 static void
18236 print_tx_offloads(uint64_t offloads)
18237 {
18238         uint64_t single_offload;
18239         int begin;
18240         int end;
18241         int bit;
18242
18243         if (offloads == 0)
18244                 return;
18245
18246         begin = __builtin_ctzll(offloads);
18247         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18248
18249         single_offload = 1ULL << begin;
18250         for (bit = begin; bit < end; bit++) {
18251                 if (offloads & single_offload)
18252                         printf(" %s",
18253                                rte_eth_dev_tx_offload_name(single_offload));
18254                 single_offload <<= 1;
18255         }
18256 }
18257
18258 static void
18259 cmd_tx_offload_get_capa_parsed(
18260         void *parsed_result,
18261         __attribute__((unused)) struct cmdline *cl,
18262         __attribute__((unused)) void *data)
18263 {
18264         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18265         struct rte_eth_dev_info dev_info;
18266         portid_t port_id = res->port_id;
18267         uint64_t queue_offloads;
18268         uint64_t port_offloads;
18269
18270         rte_eth_dev_info_get(port_id, &dev_info);
18271         queue_offloads = dev_info.tx_queue_offload_capa;
18272         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18273
18274         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18275         printf("  Per Queue :");
18276         print_tx_offloads(queue_offloads);
18277
18278         printf("\n");
18279         printf("  Per Port  :");
18280         print_tx_offloads(port_offloads);
18281         printf("\n\n");
18282 }
18283
18284 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18285         .f = cmd_tx_offload_get_capa_parsed,
18286         .data = NULL,
18287         .help_str = "show port <port_id> tx_offload capabilities",
18288         .tokens = {
18289                 (void *)&cmd_tx_offload_get_capa_show,
18290                 (void *)&cmd_tx_offload_get_capa_port,
18291                 (void *)&cmd_tx_offload_get_capa_port_id,
18292                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18293                 (void *)&cmd_tx_offload_get_capa_capabilities,
18294                 NULL,
18295         }
18296 };
18297
18298 /* Get Tx offloads configuration */
18299 struct cmd_tx_offload_get_configuration_result {
18300         cmdline_fixed_string_t show;
18301         cmdline_fixed_string_t port;
18302         portid_t port_id;
18303         cmdline_fixed_string_t tx_offload;
18304         cmdline_fixed_string_t configuration;
18305 };
18306
18307 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18308         TOKEN_STRING_INITIALIZER
18309                 (struct cmd_tx_offload_get_configuration_result,
18310                  show, "show");
18311 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18312         TOKEN_STRING_INITIALIZER
18313                 (struct cmd_tx_offload_get_configuration_result,
18314                  port, "port");
18315 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18316         TOKEN_NUM_INITIALIZER
18317                 (struct cmd_tx_offload_get_configuration_result,
18318                  port_id, UINT16);
18319 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18320         TOKEN_STRING_INITIALIZER
18321                 (struct cmd_tx_offload_get_configuration_result,
18322                  tx_offload, "tx_offload");
18323 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18324         TOKEN_STRING_INITIALIZER
18325                 (struct cmd_tx_offload_get_configuration_result,
18326                  configuration, "configuration");
18327
18328 static void
18329 cmd_tx_offload_get_configuration_parsed(
18330         void *parsed_result,
18331         __attribute__((unused)) struct cmdline *cl,
18332         __attribute__((unused)) void *data)
18333 {
18334         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18335         struct rte_eth_dev_info dev_info;
18336         portid_t port_id = res->port_id;
18337         struct rte_port *port = &ports[port_id];
18338         uint64_t port_offloads;
18339         uint64_t queue_offloads;
18340         uint16_t nb_tx_queues;
18341         int q;
18342
18343         printf("Tx Offloading Configuration of port %d :\n", port_id);
18344
18345         port_offloads = port->dev_conf.txmode.offloads;
18346         printf("  Port :");
18347         print_tx_offloads(port_offloads);
18348         printf("\n");
18349
18350         rte_eth_dev_info_get(port_id, &dev_info);
18351         nb_tx_queues = dev_info.nb_tx_queues;
18352         for (q = 0; q < nb_tx_queues; q++) {
18353                 queue_offloads = port->tx_conf[q].offloads;
18354                 printf("  Queue[%2d] :", q);
18355                 print_tx_offloads(queue_offloads);
18356                 printf("\n");
18357         }
18358         printf("\n");
18359 }
18360
18361 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18362         .f = cmd_tx_offload_get_configuration_parsed,
18363         .data = NULL,
18364         .help_str = "show port <port_id> tx_offload configuration",
18365         .tokens = {
18366                 (void *)&cmd_tx_offload_get_configuration_show,
18367                 (void *)&cmd_tx_offload_get_configuration_port,
18368                 (void *)&cmd_tx_offload_get_configuration_port_id,
18369                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18370                 (void *)&cmd_tx_offload_get_configuration_configuration,
18371                 NULL,
18372         }
18373 };
18374
18375 /* Enable/Disable a per port offloading */
18376 struct cmd_config_per_port_tx_offload_result {
18377         cmdline_fixed_string_t port;
18378         cmdline_fixed_string_t config;
18379         portid_t port_id;
18380         cmdline_fixed_string_t tx_offload;
18381         cmdline_fixed_string_t offload;
18382         cmdline_fixed_string_t on_off;
18383 };
18384
18385 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18386         TOKEN_STRING_INITIALIZER
18387                 (struct cmd_config_per_port_tx_offload_result,
18388                  port, "port");
18389 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18390         TOKEN_STRING_INITIALIZER
18391                 (struct cmd_config_per_port_tx_offload_result,
18392                  config, "config");
18393 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18394         TOKEN_NUM_INITIALIZER
18395                 (struct cmd_config_per_port_tx_offload_result,
18396                  port_id, UINT16);
18397 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18398         TOKEN_STRING_INITIALIZER
18399                 (struct cmd_config_per_port_tx_offload_result,
18400                  tx_offload, "tx_offload");
18401 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18402         TOKEN_STRING_INITIALIZER
18403                 (struct cmd_config_per_port_tx_offload_result,
18404                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18405                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18406                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18407                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18408                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18409                           "match_metadata");
18410 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18411         TOKEN_STRING_INITIALIZER
18412                 (struct cmd_config_per_port_tx_offload_result,
18413                  on_off, "on#off");
18414
18415 static uint64_t
18416 search_tx_offload(const char *name)
18417 {
18418         uint64_t single_offload;
18419         const char *single_name;
18420         int found = 0;
18421         unsigned int bit;
18422
18423         single_offload = 1;
18424         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18425                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18426                 if (single_name == NULL)
18427                         break;
18428                 if (!strcasecmp(single_name, name)) {
18429                         found = 1;
18430                         break;
18431                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18432                         break;
18433                 single_offload <<= 1;
18434         }
18435
18436         if (found)
18437                 return single_offload;
18438
18439         return 0;
18440 }
18441
18442 static void
18443 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18444                                 __attribute__((unused)) struct cmdline *cl,
18445                                 __attribute__((unused)) void *data)
18446 {
18447         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18448         portid_t port_id = res->port_id;
18449         struct rte_eth_dev_info dev_info;
18450         struct rte_port *port = &ports[port_id];
18451         uint64_t single_offload;
18452         uint16_t nb_tx_queues;
18453         int q;
18454
18455         if (port->port_status != RTE_PORT_STOPPED) {
18456                 printf("Error: Can't config offload when Port %d "
18457                        "is not stopped\n", port_id);
18458                 return;
18459         }
18460
18461         single_offload = search_tx_offload(res->offload);
18462         if (single_offload == 0) {
18463                 printf("Unknown offload name: %s\n", res->offload);
18464                 return;
18465         }
18466
18467         rte_eth_dev_info_get(port_id, &dev_info);
18468         nb_tx_queues = dev_info.nb_tx_queues;
18469         if (!strcmp(res->on_off, "on")) {
18470                 port->dev_conf.txmode.offloads |= single_offload;
18471                 for (q = 0; q < nb_tx_queues; q++)
18472                         port->tx_conf[q].offloads |= single_offload;
18473         } else {
18474                 port->dev_conf.txmode.offloads &= ~single_offload;
18475                 for (q = 0; q < nb_tx_queues; q++)
18476                         port->tx_conf[q].offloads &= ~single_offload;
18477         }
18478
18479         cmd_reconfig_device_queue(port_id, 1, 1);
18480 }
18481
18482 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18483         .f = cmd_config_per_port_tx_offload_parsed,
18484         .data = NULL,
18485         .help_str = "port config <port_id> tx_offload "
18486                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18487                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18488                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18489                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18490                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18491                     "match_metadata on|off",
18492         .tokens = {
18493                 (void *)&cmd_config_per_port_tx_offload_result_port,
18494                 (void *)&cmd_config_per_port_tx_offload_result_config,
18495                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18496                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18497                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18498                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18499                 NULL,
18500         }
18501 };
18502
18503 /* Enable/Disable a per queue offloading */
18504 struct cmd_config_per_queue_tx_offload_result {
18505         cmdline_fixed_string_t port;
18506         portid_t port_id;
18507         cmdline_fixed_string_t txq;
18508         uint16_t queue_id;
18509         cmdline_fixed_string_t tx_offload;
18510         cmdline_fixed_string_t offload;
18511         cmdline_fixed_string_t on_off;
18512 };
18513
18514 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18515         TOKEN_STRING_INITIALIZER
18516                 (struct cmd_config_per_queue_tx_offload_result,
18517                  port, "port");
18518 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18519         TOKEN_NUM_INITIALIZER
18520                 (struct cmd_config_per_queue_tx_offload_result,
18521                  port_id, UINT16);
18522 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18523         TOKEN_STRING_INITIALIZER
18524                 (struct cmd_config_per_queue_tx_offload_result,
18525                  txq, "txq");
18526 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18527         TOKEN_NUM_INITIALIZER
18528                 (struct cmd_config_per_queue_tx_offload_result,
18529                  queue_id, UINT16);
18530 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18531         TOKEN_STRING_INITIALIZER
18532                 (struct cmd_config_per_queue_tx_offload_result,
18533                  tx_offload, "tx_offload");
18534 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18535         TOKEN_STRING_INITIALIZER
18536                 (struct cmd_config_per_queue_tx_offload_result,
18537                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18538                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18539                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18540                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18541                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18542 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18543         TOKEN_STRING_INITIALIZER
18544                 (struct cmd_config_per_queue_tx_offload_result,
18545                  on_off, "on#off");
18546
18547 static void
18548 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18549                                 __attribute__((unused)) struct cmdline *cl,
18550                                 __attribute__((unused)) void *data)
18551 {
18552         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18553         struct rte_eth_dev_info dev_info;
18554         portid_t port_id = res->port_id;
18555         uint16_t queue_id = res->queue_id;
18556         struct rte_port *port = &ports[port_id];
18557         uint64_t single_offload;
18558
18559         if (port->port_status != RTE_PORT_STOPPED) {
18560                 printf("Error: Can't config offload when Port %d "
18561                        "is not stopped\n", port_id);
18562                 return;
18563         }
18564
18565         rte_eth_dev_info_get(port_id, &dev_info);
18566         if (queue_id >= dev_info.nb_tx_queues) {
18567                 printf("Error: input queue_id should be 0 ... "
18568                        "%d\n", dev_info.nb_tx_queues - 1);
18569                 return;
18570         }
18571
18572         single_offload = search_tx_offload(res->offload);
18573         if (single_offload == 0) {
18574                 printf("Unknown offload name: %s\n", res->offload);
18575                 return;
18576         }
18577
18578         if (!strcmp(res->on_off, "on"))
18579                 port->tx_conf[queue_id].offloads |= single_offload;
18580         else
18581                 port->tx_conf[queue_id].offloads &= ~single_offload;
18582
18583         cmd_reconfig_device_queue(port_id, 1, 1);
18584 }
18585
18586 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18587         .f = cmd_config_per_queue_tx_offload_parsed,
18588         .data = NULL,
18589         .help_str = "port <port_id> txq <queue_id> tx_offload "
18590                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18591                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18592                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18593                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18594                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18595                     "on|off",
18596         .tokens = {
18597                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18598                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18599                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18600                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18601                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18602                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18603                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18604                 NULL,
18605         }
18606 };
18607
18608 /* *** configure tx_metadata for specific port *** */
18609 struct cmd_config_tx_metadata_specific_result {
18610         cmdline_fixed_string_t port;
18611         cmdline_fixed_string_t keyword;
18612         uint16_t port_id;
18613         cmdline_fixed_string_t item;
18614         uint32_t value;
18615 };
18616
18617 static void
18618 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18619                                 __attribute__((unused)) struct cmdline *cl,
18620                                 __attribute__((unused)) void *data)
18621 {
18622         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18623
18624         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18625                 return;
18626         ports[res->port_id].tx_metadata = rte_cpu_to_be_32(res->value);
18627         /* Add/remove callback to insert valid metadata in every Tx packet. */
18628         if (ports[res->port_id].tx_metadata)
18629                 add_tx_md_callback(res->port_id);
18630         else
18631                 remove_tx_md_callback(res->port_id);
18632 }
18633
18634 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18635         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18636                         port, "port");
18637 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18638         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18639                         keyword, "config");
18640 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18641         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18642                         port_id, UINT16);
18643 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18644         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18645                         item, "tx_metadata");
18646 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18647         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18648                         value, UINT32);
18649
18650 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18651         .f = cmd_config_tx_metadata_specific_parsed,
18652         .data = NULL,
18653         .help_str = "port config <port_id> tx_metadata <value>",
18654         .tokens = {
18655                 (void *)&cmd_config_tx_metadata_specific_port,
18656                 (void *)&cmd_config_tx_metadata_specific_keyword,
18657                 (void *)&cmd_config_tx_metadata_specific_id,
18658                 (void *)&cmd_config_tx_metadata_specific_item,
18659                 (void *)&cmd_config_tx_metadata_specific_value,
18660                 NULL,
18661         },
18662 };
18663
18664 /* *** display tx_metadata per port configuration *** */
18665 struct cmd_show_tx_metadata_result {
18666         cmdline_fixed_string_t cmd_show;
18667         cmdline_fixed_string_t cmd_port;
18668         cmdline_fixed_string_t cmd_keyword;
18669         portid_t cmd_pid;
18670 };
18671
18672 static void
18673 cmd_show_tx_metadata_parsed(void *parsed_result,
18674                 __attribute__((unused)) struct cmdline *cl,
18675                 __attribute__((unused)) void *data)
18676 {
18677         struct cmd_show_tx_metadata_result *res = parsed_result;
18678
18679         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18680                 printf("invalid port id %u\n", res->cmd_pid);
18681                 return;
18682         }
18683         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18684                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18685                         rte_be_to_cpu_32(ports[res->cmd_pid].tx_metadata));
18686         }
18687 }
18688
18689 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18690         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18691                         cmd_show, "show");
18692 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18693         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18694                         cmd_port, "port");
18695 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18696         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18697                         cmd_pid, UINT16);
18698 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18699         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18700                         cmd_keyword, "tx_metadata");
18701
18702 cmdline_parse_inst_t cmd_show_tx_metadata = {
18703         .f = cmd_show_tx_metadata_parsed,
18704         .data = NULL,
18705         .help_str = "show port <port_id> tx_metadata",
18706         .tokens = {
18707                 (void *)&cmd_show_tx_metadata_show,
18708                 (void *)&cmd_show_tx_metadata_port,
18709                 (void *)&cmd_show_tx_metadata_pid,
18710                 (void *)&cmd_show_tx_metadata_keyword,
18711                 NULL,
18712         },
18713 };
18714
18715 /* ******************************************************************************** */
18716
18717 /* list of instructions */
18718 cmdline_parse_ctx_t main_ctx[] = {
18719         (cmdline_parse_inst_t *)&cmd_help_brief,
18720         (cmdline_parse_inst_t *)&cmd_help_long,
18721         (cmdline_parse_inst_t *)&cmd_quit,
18722         (cmdline_parse_inst_t *)&cmd_load_from_file,
18723         (cmdline_parse_inst_t *)&cmd_showport,
18724         (cmdline_parse_inst_t *)&cmd_showqueue,
18725         (cmdline_parse_inst_t *)&cmd_showportall,
18726         (cmdline_parse_inst_t *)&cmd_showcfg,
18727         (cmdline_parse_inst_t *)&cmd_showfwdall,
18728         (cmdline_parse_inst_t *)&cmd_start,
18729         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18730         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18731         (cmdline_parse_inst_t *)&cmd_set_link_up,
18732         (cmdline_parse_inst_t *)&cmd_set_link_down,
18733         (cmdline_parse_inst_t *)&cmd_reset,
18734         (cmdline_parse_inst_t *)&cmd_set_numbers,
18735         (cmdline_parse_inst_t *)&cmd_set_log,
18736         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18737         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18738         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18739         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18740         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18741         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18742         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18743         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18744         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18745         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18746         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18747         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18748         (cmdline_parse_inst_t *)&cmd_set_link_check,
18749         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18750         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18751         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18752         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18753 #ifdef RTE_LIBRTE_PMD_BOND
18754         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18755         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18756         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18757         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18758         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18759         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18760         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18761         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18762         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18763         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18764         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18765 #endif
18766         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18767         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18768         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18769         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18770         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18771         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18772         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18773         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18774         (cmdline_parse_inst_t *)&cmd_csum_set,
18775         (cmdline_parse_inst_t *)&cmd_csum_show,
18776         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18777         (cmdline_parse_inst_t *)&cmd_tso_set,
18778         (cmdline_parse_inst_t *)&cmd_tso_show,
18779         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18780         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18781         (cmdline_parse_inst_t *)&cmd_gro_enable,
18782         (cmdline_parse_inst_t *)&cmd_gro_flush,
18783         (cmdline_parse_inst_t *)&cmd_gro_show,
18784         (cmdline_parse_inst_t *)&cmd_gso_enable,
18785         (cmdline_parse_inst_t *)&cmd_gso_size,
18786         (cmdline_parse_inst_t *)&cmd_gso_show,
18787         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18788         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18789         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18790         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18791         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18792         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18793         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18794         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18795         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18796         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18797         (cmdline_parse_inst_t *)&cmd_config_dcb,
18798         (cmdline_parse_inst_t *)&cmd_read_reg,
18799         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18800         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18801         (cmdline_parse_inst_t *)&cmd_write_reg,
18802         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18803         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18804         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18805         (cmdline_parse_inst_t *)&cmd_stop,
18806         (cmdline_parse_inst_t *)&cmd_mac_addr,
18807         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18808         (cmdline_parse_inst_t *)&cmd_set_qmap,
18809         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18810         (cmdline_parse_inst_t *)&cmd_operate_port,
18811         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18812         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18813         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18814         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18815         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18816         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18817         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18818         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18819         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18820         (cmdline_parse_inst_t *)&cmd_config_mtu,
18821         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18822         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18823         (cmdline_parse_inst_t *)&cmd_config_rss,
18824         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18825         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18826         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18827         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18828         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18829         (cmdline_parse_inst_t *)&cmd_showport_reta,
18830         (cmdline_parse_inst_t *)&cmd_config_burst,
18831         (cmdline_parse_inst_t *)&cmd_config_thresh,
18832         (cmdline_parse_inst_t *)&cmd_config_threshold,
18833         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18834         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18835         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18836         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
18837         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18838         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
18839         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18840         (cmdline_parse_inst_t *)&cmd_global_config,
18841         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18842         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18843         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18844         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18845         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18846         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18847         (cmdline_parse_inst_t *)&cmd_dump,
18848         (cmdline_parse_inst_t *)&cmd_dump_one,
18849         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
18850         (cmdline_parse_inst_t *)&cmd_syn_filter,
18851         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
18852         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
18853         (cmdline_parse_inst_t *)&cmd_flex_filter,
18854         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18855         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18856         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18857         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18858         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18859         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18860         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18861         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18862         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18863         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18864         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18865         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18866         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18867         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
18868         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
18869         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
18870         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
18871         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
18872         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18873         (cmdline_parse_inst_t *)&cmd_flow,
18874         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18875         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18876         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18877         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18878         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18879         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18880         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18881         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18882         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18883         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18884         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18885         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18886         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18887         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18888         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18889         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18890         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18891         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18892         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18893         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18894         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18895         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18896         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18897         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18898         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18899         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18900         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18901         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18902         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18903         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18904         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18905         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18906         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18907         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18908         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18909         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18910         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18911         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18912         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18913         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18914         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18915         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18916         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18917         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18918         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18919         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18920         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18921         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18922         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18923 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
18924         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
18925 #endif
18926         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18927         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18928         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18929         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18930         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18931         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18932         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18933         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18934         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18935         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18936         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18937         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18938         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18939         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18940         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18941         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18942         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18943         (cmdline_parse_inst_t *)&cmd_ddp_add,
18944         (cmdline_parse_inst_t *)&cmd_ddp_del,
18945         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18946         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18947         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18948         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18949         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18950         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18951         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18952         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18953         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18954         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18955
18956         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18957         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18958         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18959         (cmdline_parse_inst_t *)&cmd_queue_region,
18960         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18961         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18962         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18963         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18964         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18965         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18966         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18967         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18968         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18969         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18970         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18971         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18972         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18973         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18974         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18975         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18976         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18977         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18978         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18979         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18980         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18981         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18982         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18983         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18984         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18985         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18986         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18987         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18988         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18989         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18990         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18991         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18992         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18993         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18994         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18995 #ifdef RTE_LIBRTE_BPF
18996         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18997         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18998 #endif
18999         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19000         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19001         NULL,
19002 };
19003
19004 /* read cmdline commands from file */
19005 void
19006 cmdline_read_from_file(const char *filename)
19007 {
19008         struct cmdline *cl;
19009
19010         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19011         if (cl == NULL) {
19012                 printf("Failed to create file based cmdline context: %s\n",
19013                        filename);
19014                 return;
19015         }
19016
19017         cmdline_interact(cl);
19018         cmdline_quit(cl);
19019
19020         cmdline_free(cl);
19021
19022         printf("Read CLI commands from %s\n", filename);
19023 }
19024
19025 /* prompt function, called from main on MASTER lcore */
19026 void
19027 prompt(void)
19028 {
19029         /* initialize non-constant commands */
19030         cmd_set_fwd_mode_init();
19031         cmd_set_fwd_retry_mode_init();
19032
19033         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19034         if (testpmd_cl == NULL)
19035                 return;
19036         cmdline_interact(testpmd_cl);
19037         cmdline_stdin_exit(testpmd_cl);
19038 }
19039
19040 void
19041 prompt_exit(void)
19042 {
19043         if (testpmd_cl != NULL)
19044                 cmdline_quit(testpmd_cl);
19045 }
19046
19047 static void
19048 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19049 {
19050         if (id == (portid_t)RTE_PORT_ALL) {
19051                 portid_t pid;
19052
19053                 RTE_ETH_FOREACH_DEV(pid) {
19054                         /* check if need_reconfig has been set to 1 */
19055                         if (ports[pid].need_reconfig == 0)
19056                                 ports[pid].need_reconfig = dev;
19057                         /* check if need_reconfig_queues has been set to 1 */
19058                         if (ports[pid].need_reconfig_queues == 0)
19059                                 ports[pid].need_reconfig_queues = queue;
19060                 }
19061         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19062                 /* check if need_reconfig has been set to 1 */
19063                 if (ports[id].need_reconfig == 0)
19064                         ports[id].need_reconfig = dev;
19065                 /* check if need_reconfig_queues has been set to 1 */
19066                 if (ports[id].need_reconfig_queues == 0)
19067                         ports[id].need_reconfig_queues = queue;
19068         }
19069 }