39ad938384cbc3fcf4e210628e438f47cdbb7a5e
[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 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port X rss reta (size) (mask0,mask1,...)\n"
170                         "    Display the rss redirection table entry indicated"
171                         " by masks on port X. size is used to indicate the"
172                         " hardware supported reta size\n\n"
173
174                         "show port (port_id) rss-hash [key]\n"
175                         "    Display the RSS hash functions and RSS hash key of port\n\n"
176
177                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178                         "    Clear information for port_id, or all.\n\n"
179
180                         "show (rxq|txq) info (port_id) (queue_id)\n"
181                         "    Display information for configured RX/TX queue.\n\n"
182
183                         "show config (rxtx|cores|fwd|txpkts)\n"
184                         "    Display the given configuration.\n\n"
185
186                         "read rxd (port_id) (queue_id) (rxd_id)\n"
187                         "    Display an RX descriptor of a port RX queue.\n\n"
188
189                         "read txd (port_id) (queue_id) (txd_id)\n"
190                         "    Display a TX descriptor of a port TX queue.\n\n"
191
192                         "ddp get list (port_id)\n"
193                         "    Get ddp profile info list\n\n"
194
195                         "ddp get info (profile_path)\n"
196                         "    Get ddp profile information.\n\n"
197
198                         "show vf stats (port_id) (vf_id)\n"
199                         "    Display a VF's statistics.\n\n"
200
201                         "clear vf stats (port_id) (vf_id)\n"
202                         "    Reset a VF's statistics.\n\n"
203
204                         "show port (port_id) pctype mapping\n"
205                         "    Get flow ptype to pctype mapping on a port\n\n"
206
207                         "show port meter stats (port_id) (meter_id) (clear)\n"
208                         "    Get meter stats on a port\n\n"
209
210                         "show fwd stats all\n"
211                         "    Display statistics for all fwd engines.\n\n"
212
213                         "clear fwd stats all\n"
214                         "    Clear statistics for all fwd engines.\n\n"
215
216                         "show port (port_id) rx_offload capabilities\n"
217                         "    List all per queue and per port Rx offloading"
218                         " capabilities of a port\n\n"
219
220                         "show port (port_id) rx_offload configuration\n"
221                         "    List port level and all queue level"
222                         " Rx offloading configuration\n\n"
223
224                         "show port (port_id) tx_offload capabilities\n"
225                         "    List all per queue and per port"
226                         " Tx offloading capabilities of a port\n\n"
227
228                         "show port (port_id) tx_offload configuration\n"
229                         "    List port level and all queue level"
230                         " Tx offloading configuration\n\n"
231
232                         "show port (port_id) tx_metadata\n"
233                         "    Show Tx metadata value set"
234                         " for a specific port\n\n"
235
236                         "show port (port_id) ptypes\n"
237                         "    Show port supported ptypes"
238                         " for a specific port\n\n"
239
240                         "show device info (<identifier>|all)"
241                         "       Show general information about devices probed.\n\n"
242
243                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244                         "       Show status of rx|tx descriptor.\n\n"
245
246                         "show port (port_id) macs|mcast_macs"
247                         "       Display list of mac addresses added to port.\n\n"
248                 );
249         }
250
251         if (show_all || !strcmp(res->section, "config")) {
252                 cmdline_printf(
253                         cl,
254                         "\n"
255                         "Configuration:\n"
256                         "--------------\n"
257                         "Configuration changes only become active when"
258                         " forwarding is started/restarted.\n\n"
259
260                         "set default\n"
261                         "    Reset forwarding to the default configuration.\n\n"
262
263                         "set verbose (level)\n"
264                         "    Set the debug verbosity level X.\n\n"
265
266                         "set log global|(type) (level)\n"
267                         "    Set the log level.\n\n"
268
269                         "set nbport (num)\n"
270                         "    Set number of ports.\n\n"
271
272                         "set nbcore (num)\n"
273                         "    Set number of cores.\n\n"
274
275                         "set coremask (mask)\n"
276                         "    Set the forwarding cores hexadecimal mask.\n\n"
277
278                         "set portmask (mask)\n"
279                         "    Set the forwarding ports hexadecimal mask.\n\n"
280
281                         "set burst (num)\n"
282                         "    Set number of packets per burst.\n\n"
283
284                         "set burst tx delay (microseconds) retry (num)\n"
285                         "    Set the transmit delay time and number of retries,"
286                         " effective when retry is enabled.\n\n"
287
288                         "set txpkts (x[,y]*)\n"
289                         "    Set the length of each segment of TXONLY"
290                         " and optionally CSUM packets.\n\n"
291
292                         "set txsplit (off|on|rand)\n"
293                         "    Set the split policy for the TX packets."
294                         " Right now only applicable for CSUM and TXONLY"
295                         " modes\n\n"
296
297                         "set corelist (x[,y]*)\n"
298                         "    Set the list of forwarding cores.\n\n"
299
300                         "set portlist (x[,y]*)\n"
301                         "    Set the list of forwarding ports.\n\n"
302
303                         "set port setup on (iterator|event)\n"
304                         "    Select how attached port is retrieved for setup.\n\n"
305
306                         "set tx loopback (port_id) (on|off)\n"
307                         "    Enable or disable tx loopback.\n\n"
308
309                         "set all queues drop (port_id) (on|off)\n"
310                         "    Set drop enable bit for all queues.\n\n"
311
312                         "set vf split drop (port_id) (vf_id) (on|off)\n"
313                         "    Set split drop enable bit for a VF from the PF.\n\n"
314
315                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316                         "    Set MAC antispoof for a VF from the PF.\n\n"
317
318                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319                         "    Enable MACsec offload.\n\n"
320
321                         "set macsec offload (port_id) off\n"
322                         "    Disable MACsec offload.\n\n"
323
324                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325                         "    Configure MACsec secure connection (SC).\n\n"
326
327                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328                         "    Configure MACsec secure association (SA).\n\n"
329
330                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
331                         "    Set VF broadcast for a VF from the PF.\n\n"
332
333                         "vlan set stripq (on|off) (port_id,queue_id)\n"
334                         "    Set the VLAN strip for a queue on a port.\n\n"
335
336                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338
339                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340                         "    Set VLAN insert for a VF from the PF.\n\n"
341
342                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343                         "    Set VLAN antispoof for a VF from the PF.\n\n"
344
345                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
346                         "    Set VLAN tag for a VF from the PF.\n\n"
347
348                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349                         "    Set a VF's max bandwidth(Mbps).\n\n"
350
351                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353
354                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356
357                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
358                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
359
360                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362
363                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
365
366                         "vlan set (inner|outer) tpid (value) (port_id)\n"
367                         "    Set the VLAN TPID for Packet Filtering on"
368                         " a port\n\n"
369
370                         "rx_vlan add (vlan_id|all) (port_id)\n"
371                         "    Add a vlan_id, or all identifiers, to the set"
372                         " of VLAN identifiers filtered by port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id|all) (port_id)\n"
375                         "    Remove a vlan_id, or all identifiers, from the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379                         "    Add a vlan_id, to the set of VLAN identifiers"
380                         "filtered for VF(s) from port_id.\n\n"
381
382                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Remove a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   add a tunnel filter of a port.\n\n"
390
391                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394                         "   remove a tunnel filter of a port.\n\n"
395
396                         "rx_vxlan_port add (udp_port) (port_id)\n"
397                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
398
399                         "rx_vxlan_port rm (udp_port) (port_id)\n"
400                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
401
402                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
404                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405
406                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
407                         "    Set port based TX VLAN insertion.\n\n"
408
409                         "tx_vlan reset (port_id)\n"
410                         "    Disable hardware insertion of a VLAN header in"
411                         " packets sent on a port.\n\n"
412
413                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414                         "    Select hardware or software calculation of the"
415                         " checksum when transmitting a packet using the"
416                         " csum forward engine.\n"
417                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
418                         "    outer-ip concerns the outer IP layer in"
419                         "    outer-udp concerns the outer UDP layer in"
420                         " case the packet is recognized as a tunnel packet by"
421                         " the forward engine (vxlan, gre and ipip are supported)\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "csum parse-tunnel (on|off) (tx_port_id)\n"
425                         "    If disabled, treat tunnel packets as non-tunneled"
426                         " packets (treat inner headers as payload). The port\n"
427                         "    argument is the port used for TX in csum forward"
428                         " engine.\n\n"
429
430                         "csum show (port_id)\n"
431                         "    Display tx checksum offload configuration\n\n"
432
433                         "tso set (segsize) (portid)\n"
434                         "    Enable TCP Segmentation Offload in csum forward"
435                         " engine.\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "tso show (portid)"
439                         "    Display the status of TCP Segmentation Offload.\n\n"
440
441                         "set port (port_id) gro on|off\n"
442                         "    Enable or disable Generic Receive Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "show port (port_id) gro\n"
446                         "    Display GRO configuration.\n\n"
447
448                         "set gro flush (cycles)\n"
449                         "    Set the cycle to flush GROed packets from"
450                         " reassembly tables.\n\n"
451
452                         "set port (port_id) gso (on|off)"
453                         "    Enable or disable Generic Segmentation Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "set gso segsz (length)\n"
457                         "    Set max packet length for output GSO segments,"
458                         " including packet header and payload.\n\n"
459
460                         "show port (port_id) gso\n"
461                         "    Show GSO configuration.\n\n"
462
463                         "set fwd (%s)\n"
464                         "    Set packet forwarding mode.\n\n"
465
466                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467                         "    Add a MAC address on port_id.\n\n"
468
469                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470                         "    Remove a MAC address from port_id.\n\n"
471
472                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473                         "    Set the default MAC address for port_id.\n\n"
474
475                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476                         "    Add a MAC address for a VF on the port.\n\n"
477
478                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479                         "    Set the MAC address for a VF from the PF.\n\n"
480
481                         "set eth-peer (port_id) (peer_addr)\n"
482                         "    set the peer address for certain port.\n\n"
483
484                         "set port (port_id) uta (mac_address|all) (on|off)\n"
485                         "    Add/Remove a or all unicast hash filter(s)"
486                         "from port X.\n\n"
487
488                         "set promisc (port_id|all) (on|off)\n"
489                         "    Set the promiscuous mode on port_id, or all.\n\n"
490
491                         "set allmulti (port_id|all) (on|off)\n"
492                         "    Set the allmulti mode on port_id, or all.\n\n"
493
494                         "set vf promisc (port_id) (vf_id) (on|off)\n"
495                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
496
497                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
498                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
499
500                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502                         " (on|off) autoneg (on|off) (port_id)\n"
503                         "set flow_ctrl rx (on|off) (portid)\n"
504                         "set flow_ctrl tx (on|off) (portid)\n"
505                         "set flow_ctrl high_water (high_water) (portid)\n"
506                         "set flow_ctrl low_water (low_water) (portid)\n"
507                         "set flow_ctrl pause_time (pause_time) (portid)\n"
508                         "set flow_ctrl send_xon (send_xon) (portid)\n"
509                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510                         "set flow_ctrl autoneg (on|off) (port_id)\n"
511                         "    Set the link flow control parameter on a port.\n\n"
512
513                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (priority) (port_id)\n"
515                         "    Set the priority flow control parameter on a"
516                         " port.\n\n"
517
518                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
520                         " queue on port.\n"
521                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522                         " on port 0 to mapping 5.\n\n"
523
524                         "set xstats-hide-zero on|off\n"
525                         "    Set the option to hide the zero values"
526                         " for xstats display.\n"
527
528                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
529                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
530
531                         "set port (port_id) vf (vf_id) (mac_addr)"
532                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533                         "   Add/Remove unicast or multicast MAC addr filter"
534                         " for a VF.\n\n"
535
536                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537                         "|MPE) (on|off)\n"
538                         "    AUPE:accepts untagged VLAN;"
539                         "ROPE:accept unicast hash\n\n"
540                         "    BAM:accepts broadcast packets;"
541                         "MPE:accepts all multicast packets\n\n"
542                         "    Enable/Disable a VF receive mode of a port\n\n"
543
544                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
545                         "    Set rate limit for a queue of a port\n\n"
546
547                         "set port (port_id) vf (vf_id) rate (rate_num) "
548                         "queue_mask (queue_mask_value)\n"
549                         "    Set rate limit for queues in VF of a port\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554                         "   Set pool or vlan type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
557                         " to pool 0.\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (uplink-mirror|downlink-mirror) dst-pool"
561                         " (pool_id) (on|off)\n"
562                         "   Set uplink or downlink type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564                         " 0 on' enable mirror income traffic to pool 0.\n\n"
565
566                         "reset port (port_id) mirror-rule (rule_id)\n"
567                         "   Reset a mirror rule.\n\n"
568
569                         "set flush_rx (on|off)\n"
570                         "   Flush (default) or don't flush RX streams before"
571                         " forwarding. Mainly used with PCAP drivers.\n\n"
572
573                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the bypass mode for the lowest port on bypass enabled"
575                         " NIC.\n\n"
576
577                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
578                         "mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the event required to initiate specified bypass mode for"
580                         " the lowest port on a bypass enabled NIC where:\n"
581                         "       timeout   = enable bypass after watchdog timeout.\n"
582                         "       os_on     = enable bypass when OS/board is powered on.\n"
583                         "       os_off    = enable bypass when OS/board is powered off.\n"
584                         "       power_on  = enable bypass when power supply is turned on.\n"
585                         "       power_off = enable bypass when power supply is turned off."
586                         "\n\n"
587
588                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589                         "   Set the bypass watchdog timeout to 'n' seconds"
590                         " where 0 = instant.\n\n"
591
592                         "show bypass config (port_id)\n"
593                         "   Show the bypass configuration for a bypass enabled NIC"
594                         " using the lowest port on the NIC.\n\n"
595
596 #ifdef RTE_LIBRTE_PMD_BOND
597                         "create bonded device (mode) (socket)\n"
598                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
599
600                         "add bonding slave (slave_id) (port_id)\n"
601                         "       Add a slave device to a bonded device.\n\n"
602
603                         "remove bonding slave (slave_id) (port_id)\n"
604                         "       Remove a slave device from a bonded device.\n\n"
605
606                         "set bonding mode (value) (port_id)\n"
607                         "       Set the bonding mode on a bonded device.\n\n"
608
609                         "set bonding primary (slave_id) (port_id)\n"
610                         "       Set the primary slave for a bonded device.\n\n"
611
612                         "show bonding config (port_id)\n"
613                         "       Show the bonding config for port_id.\n\n"
614
615                         "set bonding mac_addr (port_id) (address)\n"
616                         "       Set the MAC address of a bonded device.\n\n"
617
618                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
620
621                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
623
624                         "set bonding mon_period (port_id) (value)\n"
625                         "       Set the bonding link status monitoring polling period in ms.\n\n"
626
627                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
629
630 #endif
631                         "set link-up port (port_id)\n"
632                         "       Set link up for a port.\n\n"
633
634                         "set link-down port (port_id)\n"
635                         "       Set link down for a port.\n\n"
636
637                         "E-tag set insertion on port-tag-id (value)"
638                         " port (port_id) vf (vf_id)\n"
639                         "    Enable E-tag insertion for a VF on a port\n\n"
640
641                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
642                         "    Disable E-tag insertion for a VF on a port\n\n"
643
644                         "E-tag set stripping (on|off) port (port_id)\n"
645                         "    Enable/disable E-tag stripping on a port\n\n"
646
647                         "E-tag set forwarding (on|off) port (port_id)\n"
648                         "    Enable/disable E-tag based forwarding"
649                         " on a port\n\n"
650
651                         "E-tag set filter add e-tag-id (value) dst-pool"
652                         " (pool_id) port (port_id)\n"
653                         "    Add an E-tag forwarding filter on a port\n\n"
654
655                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
656                         "    Delete an E-tag forwarding filter on a port\n\n"
657
658                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
659                         "    Load a profile package on a port\n\n"
660
661                         "ddp del (port_id) (backup_profile_path)\n"
662                         "    Delete a profile package from a port\n\n"
663
664                         "ptype mapping get (port_id) (valid_only)\n"
665                         "    Get ptype mapping on a port\n\n"
666
667                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668                         "    Replace target with the pkt_type in ptype mapping\n\n"
669
670                         "ptype mapping reset (port_id)\n"
671                         "    Reset ptype mapping on a port\n\n"
672
673                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674                         "    Update a ptype mapping item on a port\n\n"
675
676                         "set port (port_id) ptype_mask (ptype_mask)\n"
677                         "    set packet types classification for a specific port\n\n"
678
679                         "set port (port_id) queue-region region_id (value) "
680                         "queue_start_index (value) queue_num (value)\n"
681                         "    Set a queue region on a port\n\n"
682
683                         "set port (port_id) queue-region region_id (value) "
684                         "flowtype (value)\n"
685                         "    Set a flowtype region index on a port\n\n"
686
687                         "set port (port_id) queue-region UP (value) region_id (value)\n"
688                         "    Set the mapping of User Priority to "
689                         "queue region on a port\n\n"
690
691                         "set port (port_id) queue-region flush (on|off)\n"
692                         "    flush all queue region related configuration\n\n"
693
694                         "show port meter cap (port_id)\n"
695                         "    Show port meter capability information\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712                         "(dscp_tbl_entry63)]\n"
713                         "    meter create\n\n"
714
715                         "enable port meter (port_id) (mtr_id)\n"
716                         "    meter enable\n\n"
717
718                         "disable port meter (port_id) (mtr_id)\n"
719                         "    meter disable\n\n"
720
721                         "del port meter (port_id) (mtr_id)\n"
722                         "    meter delete\n\n"
723
724                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
725                         "    meter update meter profile\n\n"
726
727                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729                         "    update meter dscp table entries\n\n"
730
731                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732                         "(action0) [(action1) (action2)]\n"
733                         "    meter update policer action\n\n"
734
735                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736                         "    meter update stats\n\n"
737
738                         "show port (port_id) queue-region\n"
739                         "    show all queue region related configuration info\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
773                         " duplex (half|full|auto)\n"
774                         "    Set speed and duplex for all ports or port_id\n\n"
775
776                         "port config (port_id|all) loopback (mode)\n"
777                         "    Set loopback mode for all ports or port_id\n\n"
778
779                         "port config all (rxq|txq|rxd|txd) (value)\n"
780                         "    Set number for rxq/txq/rxd/txd.\n\n"
781
782                         "port config all max-pkt-len (value)\n"
783                         "    Set the max packet length.\n\n"
784
785                         "port config all max-lro-pkt-size (value)\n"
786                         "    Set the max LRO aggregated packet size.\n\n"
787
788                         "port config all drop-en (on|off)\n"
789                         "    Enable or disable packet drop on all RX queues of all ports when no "
790                         "receive buffers available.\n\n"
791
792                         "port config all rss (all|default|ip|tcp|udp|sctp|"
793                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794                         "    Set the RSS mode.\n\n"
795
796                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797                         "    Set the RSS redirection table.\n\n"
798
799                         "port config (port_id) dcb vt (on|off) (traffic_class)"
800                         " pfc (on|off)\n"
801                         "    Set the DCB mode.\n\n"
802
803                         "port config all burst (value)\n"
804                         "    Set the number of packets per burst.\n\n"
805
806                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807                         " (value)\n"
808                         "    Set the ring prefetch/host/writeback threshold"
809                         " for tx/rx queue.\n\n"
810
811                         "port config all (txfreet|txrst|rxfreet) (value)\n"
812                         "    Set free threshold for rx/tx, or set"
813                         " tx rs bit threshold.\n\n"
814                         "port config mtu X value\n"
815                         "    Set the MTU of port X to a given value\n\n"
816
817                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818                         "    Set a rx/tx queue's ring size configuration, the new"
819                         " value will take effect after command that (re-)start the port"
820                         " or command that setup the specific queue\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823                         "    Start/stop a rx/tx queue of port X. Only take effect"
824                         " when port X is started\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
828                         " take effect when port X is stopped.\n\n"
829
830                         "port (port_id) (rxq|txq) (queue_id) setup\n"
831                         "    Setup a rx/tx queue of port X.\n\n"
832
833                         "port config (port_id|all) l2-tunnel E-tag ether-type"
834                         " (value)\n"
835                         "    Set the value of E-tag ether-type.\n\n"
836
837                         "port config (port_id|all) l2-tunnel E-tag"
838                         " (enable|disable)\n"
839                         "    Enable/disable the E-tag support.\n\n"
840
841                         "port config (port_id) pctype mapping reset\n"
842                         "    Reset flow type to pctype mapping on a port\n\n"
843
844                         "port config (port_id) pctype mapping update"
845                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846                         "    Update a flow type to pctype mapping item on a port\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
850                         " (field_idx)\n"
851                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852
853                         "port config (port_id) pctype (pctype_id) hash_inset|"
854                         "fdir_inset|fdir_flx_inset clear all"
855                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856
857                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
859
860                         "port config <port_id> rx_offload vlan_strip|"
861                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862                         "outer_ipv4_cksum|macsec_strip|header_split|"
863                         "vlan_filter|vlan_extend|jumbo_frame|"
864                         "scatter|timestamp|security|keep_crc on|off\n"
865                         "     Enable or disable a per port Rx offloading"
866                         " on all Rx queues of a port\n\n"
867
868                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|"
872                         "scatter|timestamp|security|keep_crc on|off\n"
873                         "    Enable or disable a per queue Rx offloading"
874                         " only on a specific Rx queue\n\n"
875
876                         "port config (port_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881                         "security on|off\n"
882                         "    Enable or disable a per port Tx offloading"
883                         " on all Tx queues of a port\n\n"
884
885                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
886                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
890                         " on|off\n"
891                         "    Enable or disable a per queue Tx offloading"
892                         " only on a specific Tx queue\n\n"
893
894                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895                         "    Load an eBPF program as a callback"
896                         " for particular RX/TX queue\n\n"
897
898                         "bpf-unload rx|tx (port) (queue)\n"
899                         "    Unload previously loaded eBPF program"
900                         " for particular RX/TX queue\n\n"
901
902                         "port config (port_id) tx_metadata (value)\n"
903                         "    Set Tx metadata value per port. Testpmd will add this value"
904                         " to any Tx packet sent from this port\n\n"
905
906                         "port config (port_id) dynf (name) set|clear\n"
907                         "    Register a dynf and Set/clear this flag on Tx. "
908                         "Testpmd will set this value to any Tx packet "
909                         "sent from this port\n\n"
910                 );
911         }
912
913         if (show_all || !strcmp(res->section, "registers")) {
914
915                 cmdline_printf(
916                         cl,
917                         "\n"
918                         "Registers:\n"
919                         "----------\n\n"
920
921                         "read reg (port_id) (address)\n"
922                         "    Display value of a port register.\n\n"
923
924                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
925                         "    Display a port register bit field.\n\n"
926
927                         "read regbit (port_id) (address) (bit_x)\n"
928                         "    Display a single port register bit.\n\n"
929
930                         "write reg (port_id) (address) (value)\n"
931                         "    Set value of a port register.\n\n"
932
933                         "write regfield (port_id) (address) (bit_x) (bit_y)"
934                         " (value)\n"
935                         "    Set bit field of a port register.\n\n"
936
937                         "write regbit (port_id) (address) (bit_x) (value)\n"
938                         "    Set single bit value of a port register.\n\n"
939                 );
940         }
941         if (show_all || !strcmp(res->section, "filters")) {
942
943                 cmdline_printf(
944                         cl,
945                         "\n"
946                         "filters:\n"
947                         "--------\n\n"
948
949                         "ethertype_filter (port_id) (add|del)"
950                         " (mac_addr|mac_ignr) (mac_address) ethertype"
951                         " (ether_type) (drop|fwd) queue (queue_id)\n"
952                         "    Add/Del an ethertype filter.\n\n"
953
954                         "2tuple_filter (port_id) (add|del)"
955                         " dst_port (dst_port_value) protocol (protocol_value)"
956                         " mask (mask_value) tcp_flags (tcp_flags_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a 2tuple filter.\n\n"
959
960                         "5tuple_filter (port_id) (add|del)"
961                         " dst_ip (dst_address) src_ip (src_address)"
962                         " dst_port (dst_port_value) src_port (src_port_value)"
963                         " protocol (protocol_value)"
964                         " mask (mask_value) tcp_flags (tcp_flags_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a 5tuple filter.\n\n"
967
968                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969                         "    Add/Del syn filter.\n\n"
970
971                         "flex_filter (port_id) (add|del) len (len_value)"
972                         " bytes (bytes_value) mask (mask_value)"
973                         " priority (prio_value) queue (queue_id)\n"
974                         "    Add/Del a flex filter.\n\n"
975
976                         "flow_director_filter (port_id) mode IP (add|del|update)"
977                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978                         " src (src_ip_address) dst (dst_ip_address)"
979                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
980                         " vlan (vlan_value) flexbytes (flexbytes_value)"
981                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982                         " fd_id (fd_id_value)\n"
983                         "    Add/Del an IP type flow director filter.\n\n"
984
985                         "flow_director_filter (port_id) mode IP (add|del|update)"
986                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987                         " src (src_ip_address) (src_port)"
988                         " dst (dst_ip_address) (dst_port)"
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value) flexbytes (flexbytes_value)"
991                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992                         " fd_id (fd_id_value)\n"
993                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-sctp|ipv6-sctp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tag (verification_tag) "
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a SCTP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow l2_payload ether (ethertype)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a l2 payload type flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013                         " mac (mac_address) vlan (vlan_value)"
1014                         " flexbytes (flexbytes_value) (drop|fwd)"
1015                         " queue (queue_id) fd_id (fd_id_value)\n"
1016                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019                         " mac (mac_address) vlan (vlan_value)"
1020                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a Tunnel flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode raw (add|del|update)"
1026                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1027                         " fd_id (fd_id_value) packet (packet file name)\n"
1028                         "    Add/Del a raw type flow director filter.\n\n"
1029
1030                         "flush_flow_director (port_id)\n"
1031                         "    Flush all flow director entries of a device.\n\n"
1032
1033                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1035                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036                         "    Set flow director IP mask.\n\n"
1037
1038                         "flow_director_mask (port_id) mode MAC-VLAN"
1039                         " vlan (vlan_value)\n"
1040                         "    Set flow director MAC-VLAN mask.\n\n"
1041
1042                         "flow_director_mask (port_id) mode Tunnel"
1043                         " vlan (vlan_value) mac (mac_value)"
1044                         " tunnel-type (tunnel_type_value)"
1045                         " tunnel-id (tunnel_id_value)\n"
1046                         "    Set flow director Tunnel mask.\n\n"
1047
1048                         "flow_director_flex_mask (port_id)"
1049                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051                         " (mask)\n"
1052                         "    Configure mask of flex payload.\n\n"
1053
1054                         "flow_director_flex_payload (port_id)"
1055                         " (raw|l2|l3|l4) (config)\n"
1056                         "    Configure flex payload selection.\n\n"
1057
1058                         "get_sym_hash_ena_per_port (port_id)\n"
1059                         "    get symmetric hash enable configuration per port.\n\n"
1060
1061                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062                         "    set symmetric hash enable configuration per port"
1063                         " to enable or disable.\n\n"
1064
1065                         "get_hash_global_config (port_id)\n"
1066                         "    Get the global configurations of hash filters.\n\n"
1067
1068                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071                         " (enable|disable)\n"
1072                         "    Set the global configurations of hash filters.\n\n"
1073
1074                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1080                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1081                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083                         "fld-8th|none) (select|add)\n"
1084                         "    Set the input set for hash.\n\n"
1085
1086                         "set_fdir_input_set (port_id) "
1087                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1093                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094                         " (select|add)\n"
1095                         "    Set the input set for FDir.\n\n"
1096
1097                         "flow validate {port_id}"
1098                         " [group {group_id}] [priority {level}]"
1099                         " [ingress] [egress]"
1100                         " pattern {item} [/ {item} [...]] / end"
1101                         " actions {action} [/ {action} [...]] / end\n"
1102                         "    Check whether a flow rule can be created.\n\n"
1103
1104                         "flow create {port_id}"
1105                         " [group {group_id}] [priority {level}]"
1106                         " [ingress] [egress]"
1107                         " pattern {item} [/ {item} [...]] / end"
1108                         " actions {action} [/ {action} [...]] / end\n"
1109                         "    Create a flow rule.\n\n"
1110
1111                         "flow destroy {port_id} rule {rule_id} [...]\n"
1112                         "    Destroy specific flow rules.\n\n"
1113
1114                         "flow flush {port_id}\n"
1115                         "    Destroy all flow rules.\n\n"
1116
1117                         "flow query {port_id} {rule_id} {action}\n"
1118                         "    Query an existing flow rule.\n\n"
1119
1120                         "flow list {port_id} [group {group_id}] [...]\n"
1121                         "    List existing flow rules sorted by priority,"
1122                         " filtered by group identifiers.\n\n"
1123
1124                         "flow isolate {port_id} {boolean}\n"
1125                         "    Restrict ingress traffic to the defined"
1126                         " flow rules\n\n"
1127
1128                         "flow aged {port_id} [destroy]\n"
1129                         "    List and destroy aged flows"
1130                         " flow rules\n\n"
1131
1132                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1133                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1134                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1135                         "       Configure the VXLAN encapsulation for flows.\n\n"
1136
1137                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1138                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1139                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1140                         " eth-dst (eth-dst)\n"
1141                         "       Configure the VXLAN encapsulation for flows.\n\n"
1142
1143                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1144                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1145                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1146                         " eth-dst (eth-dst)\n"
1147                         "       Configure the VXLAN encapsulation for flows.\n\n"
1148
1149                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1150                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1151                         " (eth-dst)\n"
1152                         "       Configure the NVGRE encapsulation for flows.\n\n"
1153
1154                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1155                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1156                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1157                         "       Configure the NVGRE encapsulation for flows.\n\n"
1158
1159                         "set raw_encap {flow items}\n"
1160                         "       Configure the encapsulation with raw data.\n\n"
1161
1162                         "set raw_decap {flow items}\n"
1163                         "       Configure the decapsulation with raw data.\n\n"
1164
1165                 );
1166         }
1167
1168         if (show_all || !strcmp(res->section, "traffic_management")) {
1169                 cmdline_printf(
1170                         cl,
1171                         "\n"
1172                         "Traffic Management:\n"
1173                         "--------------\n"
1174                         "show port tm cap (port_id)\n"
1175                         "       Display the port TM capability.\n\n"
1176
1177                         "show port tm level cap (port_id) (level_id)\n"
1178                         "       Display the port TM hierarchical level capability.\n\n"
1179
1180                         "show port tm node cap (port_id) (node_id)\n"
1181                         "       Display the port TM node capability.\n\n"
1182
1183                         "show port tm node type (port_id) (node_id)\n"
1184                         "       Display the port TM node type.\n\n"
1185
1186                         "show port tm node stats (port_id) (node_id) (clear)\n"
1187                         "       Display the port TM node stats.\n\n"
1188
1189 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1190                         "set port tm hierarchy default (port_id)\n"
1191                         "       Set default traffic Management hierarchy on a port\n\n"
1192 #endif
1193
1194                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1195                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1196                         " (packet_length_adjust)\n"
1197                         "       Add port tm node private shaper profile.\n\n"
1198
1199                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1200                         "       Delete port tm node private shaper profile.\n\n"
1201
1202                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1203                         " (shaper_profile_id)\n"
1204                         "       Add/update port tm node shared shaper.\n\n"
1205
1206                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1207                         "       Delete port tm node shared shaper.\n\n"
1208
1209                         "set port tm node shaper profile (port_id) (node_id)"
1210                         " (shaper_profile_id)\n"
1211                         "       Set port tm node shaper profile.\n\n"
1212
1213                         "add port tm node wred profile (port_id) (wred_profile_id)"
1214                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1215                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1216                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1217                         "       Add port tm node wred profile.\n\n"
1218
1219                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1220                         "       Delete port tm node wred profile.\n\n"
1221
1222                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1223                         " (priority) (weight) (level_id) (shaper_profile_id)"
1224                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1225                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1226                         "       Add port tm nonleaf node.\n\n"
1227
1228                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1229                         " (priority) (weight) (level_id) (shaper_profile_id)"
1230                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1231                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1232                         "       Add port tm leaf node.\n\n"
1233
1234                         "del port tm node (port_id) (node_id)\n"
1235                         "       Delete port tm node.\n\n"
1236
1237                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1238                         " (priority) (weight)\n"
1239                         "       Set port tm node parent.\n\n"
1240
1241                         "suspend port tm node (port_id) (node_id)"
1242                         "       Suspend tm node.\n\n"
1243
1244                         "resume port tm node (port_id) (node_id)"
1245                         "       Resume tm node.\n\n"
1246
1247                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1248                         "       Commit tm hierarchy.\n\n"
1249
1250                         "set port tm mark ip_ecn (port) (green) (yellow)"
1251                         " (red)\n"
1252                         "    Enables/Disables the traffic management marking"
1253                         " for IP ECN (Explicit Congestion Notification)"
1254                         " packets on a given port\n\n"
1255
1256                         "set port tm mark ip_dscp (port) (green) (yellow)"
1257                         " (red)\n"
1258                         "    Enables/Disables the traffic management marking"
1259                         " on the port for IP dscp packets\n\n"
1260
1261                         "set port tm mark vlan_dei (port) (green) (yellow)"
1262                         " (red)\n"
1263                         "    Enables/Disables the traffic management marking"
1264                         " on the port for VLAN packets with DEI enabled\n\n"
1265                 );
1266         }
1267
1268         if (show_all || !strcmp(res->section, "devices")) {
1269                 cmdline_printf(
1270                         cl,
1271                         "\n"
1272                         "Device Operations:\n"
1273                         "--------------\n"
1274                         "device detach (identifier)\n"
1275                         "       Detach device by identifier.\n\n"
1276                 );
1277         }
1278
1279 }
1280
1281 cmdline_parse_token_string_t cmd_help_long_help =
1282         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1283
1284 cmdline_parse_token_string_t cmd_help_long_section =
1285         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1286                         "all#control#display#config#"
1287                         "ports#registers#filters#traffic_management#devices");
1288
1289 cmdline_parse_inst_t cmd_help_long = {
1290         .f = cmd_help_long_parsed,
1291         .data = NULL,
1292         .help_str = "help all|control|display|config|ports|register|"
1293                 "filters|traffic_management|devices: "
1294                 "Show help",
1295         .tokens = {
1296                 (void *)&cmd_help_long_help,
1297                 (void *)&cmd_help_long_section,
1298                 NULL,
1299         },
1300 };
1301
1302
1303 /* *** start/stop/close all ports *** */
1304 struct cmd_operate_port_result {
1305         cmdline_fixed_string_t keyword;
1306         cmdline_fixed_string_t name;
1307         cmdline_fixed_string_t value;
1308 };
1309
1310 static void cmd_operate_port_parsed(void *parsed_result,
1311                                 __rte_unused struct cmdline *cl,
1312                                 __rte_unused void *data)
1313 {
1314         struct cmd_operate_port_result *res = parsed_result;
1315
1316         if (!strcmp(res->name, "start"))
1317                 start_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "stop"))
1319                 stop_port(RTE_PORT_ALL);
1320         else if (!strcmp(res->name, "close"))
1321                 close_port(RTE_PORT_ALL);
1322         else if (!strcmp(res->name, "reset"))
1323                 reset_port(RTE_PORT_ALL);
1324         else
1325                 printf("Unknown parameter\n");
1326 }
1327
1328 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1329         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1330                                                                 "port");
1331 cmdline_parse_token_string_t cmd_operate_port_all_port =
1332         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1333                                                 "start#stop#close#reset");
1334 cmdline_parse_token_string_t cmd_operate_port_all_all =
1335         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1336
1337 cmdline_parse_inst_t cmd_operate_port = {
1338         .f = cmd_operate_port_parsed,
1339         .data = NULL,
1340         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1341         .tokens = {
1342                 (void *)&cmd_operate_port_all_cmd,
1343                 (void *)&cmd_operate_port_all_port,
1344                 (void *)&cmd_operate_port_all_all,
1345                 NULL,
1346         },
1347 };
1348
1349 /* *** start/stop/close specific port *** */
1350 struct cmd_operate_specific_port_result {
1351         cmdline_fixed_string_t keyword;
1352         cmdline_fixed_string_t name;
1353         uint8_t value;
1354 };
1355
1356 static void cmd_operate_specific_port_parsed(void *parsed_result,
1357                         __rte_unused struct cmdline *cl,
1358                                 __rte_unused void *data)
1359 {
1360         struct cmd_operate_specific_port_result *res = parsed_result;
1361
1362         if (!strcmp(res->name, "start"))
1363                 start_port(res->value);
1364         else if (!strcmp(res->name, "stop"))
1365                 stop_port(res->value);
1366         else if (!strcmp(res->name, "close"))
1367                 close_port(res->value);
1368         else if (!strcmp(res->name, "reset"))
1369                 reset_port(res->value);
1370         else
1371                 printf("Unknown parameter\n");
1372 }
1373
1374 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1375         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1376                                                         keyword, "port");
1377 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1378         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1379                                                 name, "start#stop#close#reset");
1380 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1381         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1382                                                         value, UINT8);
1383
1384 cmdline_parse_inst_t cmd_operate_specific_port = {
1385         .f = cmd_operate_specific_port_parsed,
1386         .data = NULL,
1387         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1388         .tokens = {
1389                 (void *)&cmd_operate_specific_port_cmd,
1390                 (void *)&cmd_operate_specific_port_port,
1391                 (void *)&cmd_operate_specific_port_id,
1392                 NULL,
1393         },
1394 };
1395
1396 /* *** enable port setup (after attach) via iterator or event *** */
1397 struct cmd_set_port_setup_on_result {
1398         cmdline_fixed_string_t set;
1399         cmdline_fixed_string_t port;
1400         cmdline_fixed_string_t setup;
1401         cmdline_fixed_string_t on;
1402         cmdline_fixed_string_t mode;
1403 };
1404
1405 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1406                                 __rte_unused struct cmdline *cl,
1407                                 __rte_unused void *data)
1408 {
1409         struct cmd_set_port_setup_on_result *res = parsed_result;
1410
1411         if (strcmp(res->mode, "event") == 0)
1412                 setup_on_probe_event = true;
1413         else if (strcmp(res->mode, "iterator") == 0)
1414                 setup_on_probe_event = false;
1415         else
1416                 printf("Unknown mode\n");
1417 }
1418
1419 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1420         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1421                         set, "set");
1422 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1424                         port, "port");
1425 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1426         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1427                         setup, "setup");
1428 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1429         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1430                         on, "on");
1431 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1432         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1433                         mode, "iterator#event");
1434
1435 cmdline_parse_inst_t cmd_set_port_setup_on = {
1436         .f = cmd_set_port_setup_on_parsed,
1437         .data = NULL,
1438         .help_str = "set port setup on iterator|event",
1439         .tokens = {
1440                 (void *)&cmd_set_port_setup_on_set,
1441                 (void *)&cmd_set_port_setup_on_port,
1442                 (void *)&cmd_set_port_setup_on_setup,
1443                 (void *)&cmd_set_port_setup_on_on,
1444                 (void *)&cmd_set_port_setup_on_mode,
1445                 NULL,
1446         },
1447 };
1448
1449 /* *** attach a specified port *** */
1450 struct cmd_operate_attach_port_result {
1451         cmdline_fixed_string_t port;
1452         cmdline_fixed_string_t keyword;
1453         cmdline_multi_string_t identifier;
1454 };
1455
1456 static void cmd_operate_attach_port_parsed(void *parsed_result,
1457                                 __rte_unused struct cmdline *cl,
1458                                 __rte_unused void *data)
1459 {
1460         struct cmd_operate_attach_port_result *res = parsed_result;
1461
1462         if (!strcmp(res->keyword, "attach"))
1463                 attach_port(res->identifier);
1464         else
1465                 printf("Unknown parameter\n");
1466 }
1467
1468 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1469         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1470                         port, "port");
1471 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1472         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1473                         keyword, "attach");
1474 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1475         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1476                         identifier, TOKEN_STRING_MULTI);
1477
1478 cmdline_parse_inst_t cmd_operate_attach_port = {
1479         .f = cmd_operate_attach_port_parsed,
1480         .data = NULL,
1481         .help_str = "port attach <identifier>: "
1482                 "(identifier: pci address or virtual dev name)",
1483         .tokens = {
1484                 (void *)&cmd_operate_attach_port_port,
1485                 (void *)&cmd_operate_attach_port_keyword,
1486                 (void *)&cmd_operate_attach_port_identifier,
1487                 NULL,
1488         },
1489 };
1490
1491 /* *** detach a specified port *** */
1492 struct cmd_operate_detach_port_result {
1493         cmdline_fixed_string_t port;
1494         cmdline_fixed_string_t keyword;
1495         portid_t port_id;
1496 };
1497
1498 static void cmd_operate_detach_port_parsed(void *parsed_result,
1499                                 __rte_unused struct cmdline *cl,
1500                                 __rte_unused void *data)
1501 {
1502         struct cmd_operate_detach_port_result *res = parsed_result;
1503
1504         if (!strcmp(res->keyword, "detach")) {
1505                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1506                 detach_port_device(res->port_id);
1507         } else {
1508                 printf("Unknown parameter\n");
1509         }
1510 }
1511
1512 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1513         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1514                         port, "port");
1515 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1516         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1517                         keyword, "detach");
1518 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1519         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1520                         port_id, UINT16);
1521
1522 cmdline_parse_inst_t cmd_operate_detach_port = {
1523         .f = cmd_operate_detach_port_parsed,
1524         .data = NULL,
1525         .help_str = "port detach <port_id>",
1526         .tokens = {
1527                 (void *)&cmd_operate_detach_port_port,
1528                 (void *)&cmd_operate_detach_port_keyword,
1529                 (void *)&cmd_operate_detach_port_port_id,
1530                 NULL,
1531         },
1532 };
1533
1534 /* *** detach device by identifier *** */
1535 struct cmd_operate_detach_device_result {
1536         cmdline_fixed_string_t device;
1537         cmdline_fixed_string_t keyword;
1538         cmdline_fixed_string_t identifier;
1539 };
1540
1541 static void cmd_operate_detach_device_parsed(void *parsed_result,
1542                                 __rte_unused struct cmdline *cl,
1543                                 __rte_unused void *data)
1544 {
1545         struct cmd_operate_detach_device_result *res = parsed_result;
1546
1547         if (!strcmp(res->keyword, "detach"))
1548                 detach_devargs(res->identifier);
1549         else
1550                 printf("Unknown parameter\n");
1551 }
1552
1553 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1554         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1555                         device, "device");
1556 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1557         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1558                         keyword, "detach");
1559 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1560         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1561                         identifier, NULL);
1562
1563 cmdline_parse_inst_t cmd_operate_detach_device = {
1564         .f = cmd_operate_detach_device_parsed,
1565         .data = NULL,
1566         .help_str = "device detach <identifier>:"
1567                 "(identifier: pci address or virtual dev name)",
1568         .tokens = {
1569                 (void *)&cmd_operate_detach_device_device,
1570                 (void *)&cmd_operate_detach_device_keyword,
1571                 (void *)&cmd_operate_detach_device_identifier,
1572                 NULL,
1573         },
1574 };
1575 /* *** configure speed for all ports *** */
1576 struct cmd_config_speed_all {
1577         cmdline_fixed_string_t port;
1578         cmdline_fixed_string_t keyword;
1579         cmdline_fixed_string_t all;
1580         cmdline_fixed_string_t item1;
1581         cmdline_fixed_string_t item2;
1582         cmdline_fixed_string_t value1;
1583         cmdline_fixed_string_t value2;
1584 };
1585
1586 static int
1587 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1588 {
1589
1590         int duplex;
1591
1592         if (!strcmp(duplexstr, "half")) {
1593                 duplex = ETH_LINK_HALF_DUPLEX;
1594         } else if (!strcmp(duplexstr, "full")) {
1595                 duplex = ETH_LINK_FULL_DUPLEX;
1596         } else if (!strcmp(duplexstr, "auto")) {
1597                 duplex = ETH_LINK_FULL_DUPLEX;
1598         } else {
1599                 printf("Unknown duplex parameter\n");
1600                 return -1;
1601         }
1602
1603         if (!strcmp(speedstr, "10")) {
1604                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1605                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1606         } else if (!strcmp(speedstr, "100")) {
1607                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1608                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1609         } else {
1610                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1611                         printf("Invalid speed/duplex parameters\n");
1612                         return -1;
1613                 }
1614                 if (!strcmp(speedstr, "1000")) {
1615                         *speed = ETH_LINK_SPEED_1G;
1616                 } else if (!strcmp(speedstr, "10000")) {
1617                         *speed = ETH_LINK_SPEED_10G;
1618                 } else if (!strcmp(speedstr, "25000")) {
1619                         *speed = ETH_LINK_SPEED_25G;
1620                 } else if (!strcmp(speedstr, "40000")) {
1621                         *speed = ETH_LINK_SPEED_40G;
1622                 } else if (!strcmp(speedstr, "50000")) {
1623                         *speed = ETH_LINK_SPEED_50G;
1624                 } else if (!strcmp(speedstr, "100000")) {
1625                         *speed = ETH_LINK_SPEED_100G;
1626                 } else if (!strcmp(speedstr, "200000")) {
1627                         *speed = ETH_LINK_SPEED_200G;
1628                 } else if (!strcmp(speedstr, "auto")) {
1629                         *speed = ETH_LINK_SPEED_AUTONEG;
1630                 } else {
1631                         printf("Unknown speed parameter\n");
1632                         return -1;
1633                 }
1634         }
1635
1636         return 0;
1637 }
1638
1639 static void
1640 cmd_config_speed_all_parsed(void *parsed_result,
1641                         __rte_unused struct cmdline *cl,
1642                         __rte_unused void *data)
1643 {
1644         struct cmd_config_speed_all *res = parsed_result;
1645         uint32_t link_speed;
1646         portid_t pid;
1647
1648         if (!all_ports_stopped()) {
1649                 printf("Please stop all ports first\n");
1650                 return;
1651         }
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         RTE_ETH_FOREACH_DEV(pid) {
1658                 ports[pid].dev_conf.link_speeds = link_speed;
1659         }
1660
1661         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1662 }
1663
1664 cmdline_parse_token_string_t cmd_config_speed_all_port =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1666 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1668                                                         "config");
1669 cmdline_parse_token_string_t cmd_config_speed_all_all =
1670         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1671 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1673 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1675                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1676 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1678 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1680                                                 "half#full#auto");
1681
1682 cmdline_parse_inst_t cmd_config_speed_all = {
1683         .f = cmd_config_speed_all_parsed,
1684         .data = NULL,
1685         .help_str = "port config all speed "
1686                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1687                                                         "half|full|auto",
1688         .tokens = {
1689                 (void *)&cmd_config_speed_all_port,
1690                 (void *)&cmd_config_speed_all_keyword,
1691                 (void *)&cmd_config_speed_all_all,
1692                 (void *)&cmd_config_speed_all_item1,
1693                 (void *)&cmd_config_speed_all_value1,
1694                 (void *)&cmd_config_speed_all_item2,
1695                 (void *)&cmd_config_speed_all_value2,
1696                 NULL,
1697         },
1698 };
1699
1700 /* *** configure speed for specific port *** */
1701 struct cmd_config_speed_specific {
1702         cmdline_fixed_string_t port;
1703         cmdline_fixed_string_t keyword;
1704         portid_t id;
1705         cmdline_fixed_string_t item1;
1706         cmdline_fixed_string_t item2;
1707         cmdline_fixed_string_t value1;
1708         cmdline_fixed_string_t value2;
1709 };
1710
1711 static void
1712 cmd_config_speed_specific_parsed(void *parsed_result,
1713                                 __rte_unused struct cmdline *cl,
1714                                 __rte_unused void *data)
1715 {
1716         struct cmd_config_speed_specific *res = parsed_result;
1717         uint32_t link_speed;
1718
1719         if (!all_ports_stopped()) {
1720                 printf("Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         if (port_id_is_invalid(res->id, ENABLED_WARN))
1725                 return;
1726
1727         if (parse_and_check_speed_duplex(res->value1, res->value2,
1728                         &link_speed) < 0)
1729                 return;
1730
1731         ports[res->id].dev_conf.link_speeds = link_speed;
1732
1733         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1734 }
1735
1736
1737 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1739                                                                 "port");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1742                                                                 "config");
1743 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1744         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1747                                                                 "speed");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1750                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1751 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1753                                                                 "duplex");
1754 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1756                                                         "half#full#auto");
1757
1758 cmdline_parse_inst_t cmd_config_speed_specific = {
1759         .f = cmd_config_speed_specific_parsed,
1760         .data = NULL,
1761         .help_str = "port config <port_id> speed "
1762                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1763                                                         "half|full|auto",
1764         .tokens = {
1765                 (void *)&cmd_config_speed_specific_port,
1766                 (void *)&cmd_config_speed_specific_keyword,
1767                 (void *)&cmd_config_speed_specific_id,
1768                 (void *)&cmd_config_speed_specific_item1,
1769                 (void *)&cmd_config_speed_specific_value1,
1770                 (void *)&cmd_config_speed_specific_item2,
1771                 (void *)&cmd_config_speed_specific_value2,
1772                 NULL,
1773         },
1774 };
1775
1776 /* *** configure loopback for all ports *** */
1777 struct cmd_config_loopback_all {
1778         cmdline_fixed_string_t port;
1779         cmdline_fixed_string_t keyword;
1780         cmdline_fixed_string_t all;
1781         cmdline_fixed_string_t item;
1782         uint32_t mode;
1783 };
1784
1785 static void
1786 cmd_config_loopback_all_parsed(void *parsed_result,
1787                         __rte_unused struct cmdline *cl,
1788                         __rte_unused void *data)
1789 {
1790         struct cmd_config_loopback_all *res = parsed_result;
1791         portid_t pid;
1792
1793         if (!all_ports_stopped()) {
1794                 printf("Please stop all ports first\n");
1795                 return;
1796         }
1797
1798         RTE_ETH_FOREACH_DEV(pid) {
1799                 ports[pid].dev_conf.lpbk_mode = res->mode;
1800         }
1801
1802         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1803 }
1804
1805 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1807 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1809                                                         "config");
1810 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1812 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1814                                                         "loopback");
1815 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1817
1818 cmdline_parse_inst_t cmd_config_loopback_all = {
1819         .f = cmd_config_loopback_all_parsed,
1820         .data = NULL,
1821         .help_str = "port config all loopback <mode>",
1822         .tokens = {
1823                 (void *)&cmd_config_loopback_all_port,
1824                 (void *)&cmd_config_loopback_all_keyword,
1825                 (void *)&cmd_config_loopback_all_all,
1826                 (void *)&cmd_config_loopback_all_item,
1827                 (void *)&cmd_config_loopback_all_mode,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure loopback for specific port *** */
1833 struct cmd_config_loopback_specific {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         uint16_t port_id;
1837         cmdline_fixed_string_t item;
1838         uint32_t mode;
1839 };
1840
1841 static void
1842 cmd_config_loopback_specific_parsed(void *parsed_result,
1843                                 __rte_unused struct cmdline *cl,
1844                                 __rte_unused void *data)
1845 {
1846         struct cmd_config_loopback_specific *res = parsed_result;
1847
1848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1849                 return;
1850
1851         if (!port_is_stopped(res->port_id)) {
1852                 printf("Please stop port %u first\n", res->port_id);
1853                 return;
1854         }
1855
1856         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1857
1858         cmd_reconfig_device_queue(res->port_id, 1, 1);
1859 }
1860
1861
1862 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1864                                                                 "port");
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1867                                                                 "config");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1870                                                                 UINT16);
1871 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1873                                                                 "loopback");
1874 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1875         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1876                               UINT32);
1877
1878 cmdline_parse_inst_t cmd_config_loopback_specific = {
1879         .f = cmd_config_loopback_specific_parsed,
1880         .data = NULL,
1881         .help_str = "port config <port_id> loopback <mode>",
1882         .tokens = {
1883                 (void *)&cmd_config_loopback_specific_port,
1884                 (void *)&cmd_config_loopback_specific_keyword,
1885                 (void *)&cmd_config_loopback_specific_id,
1886                 (void *)&cmd_config_loopback_specific_item,
1887                 (void *)&cmd_config_loopback_specific_mode,
1888                 NULL,
1889         },
1890 };
1891
1892 /* *** configure txq/rxq, txd/rxd *** */
1893 struct cmd_config_rx_tx {
1894         cmdline_fixed_string_t port;
1895         cmdline_fixed_string_t keyword;
1896         cmdline_fixed_string_t all;
1897         cmdline_fixed_string_t name;
1898         uint16_t value;
1899 };
1900
1901 static void
1902 cmd_config_rx_tx_parsed(void *parsed_result,
1903                         __rte_unused struct cmdline *cl,
1904                         __rte_unused void *data)
1905 {
1906         struct cmd_config_rx_tx *res = parsed_result;
1907
1908         if (!all_ports_stopped()) {
1909                 printf("Please stop all ports first\n");
1910                 return;
1911         }
1912         if (!strcmp(res->name, "rxq")) {
1913                 if (!res->value && !nb_txq) {
1914                         printf("Warning: Either rx or tx queues should be non zero\n");
1915                         return;
1916                 }
1917                 if (check_nb_rxq(res->value) != 0)
1918                         return;
1919                 nb_rxq = res->value;
1920         }
1921         else if (!strcmp(res->name, "txq")) {
1922                 if (!res->value && !nb_rxq) {
1923                         printf("Warning: Either rx or tx queues should be non zero\n");
1924                         return;
1925                 }
1926                 if (check_nb_txq(res->value) != 0)
1927                         return;
1928                 nb_txq = res->value;
1929         }
1930         else if (!strcmp(res->name, "rxd")) {
1931                 if (check_nb_rxd(res->value) != 0)
1932                         return;
1933                 nb_rxd = res->value;
1934         } else if (!strcmp(res->name, "txd")) {
1935                 if (check_nb_txd(res->value) != 0)
1936                         return;
1937
1938                 nb_txd = res->value;
1939         } else {
1940                 printf("Unknown parameter\n");
1941                 return;
1942         }
1943
1944         fwd_config_setup();
1945
1946         init_port_config();
1947
1948         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1949 }
1950
1951 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1952         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1953 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1954         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1955 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1957 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1959                                                 "rxq#txq#rxd#txd");
1960 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1961         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1962
1963 cmdline_parse_inst_t cmd_config_rx_tx = {
1964         .f = cmd_config_rx_tx_parsed,
1965         .data = NULL,
1966         .help_str = "port config all rxq|txq|rxd|txd <value>",
1967         .tokens = {
1968                 (void *)&cmd_config_rx_tx_port,
1969                 (void *)&cmd_config_rx_tx_keyword,
1970                 (void *)&cmd_config_rx_tx_all,
1971                 (void *)&cmd_config_rx_tx_name,
1972                 (void *)&cmd_config_rx_tx_value,
1973                 NULL,
1974         },
1975 };
1976
1977 /* *** config max packet length *** */
1978 struct cmd_config_max_pkt_len_result {
1979         cmdline_fixed_string_t port;
1980         cmdline_fixed_string_t keyword;
1981         cmdline_fixed_string_t all;
1982         cmdline_fixed_string_t name;
1983         uint32_t value;
1984 };
1985
1986 static void
1987 cmd_config_max_pkt_len_parsed(void *parsed_result,
1988                                 __rte_unused struct cmdline *cl,
1989                                 __rte_unused void *data)
1990 {
1991         struct cmd_config_max_pkt_len_result *res = parsed_result;
1992         portid_t pid;
1993
1994         if (!all_ports_stopped()) {
1995                 printf("Please stop all ports first\n");
1996                 return;
1997         }
1998
1999         RTE_ETH_FOREACH_DEV(pid) {
2000                 struct rte_port *port = &ports[pid];
2001                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2002
2003                 if (!strcmp(res->name, "max-pkt-len")) {
2004                         if (res->value < RTE_ETHER_MIN_LEN) {
2005                                 printf("max-pkt-len can not be less than %d\n",
2006                                                 RTE_ETHER_MIN_LEN);
2007                                 return;
2008                         }
2009                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2010                                 return;
2011
2012                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2013                         if (res->value > RTE_ETHER_MAX_LEN)
2014                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2015                         else
2016                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2017                         port->dev_conf.rxmode.offloads = rx_offloads;
2018                 } else {
2019                         printf("Unknown parameter\n");
2020                         return;
2021                 }
2022         }
2023
2024         init_port_config();
2025
2026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2031                                                                 "port");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2034                                                                 "config");
2035 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2037                                                                 "all");
2038 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2039         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2040                                                                 "max-pkt-len");
2041 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2042         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2043                                                                 UINT32);
2044
2045 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2046         .f = cmd_config_max_pkt_len_parsed,
2047         .data = NULL,
2048         .help_str = "port config all max-pkt-len <value>",
2049         .tokens = {
2050                 (void *)&cmd_config_max_pkt_len_port,
2051                 (void *)&cmd_config_max_pkt_len_keyword,
2052                 (void *)&cmd_config_max_pkt_len_all,
2053                 (void *)&cmd_config_max_pkt_len_name,
2054                 (void *)&cmd_config_max_pkt_len_value,
2055                 NULL,
2056         },
2057 };
2058
2059 /* *** config max LRO aggregated packet size *** */
2060 struct cmd_config_max_lro_pkt_size_result {
2061         cmdline_fixed_string_t port;
2062         cmdline_fixed_string_t keyword;
2063         cmdline_fixed_string_t all;
2064         cmdline_fixed_string_t name;
2065         uint32_t value;
2066 };
2067
2068 static void
2069 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2070                                 __rte_unused struct cmdline *cl,
2071                                 __rte_unused void *data)
2072 {
2073         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2074         portid_t pid;
2075
2076         if (!all_ports_stopped()) {
2077                 printf("Please stop all ports first\n");
2078                 return;
2079         }
2080
2081         RTE_ETH_FOREACH_DEV(pid) {
2082                 struct rte_port *port = &ports[pid];
2083
2084                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2085                         if (res->value ==
2086                                         port->dev_conf.rxmode.max_lro_pkt_size)
2087                                 return;
2088
2089                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2090                 } else {
2091                         printf("Unknown parameter\n");
2092                         return;
2093                 }
2094         }
2095
2096         init_port_config();
2097
2098         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2099 }
2100
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103                                  port, "port");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2105         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106                                  keyword, "config");
2107 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2108         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109                                  all, "all");
2110 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2112                                  name, "max-lro-pkt-size");
2113 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2114         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2115                               value, UINT32);
2116
2117 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2118         .f = cmd_config_max_lro_pkt_size_parsed,
2119         .data = NULL,
2120         .help_str = "port config all max-lro-pkt-size <value>",
2121         .tokens = {
2122                 (void *)&cmd_config_max_lro_pkt_size_port,
2123                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2124                 (void *)&cmd_config_max_lro_pkt_size_all,
2125                 (void *)&cmd_config_max_lro_pkt_size_name,
2126                 (void *)&cmd_config_max_lro_pkt_size_value,
2127                 NULL,
2128         },
2129 };
2130
2131 /* *** configure port MTU *** */
2132 struct cmd_config_mtu_result {
2133         cmdline_fixed_string_t port;
2134         cmdline_fixed_string_t keyword;
2135         cmdline_fixed_string_t mtu;
2136         portid_t port_id;
2137         uint16_t value;
2138 };
2139
2140 static void
2141 cmd_config_mtu_parsed(void *parsed_result,
2142                       __rte_unused struct cmdline *cl,
2143                       __rte_unused void *data)
2144 {
2145         struct cmd_config_mtu_result *res = parsed_result;
2146
2147         if (res->value < RTE_ETHER_MIN_LEN) {
2148                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2149                 return;
2150         }
2151         port_mtu_set(res->port_id, res->value);
2152 }
2153
2154 cmdline_parse_token_string_t cmd_config_mtu_port =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2156                                  "port");
2157 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2158         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2159                                  "config");
2160 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2162                                  "mtu");
2163 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2164         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2165 cmdline_parse_token_num_t cmd_config_mtu_value =
2166         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2167
2168 cmdline_parse_inst_t cmd_config_mtu = {
2169         .f = cmd_config_mtu_parsed,
2170         .data = NULL,
2171         .help_str = "port config mtu <port_id> <value>",
2172         .tokens = {
2173                 (void *)&cmd_config_mtu_port,
2174                 (void *)&cmd_config_mtu_keyword,
2175                 (void *)&cmd_config_mtu_mtu,
2176                 (void *)&cmd_config_mtu_port_id,
2177                 (void *)&cmd_config_mtu_value,
2178                 NULL,
2179         },
2180 };
2181
2182 /* *** configure rx mode *** */
2183 struct cmd_config_rx_mode_flag {
2184         cmdline_fixed_string_t port;
2185         cmdline_fixed_string_t keyword;
2186         cmdline_fixed_string_t all;
2187         cmdline_fixed_string_t name;
2188         cmdline_fixed_string_t value;
2189 };
2190
2191 static void
2192 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2193                                 __rte_unused struct cmdline *cl,
2194                                 __rte_unused void *data)
2195 {
2196         struct cmd_config_rx_mode_flag *res = parsed_result;
2197
2198         if (!all_ports_stopped()) {
2199                 printf("Please stop all ports first\n");
2200                 return;
2201         }
2202
2203         if (!strcmp(res->name, "drop-en")) {
2204                 if (!strcmp(res->value, "on"))
2205                         rx_drop_en = 1;
2206                 else if (!strcmp(res->value, "off"))
2207                         rx_drop_en = 0;
2208                 else {
2209                         printf("Unknown parameter\n");
2210                         return;
2211                 }
2212         } else {
2213                 printf("Unknown parameter\n");
2214                 return;
2215         }
2216
2217         init_port_config();
2218
2219         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2220 }
2221
2222 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2223         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2226                                                                 "config");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2230         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2231                                         "drop-en");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2233         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2234                                                         "on#off");
2235
2236 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2237         .f = cmd_config_rx_mode_flag_parsed,
2238         .data = NULL,
2239         .help_str = "port config all drop-en on|off",
2240         .tokens = {
2241                 (void *)&cmd_config_rx_mode_flag_port,
2242                 (void *)&cmd_config_rx_mode_flag_keyword,
2243                 (void *)&cmd_config_rx_mode_flag_all,
2244                 (void *)&cmd_config_rx_mode_flag_name,
2245                 (void *)&cmd_config_rx_mode_flag_value,
2246                 NULL,
2247         },
2248 };
2249
2250 /* *** configure rss *** */
2251 struct cmd_config_rss {
2252         cmdline_fixed_string_t port;
2253         cmdline_fixed_string_t keyword;
2254         cmdline_fixed_string_t all;
2255         cmdline_fixed_string_t name;
2256         cmdline_fixed_string_t value;
2257 };
2258
2259 static void
2260 cmd_config_rss_parsed(void *parsed_result,
2261                         __rte_unused struct cmdline *cl,
2262                         __rte_unused void *data)
2263 {
2264         struct cmd_config_rss *res = parsed_result;
2265         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2266         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2267         int use_default = 0;
2268         int all_updated = 1;
2269         int diag;
2270         uint16_t i;
2271         int ret;
2272
2273         if (!strcmp(res->value, "all"))
2274                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2275                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2276                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2277                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2278         else if (!strcmp(res->value, "eth"))
2279                 rss_conf.rss_hf = ETH_RSS_ETH;
2280         else if (!strcmp(res->value, "vlan"))
2281                 rss_conf.rss_hf = ETH_RSS_VLAN;
2282         else if (!strcmp(res->value, "ip"))
2283                 rss_conf.rss_hf = ETH_RSS_IP;
2284         else if (!strcmp(res->value, "udp"))
2285                 rss_conf.rss_hf = ETH_RSS_UDP;
2286         else if (!strcmp(res->value, "tcp"))
2287                 rss_conf.rss_hf = ETH_RSS_TCP;
2288         else if (!strcmp(res->value, "sctp"))
2289                 rss_conf.rss_hf = ETH_RSS_SCTP;
2290         else if (!strcmp(res->value, "ether"))
2291                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2292         else if (!strcmp(res->value, "port"))
2293                 rss_conf.rss_hf = ETH_RSS_PORT;
2294         else if (!strcmp(res->value, "vxlan"))
2295                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2296         else if (!strcmp(res->value, "geneve"))
2297                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2298         else if (!strcmp(res->value, "nvgre"))
2299                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2300         else if (!strcmp(res->value, "l3-src-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2302         else if (!strcmp(res->value, "l3-dst-only"))
2303                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2304         else if (!strcmp(res->value, "l4-src-only"))
2305                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2306         else if (!strcmp(res->value, "l4-dst-only"))
2307                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2308         else if (!strcmp(res->value, "l2-src-only"))
2309                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2310         else if (!strcmp(res->value, "l2-dst-only"))
2311                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2312         else if (!strcmp(res->value, "l2tpv3"))
2313                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2314         else if (!strcmp(res->value, "esp"))
2315                 rss_conf.rss_hf = ETH_RSS_ESP;
2316         else if (!strcmp(res->value, "ah"))
2317                 rss_conf.rss_hf = ETH_RSS_AH;
2318         else if (!strcmp(res->value, "pfcp"))
2319                 rss_conf.rss_hf = ETH_RSS_PFCP;
2320         else if (!strcmp(res->value, "pppoe"))
2321                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2322         else if (!strcmp(res->value, "gtpu"))
2323                 rss_conf.rss_hf = ETH_RSS_GTPU;
2324         else if (!strcmp(res->value, "none"))
2325                 rss_conf.rss_hf = 0;
2326         else if (!strcmp(res->value, "default"))
2327                 use_default = 1;
2328         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2329                                                 atoi(res->value) < 64)
2330                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2331         else {
2332                 printf("Unknown parameter\n");
2333                 return;
2334         }
2335         rss_conf.rss_key = NULL;
2336         /* Update global configuration for RSS types. */
2337         RTE_ETH_FOREACH_DEV(i) {
2338                 struct rte_eth_rss_conf local_rss_conf;
2339
2340                 ret = eth_dev_info_get_print_err(i, &dev_info);
2341                 if (ret != 0)
2342                         return;
2343
2344                 if (use_default)
2345                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2346
2347                 local_rss_conf = rss_conf;
2348                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2349                         dev_info.flow_type_rss_offloads;
2350                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2351                         printf("Port %u modified RSS hash function based on hardware support,"
2352                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2353                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2354                 }
2355                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2356                 if (diag < 0) {
2357                         all_updated = 0;
2358                         printf("Configuration of RSS hash at ethernet port %d "
2359                                 "failed with error (%d): %s.\n",
2360                                 i, -diag, strerror(-diag));
2361                 }
2362         }
2363         if (all_updated && !use_default) {
2364                 rss_hf = rss_conf.rss_hf;
2365                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2366         }
2367 }
2368
2369 cmdline_parse_token_string_t cmd_config_rss_port =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2371 cmdline_parse_token_string_t cmd_config_rss_keyword =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2373 cmdline_parse_token_string_t cmd_config_rss_all =
2374         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2375 cmdline_parse_token_string_t cmd_config_rss_name =
2376         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2377 cmdline_parse_token_string_t cmd_config_rss_value =
2378         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2379
2380 cmdline_parse_inst_t cmd_config_rss = {
2381         .f = cmd_config_rss_parsed,
2382         .data = NULL,
2383         .help_str = "port config all rss "
2384                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2385                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2386         .tokens = {
2387                 (void *)&cmd_config_rss_port,
2388                 (void *)&cmd_config_rss_keyword,
2389                 (void *)&cmd_config_rss_all,
2390                 (void *)&cmd_config_rss_name,
2391                 (void *)&cmd_config_rss_value,
2392                 NULL,
2393         },
2394 };
2395
2396 /* *** configure rss hash key *** */
2397 struct cmd_config_rss_hash_key {
2398         cmdline_fixed_string_t port;
2399         cmdline_fixed_string_t config;
2400         portid_t port_id;
2401         cmdline_fixed_string_t rss_hash_key;
2402         cmdline_fixed_string_t rss_type;
2403         cmdline_fixed_string_t key;
2404 };
2405
2406 static uint8_t
2407 hexa_digit_to_value(char hexa_digit)
2408 {
2409         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2410                 return (uint8_t) (hexa_digit - '0');
2411         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2412                 return (uint8_t) ((hexa_digit - 'a') + 10);
2413         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2414                 return (uint8_t) ((hexa_digit - 'A') + 10);
2415         /* Invalid hexa digit */
2416         return 0xFF;
2417 }
2418
2419 static uint8_t
2420 parse_and_check_key_hexa_digit(char *key, int idx)
2421 {
2422         uint8_t hexa_v;
2423
2424         hexa_v = hexa_digit_to_value(key[idx]);
2425         if (hexa_v == 0xFF)
2426                 printf("invalid key: character %c at position %d is not a "
2427                        "valid hexa digit\n", key[idx], idx);
2428         return hexa_v;
2429 }
2430
2431 static void
2432 cmd_config_rss_hash_key_parsed(void *parsed_result,
2433                                __rte_unused struct cmdline *cl,
2434                                __rte_unused void *data)
2435 {
2436         struct cmd_config_rss_hash_key *res = parsed_result;
2437         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2438         uint8_t xdgt0;
2439         uint8_t xdgt1;
2440         int i;
2441         struct rte_eth_dev_info dev_info;
2442         uint8_t hash_key_size;
2443         uint32_t key_len;
2444         int ret;
2445
2446         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2447         if (ret != 0)
2448                 return;
2449
2450         if (dev_info.hash_key_size > 0 &&
2451                         dev_info.hash_key_size <= sizeof(hash_key))
2452                 hash_key_size = dev_info.hash_key_size;
2453         else {
2454                 printf("dev_info did not provide a valid hash key size\n");
2455                 return;
2456         }
2457         /* Check the length of the RSS hash key */
2458         key_len = strlen(res->key);
2459         if (key_len != (hash_key_size * 2)) {
2460                 printf("key length: %d invalid - key must be a string of %d"
2461                            " hexa-decimal numbers\n",
2462                            (int) key_len, hash_key_size * 2);
2463                 return;
2464         }
2465         /* Translate RSS hash key into binary representation */
2466         for (i = 0; i < hash_key_size; i++) {
2467                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2468                 if (xdgt0 == 0xFF)
2469                         return;
2470                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2471                 if (xdgt1 == 0xFF)
2472                         return;
2473                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2474         }
2475         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2476                         hash_key_size);
2477 }
2478
2479 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2481 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2482         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2483                                  "config");
2484 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2485         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2486 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2487         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2488                                  rss_hash_key, "rss-hash-key");
2489 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2490         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2491                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2492                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2493                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2494                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2495                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2496                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2497                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2498 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2499         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2500
2501 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2502         .f = cmd_config_rss_hash_key_parsed,
2503         .data = NULL,
2504         .help_str = "port config <port_id> rss-hash-key "
2505                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2506                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2507                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2508                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2509                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2510                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2511                 "<string of hex digits (variable length, NIC dependent)>",
2512         .tokens = {
2513                 (void *)&cmd_config_rss_hash_key_port,
2514                 (void *)&cmd_config_rss_hash_key_config,
2515                 (void *)&cmd_config_rss_hash_key_port_id,
2516                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2517                 (void *)&cmd_config_rss_hash_key_rss_type,
2518                 (void *)&cmd_config_rss_hash_key_value,
2519                 NULL,
2520         },
2521 };
2522
2523 /* *** configure port rxq/txq ring size *** */
2524 struct cmd_config_rxtx_ring_size {
2525         cmdline_fixed_string_t port;
2526         cmdline_fixed_string_t config;
2527         portid_t portid;
2528         cmdline_fixed_string_t rxtxq;
2529         uint16_t qid;
2530         cmdline_fixed_string_t rsize;
2531         uint16_t size;
2532 };
2533
2534 static void
2535 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2536                                  __rte_unused struct cmdline *cl,
2537                                  __rte_unused void *data)
2538 {
2539         struct cmd_config_rxtx_ring_size *res = parsed_result;
2540         struct rte_port *port;
2541         uint8_t isrx;
2542
2543         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2544                 return;
2545
2546         if (res->portid == (portid_t)RTE_PORT_ALL) {
2547                 printf("Invalid port id\n");
2548                 return;
2549         }
2550
2551         port = &ports[res->portid];
2552
2553         if (!strcmp(res->rxtxq, "rxq"))
2554                 isrx = 1;
2555         else if (!strcmp(res->rxtxq, "txq"))
2556                 isrx = 0;
2557         else {
2558                 printf("Unknown parameter\n");
2559                 return;
2560         }
2561
2562         if (isrx && rx_queue_id_is_invalid(res->qid))
2563                 return;
2564         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2565                 return;
2566
2567         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2568                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2569                        rx_free_thresh);
2570                 return;
2571         }
2572
2573         if (isrx)
2574                 port->nb_rx_desc[res->qid] = res->size;
2575         else
2576                 port->nb_tx_desc[res->qid] = res->size;
2577
2578         cmd_reconfig_device_queue(res->portid, 0, 1);
2579 }
2580
2581 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2582         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2583                                  port, "port");
2584 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2585         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2586                                  config, "config");
2587 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2588         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2589                                  portid, UINT16);
2590 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2591         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2592                                  rxtxq, "rxq#txq");
2593 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2594         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2595                               qid, UINT16);
2596 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2597         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2598                                  rsize, "ring_size");
2599 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2601                               size, UINT16);
2602
2603 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2604         .f = cmd_config_rxtx_ring_size_parsed,
2605         .data = NULL,
2606         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2607         .tokens = {
2608                 (void *)&cmd_config_rxtx_ring_size_port,
2609                 (void *)&cmd_config_rxtx_ring_size_config,
2610                 (void *)&cmd_config_rxtx_ring_size_portid,
2611                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2612                 (void *)&cmd_config_rxtx_ring_size_qid,
2613                 (void *)&cmd_config_rxtx_ring_size_rsize,
2614                 (void *)&cmd_config_rxtx_ring_size_size,
2615                 NULL,
2616         },
2617 };
2618
2619 /* *** configure port rxq/txq start/stop *** */
2620 struct cmd_config_rxtx_queue {
2621         cmdline_fixed_string_t port;
2622         portid_t portid;
2623         cmdline_fixed_string_t rxtxq;
2624         uint16_t qid;
2625         cmdline_fixed_string_t opname;
2626 };
2627
2628 static void
2629 cmd_config_rxtx_queue_parsed(void *parsed_result,
2630                         __rte_unused struct cmdline *cl,
2631                         __rte_unused void *data)
2632 {
2633         struct cmd_config_rxtx_queue *res = parsed_result;
2634         uint8_t isrx;
2635         uint8_t isstart;
2636         int ret = 0;
2637
2638         if (test_done == 0) {
2639                 printf("Please stop forwarding first\n");
2640                 return;
2641         }
2642
2643         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2644                 return;
2645
2646         if (port_is_started(res->portid) != 1) {
2647                 printf("Please start port %u first\n", res->portid);
2648                 return;
2649         }
2650
2651         if (!strcmp(res->rxtxq, "rxq"))
2652                 isrx = 1;
2653         else if (!strcmp(res->rxtxq, "txq"))
2654                 isrx = 0;
2655         else {
2656                 printf("Unknown parameter\n");
2657                 return;
2658         }
2659
2660         if (isrx && rx_queue_id_is_invalid(res->qid))
2661                 return;
2662         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2663                 return;
2664
2665         if (!strcmp(res->opname, "start"))
2666                 isstart = 1;
2667         else if (!strcmp(res->opname, "stop"))
2668                 isstart = 0;
2669         else {
2670                 printf("Unknown parameter\n");
2671                 return;
2672         }
2673
2674         if (isstart && isrx)
2675                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2676         else if (!isstart && isrx)
2677                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2678         else if (isstart && !isrx)
2679                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2680         else
2681                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2682
2683         if (ret == -ENOTSUP)
2684                 printf("Function not supported in PMD driver\n");
2685 }
2686
2687 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2689 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2690         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2691 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2692         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2693 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2694         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2695 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2696         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2697                                                 "start#stop");
2698
2699 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2700         .f = cmd_config_rxtx_queue_parsed,
2701         .data = NULL,
2702         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2703         .tokens = {
2704                 (void *)&cmd_config_rxtx_queue_port,
2705                 (void *)&cmd_config_rxtx_queue_portid,
2706                 (void *)&cmd_config_rxtx_queue_rxtxq,
2707                 (void *)&cmd_config_rxtx_queue_qid,
2708                 (void *)&cmd_config_rxtx_queue_opname,
2709                 NULL,
2710         },
2711 };
2712
2713 /* *** configure port rxq/txq deferred start on/off *** */
2714 struct cmd_config_deferred_start_rxtx_queue {
2715         cmdline_fixed_string_t port;
2716         portid_t port_id;
2717         cmdline_fixed_string_t rxtxq;
2718         uint16_t qid;
2719         cmdline_fixed_string_t opname;
2720         cmdline_fixed_string_t state;
2721 };
2722
2723 static void
2724 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2725                         __rte_unused struct cmdline *cl,
2726                         __rte_unused void *data)
2727 {
2728         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2729         struct rte_port *port;
2730         uint8_t isrx;
2731         uint8_t ison;
2732         uint8_t needreconfig = 0;
2733
2734         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2735                 return;
2736
2737         if (port_is_started(res->port_id) != 0) {
2738                 printf("Please stop port %u first\n", res->port_id);
2739                 return;
2740         }
2741
2742         port = &ports[res->port_id];
2743
2744         isrx = !strcmp(res->rxtxq, "rxq");
2745
2746         if (isrx && rx_queue_id_is_invalid(res->qid))
2747                 return;
2748         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2749                 return;
2750
2751         ison = !strcmp(res->state, "on");
2752
2753         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2754                 port->rx_conf[res->qid].rx_deferred_start = ison;
2755                 needreconfig = 1;
2756         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2757                 port->tx_conf[res->qid].tx_deferred_start = ison;
2758                 needreconfig = 1;
2759         }
2760
2761         if (needreconfig)
2762                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2763 }
2764
2765 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2766         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2767                                                 port, "port");
2768 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2769         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2770                                                 port_id, UINT16);
2771 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2772         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2773                                                 rxtxq, "rxq#txq");
2774 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2775         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2776                                                 qid, UINT16);
2777 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2779                                                 opname, "deferred_start");
2780 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2781         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2782                                                 state, "on#off");
2783
2784 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2785         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2786         .data = NULL,
2787         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2788         .tokens = {
2789                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2790                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2791                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2792                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2793                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2794                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2795                 NULL,
2796         },
2797 };
2798
2799 /* *** configure port rxq/txq setup *** */
2800 struct cmd_setup_rxtx_queue {
2801         cmdline_fixed_string_t port;
2802         portid_t portid;
2803         cmdline_fixed_string_t rxtxq;
2804         uint16_t qid;
2805         cmdline_fixed_string_t setup;
2806 };
2807
2808 /* Common CLI fields for queue setup */
2809 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2810         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2811 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2812         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2813 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2814         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2815 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2816         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2817 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2818         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2819
2820 static void
2821 cmd_setup_rxtx_queue_parsed(
2822         void *parsed_result,
2823         __rte_unused struct cmdline *cl,
2824         __rte_unused void *data)
2825 {
2826         struct cmd_setup_rxtx_queue *res = parsed_result;
2827         struct rte_port *port;
2828         struct rte_mempool *mp;
2829         unsigned int socket_id;
2830         uint8_t isrx = 0;
2831         int ret;
2832
2833         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2834                 return;
2835
2836         if (res->portid == (portid_t)RTE_PORT_ALL) {
2837                 printf("Invalid port id\n");
2838                 return;
2839         }
2840
2841         if (!strcmp(res->rxtxq, "rxq"))
2842                 isrx = 1;
2843         else if (!strcmp(res->rxtxq, "txq"))
2844                 isrx = 0;
2845         else {
2846                 printf("Unknown parameter\n");
2847                 return;
2848         }
2849
2850         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2851                 printf("Invalid rx queue\n");
2852                 return;
2853         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2854                 printf("Invalid tx queue\n");
2855                 return;
2856         }
2857
2858         port = &ports[res->portid];
2859         if (isrx) {
2860                 socket_id = rxring_numa[res->portid];
2861                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2862                         socket_id = port->socket_id;
2863
2864                 mp = mbuf_pool_find(socket_id);
2865                 if (mp == NULL) {
2866                         printf("Failed to setup RX queue: "
2867                                 "No mempool allocation"
2868                                 " on the socket %d\n",
2869                                 rxring_numa[res->portid]);
2870                         return;
2871                 }
2872                 ret = rte_eth_rx_queue_setup(res->portid,
2873                                              res->qid,
2874                                              port->nb_rx_desc[res->qid],
2875                                              socket_id,
2876                                              &port->rx_conf[res->qid],
2877                                              mp);
2878                 if (ret)
2879                         printf("Failed to setup RX queue\n");
2880         } else {
2881                 socket_id = txring_numa[res->portid];
2882                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2883                         socket_id = port->socket_id;
2884
2885                 ret = rte_eth_tx_queue_setup(res->portid,
2886                                              res->qid,
2887                                              port->nb_tx_desc[res->qid],
2888                                              socket_id,
2889                                              &port->tx_conf[res->qid]);
2890                 if (ret)
2891                         printf("Failed to setup TX queue\n");
2892         }
2893 }
2894
2895 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2896         .f = cmd_setup_rxtx_queue_parsed,
2897         .data = NULL,
2898         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2899         .tokens = {
2900                 (void *)&cmd_setup_rxtx_queue_port,
2901                 (void *)&cmd_setup_rxtx_queue_portid,
2902                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2903                 (void *)&cmd_setup_rxtx_queue_qid,
2904                 (void *)&cmd_setup_rxtx_queue_setup,
2905                 NULL,
2906         },
2907 };
2908
2909
2910 /* *** Configure RSS RETA *** */
2911 struct cmd_config_rss_reta {
2912         cmdline_fixed_string_t port;
2913         cmdline_fixed_string_t keyword;
2914         portid_t port_id;
2915         cmdline_fixed_string_t name;
2916         cmdline_fixed_string_t list_name;
2917         cmdline_fixed_string_t list_of_items;
2918 };
2919
2920 static int
2921 parse_reta_config(const char *str,
2922                   struct rte_eth_rss_reta_entry64 *reta_conf,
2923                   uint16_t nb_entries)
2924 {
2925         int i;
2926         unsigned size;
2927         uint16_t hash_index, idx, shift;
2928         uint16_t nb_queue;
2929         char s[256];
2930         const char *p, *p0 = str;
2931         char *end;
2932         enum fieldnames {
2933                 FLD_HASH_INDEX = 0,
2934                 FLD_QUEUE,
2935                 _NUM_FLD
2936         };
2937         unsigned long int_fld[_NUM_FLD];
2938         char *str_fld[_NUM_FLD];
2939
2940         while ((p = strchr(p0,'(')) != NULL) {
2941                 ++p;
2942                 if((p0 = strchr(p,')')) == NULL)
2943                         return -1;
2944
2945                 size = p0 - p;
2946                 if(size >= sizeof(s))
2947                         return -1;
2948
2949                 snprintf(s, sizeof(s), "%.*s", size, p);
2950                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2951                         return -1;
2952                 for (i = 0; i < _NUM_FLD; i++) {
2953                         errno = 0;
2954                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2955                         if (errno != 0 || end == str_fld[i] ||
2956                                         int_fld[i] > 65535)
2957                                 return -1;
2958                 }
2959
2960                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2961                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2962
2963                 if (hash_index >= nb_entries) {
2964                         printf("Invalid RETA hash index=%d\n", hash_index);
2965                         return -1;
2966                 }
2967
2968                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2969                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2970                 reta_conf[idx].mask |= (1ULL << shift);
2971                 reta_conf[idx].reta[shift] = nb_queue;
2972         }
2973
2974         return 0;
2975 }
2976
2977 static void
2978 cmd_set_rss_reta_parsed(void *parsed_result,
2979                         __rte_unused struct cmdline *cl,
2980                         __rte_unused void *data)
2981 {
2982         int ret;
2983         struct rte_eth_dev_info dev_info;
2984         struct rte_eth_rss_reta_entry64 reta_conf[8];
2985         struct cmd_config_rss_reta *res = parsed_result;
2986
2987         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2988         if (ret != 0)
2989                 return;
2990
2991         if (dev_info.reta_size == 0) {
2992                 printf("Redirection table size is 0 which is "
2993                                         "invalid for RSS\n");
2994                 return;
2995         } else
2996                 printf("The reta size of port %d is %u\n",
2997                         res->port_id, dev_info.reta_size);
2998         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2999                 printf("Currently do not support more than %u entries of "
3000                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3001                 return;
3002         }
3003
3004         memset(reta_conf, 0, sizeof(reta_conf));
3005         if (!strcmp(res->list_name, "reta")) {
3006                 if (parse_reta_config(res->list_of_items, reta_conf,
3007                                                 dev_info.reta_size)) {
3008                         printf("Invalid RSS Redirection Table "
3009                                         "config entered\n");
3010                         return;
3011                 }
3012                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3013                                 reta_conf, dev_info.reta_size);
3014                 if (ret != 0)
3015                         printf("Bad redirection table parameter, "
3016                                         "return code = %d \n", ret);
3017         }
3018 }
3019
3020 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3022 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3023         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3024 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3025         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3026 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3028 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3029         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3030 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3031         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3032                                  NULL);
3033 cmdline_parse_inst_t cmd_config_rss_reta = {
3034         .f = cmd_set_rss_reta_parsed,
3035         .data = NULL,
3036         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3037         .tokens = {
3038                 (void *)&cmd_config_rss_reta_port,
3039                 (void *)&cmd_config_rss_reta_keyword,
3040                 (void *)&cmd_config_rss_reta_port_id,
3041                 (void *)&cmd_config_rss_reta_name,
3042                 (void *)&cmd_config_rss_reta_list_name,
3043                 (void *)&cmd_config_rss_reta_list_of_items,
3044                 NULL,
3045         },
3046 };
3047
3048 /* *** SHOW PORT RETA INFO *** */
3049 struct cmd_showport_reta {
3050         cmdline_fixed_string_t show;
3051         cmdline_fixed_string_t port;
3052         portid_t port_id;
3053         cmdline_fixed_string_t rss;
3054         cmdline_fixed_string_t reta;
3055         uint16_t size;
3056         cmdline_fixed_string_t list_of_items;
3057 };
3058
3059 static int
3060 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3061                            uint16_t nb_entries,
3062                            char *str)
3063 {
3064         uint32_t size;
3065         const char *p, *p0 = str;
3066         char s[256];
3067         char *end;
3068         char *str_fld[8];
3069         uint16_t i;
3070         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3071                         RTE_RETA_GROUP_SIZE;
3072         int ret;
3073
3074         p = strchr(p0, '(');
3075         if (p == NULL)
3076                 return -1;
3077         p++;
3078         p0 = strchr(p, ')');
3079         if (p0 == NULL)
3080                 return -1;
3081         size = p0 - p;
3082         if (size >= sizeof(s)) {
3083                 printf("The string size exceeds the internal buffer size\n");
3084                 return -1;
3085         }
3086         snprintf(s, sizeof(s), "%.*s", size, p);
3087         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3088         if (ret <= 0 || ret != num) {
3089                 printf("The bits of masks do not match the number of "
3090                                         "reta entries: %u\n", num);
3091                 return -1;
3092         }
3093         for (i = 0; i < ret; i++)
3094                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3095
3096         return 0;
3097 }
3098
3099 static void
3100 cmd_showport_reta_parsed(void *parsed_result,
3101                          __rte_unused struct cmdline *cl,
3102                          __rte_unused void *data)
3103 {
3104         struct cmd_showport_reta *res = parsed_result;
3105         struct rte_eth_rss_reta_entry64 reta_conf[8];
3106         struct rte_eth_dev_info dev_info;
3107         uint16_t max_reta_size;
3108         int ret;
3109
3110         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3111         if (ret != 0)
3112                 return;
3113
3114         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3115         if (res->size == 0 || res->size > max_reta_size) {
3116                 printf("Invalid redirection table size: %u (1-%u)\n",
3117                         res->size, max_reta_size);
3118                 return;
3119         }
3120
3121         memset(reta_conf, 0, sizeof(reta_conf));
3122         if (showport_parse_reta_config(reta_conf, res->size,
3123                                 res->list_of_items) < 0) {
3124                 printf("Invalid string: %s for reta masks\n",
3125                                         res->list_of_items);
3126                 return;
3127         }
3128         port_rss_reta_info(res->port_id, reta_conf, res->size);
3129 }
3130
3131 cmdline_parse_token_string_t cmd_showport_reta_show =
3132         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3133 cmdline_parse_token_string_t cmd_showport_reta_port =
3134         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3135 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3136         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3137 cmdline_parse_token_string_t cmd_showport_reta_rss =
3138         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3139 cmdline_parse_token_string_t cmd_showport_reta_reta =
3140         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3141 cmdline_parse_token_num_t cmd_showport_reta_size =
3142         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3143 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3144         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3145                                         list_of_items, NULL);
3146
3147 cmdline_parse_inst_t cmd_showport_reta = {
3148         .f = cmd_showport_reta_parsed,
3149         .data = NULL,
3150         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3151         .tokens = {
3152                 (void *)&cmd_showport_reta_show,
3153                 (void *)&cmd_showport_reta_port,
3154                 (void *)&cmd_showport_reta_port_id,
3155                 (void *)&cmd_showport_reta_rss,
3156                 (void *)&cmd_showport_reta_reta,
3157                 (void *)&cmd_showport_reta_size,
3158                 (void *)&cmd_showport_reta_list_of_items,
3159                 NULL,
3160         },
3161 };
3162
3163 /* *** Show RSS hash configuration *** */
3164 struct cmd_showport_rss_hash {
3165         cmdline_fixed_string_t show;
3166         cmdline_fixed_string_t port;
3167         portid_t port_id;
3168         cmdline_fixed_string_t rss_hash;
3169         cmdline_fixed_string_t rss_type;
3170         cmdline_fixed_string_t key; /* optional argument */
3171 };
3172
3173 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3174                                 __rte_unused struct cmdline *cl,
3175                                 void *show_rss_key)
3176 {
3177         struct cmd_showport_rss_hash *res = parsed_result;
3178
3179         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3180 }
3181
3182 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3183         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3184 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3185         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3186 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3187         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3188 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3189         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3190                                  "rss-hash");
3191 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3192         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3193
3194 cmdline_parse_inst_t cmd_showport_rss_hash = {
3195         .f = cmd_showport_rss_hash_parsed,
3196         .data = NULL,
3197         .help_str = "show port <port_id> rss-hash",
3198         .tokens = {
3199                 (void *)&cmd_showport_rss_hash_show,
3200                 (void *)&cmd_showport_rss_hash_port,
3201                 (void *)&cmd_showport_rss_hash_port_id,
3202                 (void *)&cmd_showport_rss_hash_rss_hash,
3203                 NULL,
3204         },
3205 };
3206
3207 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3208         .f = cmd_showport_rss_hash_parsed,
3209         .data = (void *)1,
3210         .help_str = "show port <port_id> rss-hash key",
3211         .tokens = {
3212                 (void *)&cmd_showport_rss_hash_show,
3213                 (void *)&cmd_showport_rss_hash_port,
3214                 (void *)&cmd_showport_rss_hash_port_id,
3215                 (void *)&cmd_showport_rss_hash_rss_hash,
3216                 (void *)&cmd_showport_rss_hash_rss_key,
3217                 NULL,
3218         },
3219 };
3220
3221 /* *** Configure DCB *** */
3222 struct cmd_config_dcb {
3223         cmdline_fixed_string_t port;
3224         cmdline_fixed_string_t config;
3225         portid_t port_id;
3226         cmdline_fixed_string_t dcb;
3227         cmdline_fixed_string_t vt;
3228         cmdline_fixed_string_t vt_en;
3229         uint8_t num_tcs;
3230         cmdline_fixed_string_t pfc;
3231         cmdline_fixed_string_t pfc_en;
3232 };
3233
3234 static void
3235 cmd_config_dcb_parsed(void *parsed_result,
3236                         __rte_unused struct cmdline *cl,
3237                         __rte_unused void *data)
3238 {
3239         struct cmd_config_dcb *res = parsed_result;
3240         portid_t port_id = res->port_id;
3241         struct rte_port *port;
3242         uint8_t pfc_en;
3243         int ret;
3244
3245         port = &ports[port_id];
3246         /** Check if the port is not started **/
3247         if (port->port_status != RTE_PORT_STOPPED) {
3248                 printf("Please stop port %d first\n", port_id);
3249                 return;
3250         }
3251
3252         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3253                 printf("The invalid number of traffic class,"
3254                         " only 4 or 8 allowed.\n");
3255                 return;
3256         }
3257
3258         if (nb_fwd_lcores < res->num_tcs) {
3259                 printf("nb_cores shouldn't be less than number of TCs.\n");
3260                 return;
3261         }
3262         if (!strncmp(res->pfc_en, "on", 2))
3263                 pfc_en = 1;
3264         else
3265                 pfc_en = 0;
3266
3267         /* DCB in VT mode */
3268         if (!strncmp(res->vt_en, "on", 2))
3269                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3270                                 (enum rte_eth_nb_tcs)res->num_tcs,
3271                                 pfc_en);
3272         else
3273                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3274                                 (enum rte_eth_nb_tcs)res->num_tcs,
3275                                 pfc_en);
3276
3277
3278         if (ret != 0) {
3279                 printf("Cannot initialize network ports.\n");
3280                 return;
3281         }
3282
3283         cmd_reconfig_device_queue(port_id, 1, 1);
3284 }
3285
3286 cmdline_parse_token_string_t cmd_config_dcb_port =
3287         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3288 cmdline_parse_token_string_t cmd_config_dcb_config =
3289         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3290 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3291         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3292 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3294 cmdline_parse_token_string_t cmd_config_dcb_vt =
3295         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3296 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3297         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3298 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3299         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3300 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3302 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3303         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3304
3305 cmdline_parse_inst_t cmd_config_dcb = {
3306         .f = cmd_config_dcb_parsed,
3307         .data = NULL,
3308         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3309         .tokens = {
3310                 (void *)&cmd_config_dcb_port,
3311                 (void *)&cmd_config_dcb_config,
3312                 (void *)&cmd_config_dcb_port_id,
3313                 (void *)&cmd_config_dcb_dcb,
3314                 (void *)&cmd_config_dcb_vt,
3315                 (void *)&cmd_config_dcb_vt_en,
3316                 (void *)&cmd_config_dcb_num_tcs,
3317                 (void *)&cmd_config_dcb_pfc,
3318                 (void *)&cmd_config_dcb_pfc_en,
3319                 NULL,
3320         },
3321 };
3322
3323 /* *** configure number of packets per burst *** */
3324 struct cmd_config_burst {
3325         cmdline_fixed_string_t port;
3326         cmdline_fixed_string_t keyword;
3327         cmdline_fixed_string_t all;
3328         cmdline_fixed_string_t name;
3329         uint16_t value;
3330 };
3331
3332 static void
3333 cmd_config_burst_parsed(void *parsed_result,
3334                         __rte_unused struct cmdline *cl,
3335                         __rte_unused void *data)
3336 {
3337         struct cmd_config_burst *res = parsed_result;
3338         struct rte_eth_dev_info dev_info;
3339         uint16_t rec_nb_pkts;
3340         int ret;
3341
3342         if (!all_ports_stopped()) {
3343                 printf("Please stop all ports first\n");
3344                 return;
3345         }
3346
3347         if (!strcmp(res->name, "burst")) {
3348                 if (res->value == 0) {
3349                         /* If user gives a value of zero, query the PMD for
3350                          * its recommended Rx burst size. Testpmd uses a single
3351                          * size for all ports, so assume all ports are the same
3352                          * NIC model and use the values from Port 0.
3353                          */
3354                         ret = eth_dev_info_get_print_err(0, &dev_info);
3355                         if (ret != 0)
3356                                 return;
3357
3358                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3359
3360                         if (rec_nb_pkts == 0) {
3361                                 printf("PMD does not recommend a burst size.\n"
3362                                         "User provided value must be between"
3363                                         " 1 and %d\n", MAX_PKT_BURST);
3364                                 return;
3365                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3366                                 printf("PMD recommended burst size of %d"
3367                                         " exceeds maximum value of %d\n",
3368                                         rec_nb_pkts, MAX_PKT_BURST);
3369                                 return;
3370                         }
3371                         printf("Using PMD-provided burst value of %d\n",
3372                                 rec_nb_pkts);
3373                         nb_pkt_per_burst = rec_nb_pkts;
3374                 } else if (res->value > MAX_PKT_BURST) {
3375                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3376                         return;
3377                 } else
3378                         nb_pkt_per_burst = res->value;
3379         } else {
3380                 printf("Unknown parameter\n");
3381                 return;
3382         }
3383
3384         init_port_config();
3385
3386         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3387 }
3388
3389 cmdline_parse_token_string_t cmd_config_burst_port =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3391 cmdline_parse_token_string_t cmd_config_burst_keyword =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3393 cmdline_parse_token_string_t cmd_config_burst_all =
3394         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3395 cmdline_parse_token_string_t cmd_config_burst_name =
3396         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3397 cmdline_parse_token_num_t cmd_config_burst_value =
3398         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3399
3400 cmdline_parse_inst_t cmd_config_burst = {
3401         .f = cmd_config_burst_parsed,
3402         .data = NULL,
3403         .help_str = "port config all burst <value>",
3404         .tokens = {
3405                 (void *)&cmd_config_burst_port,
3406                 (void *)&cmd_config_burst_keyword,
3407                 (void *)&cmd_config_burst_all,
3408                 (void *)&cmd_config_burst_name,
3409                 (void *)&cmd_config_burst_value,
3410                 NULL,
3411         },
3412 };
3413
3414 /* *** configure rx/tx queues *** */
3415 struct cmd_config_thresh {
3416         cmdline_fixed_string_t port;
3417         cmdline_fixed_string_t keyword;
3418         cmdline_fixed_string_t all;
3419         cmdline_fixed_string_t name;
3420         uint8_t value;
3421 };
3422
3423 static void
3424 cmd_config_thresh_parsed(void *parsed_result,
3425                         __rte_unused struct cmdline *cl,
3426                         __rte_unused void *data)
3427 {
3428         struct cmd_config_thresh *res = parsed_result;
3429
3430         if (!all_ports_stopped()) {
3431                 printf("Please stop all ports first\n");
3432                 return;
3433         }
3434
3435         if (!strcmp(res->name, "txpt"))
3436                 tx_pthresh = res->value;
3437         else if(!strcmp(res->name, "txht"))
3438                 tx_hthresh = res->value;
3439         else if(!strcmp(res->name, "txwt"))
3440                 tx_wthresh = res->value;
3441         else if(!strcmp(res->name, "rxpt"))
3442                 rx_pthresh = res->value;
3443         else if(!strcmp(res->name, "rxht"))
3444                 rx_hthresh = res->value;
3445         else if(!strcmp(res->name, "rxwt"))
3446                 rx_wthresh = res->value;
3447         else {
3448                 printf("Unknown parameter\n");
3449                 return;
3450         }
3451
3452         init_port_config();
3453
3454         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3455 }
3456
3457 cmdline_parse_token_string_t cmd_config_thresh_port =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3459 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3461 cmdline_parse_token_string_t cmd_config_thresh_all =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3463 cmdline_parse_token_string_t cmd_config_thresh_name =
3464         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3465                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3466 cmdline_parse_token_num_t cmd_config_thresh_value =
3467         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3468
3469 cmdline_parse_inst_t cmd_config_thresh = {
3470         .f = cmd_config_thresh_parsed,
3471         .data = NULL,
3472         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3473         .tokens = {
3474                 (void *)&cmd_config_thresh_port,
3475                 (void *)&cmd_config_thresh_keyword,
3476                 (void *)&cmd_config_thresh_all,
3477                 (void *)&cmd_config_thresh_name,
3478                 (void *)&cmd_config_thresh_value,
3479                 NULL,
3480         },
3481 };
3482
3483 /* *** configure free/rs threshold *** */
3484 struct cmd_config_threshold {
3485         cmdline_fixed_string_t port;
3486         cmdline_fixed_string_t keyword;
3487         cmdline_fixed_string_t all;
3488         cmdline_fixed_string_t name;
3489         uint16_t value;
3490 };
3491
3492 static void
3493 cmd_config_threshold_parsed(void *parsed_result,
3494                         __rte_unused struct cmdline *cl,
3495                         __rte_unused void *data)
3496 {
3497         struct cmd_config_threshold *res = parsed_result;
3498
3499         if (!all_ports_stopped()) {
3500                 printf("Please stop all ports first\n");
3501                 return;
3502         }
3503
3504         if (!strcmp(res->name, "txfreet"))
3505                 tx_free_thresh = res->value;
3506         else if (!strcmp(res->name, "txrst"))
3507                 tx_rs_thresh = res->value;
3508         else if (!strcmp(res->name, "rxfreet"))
3509                 rx_free_thresh = res->value;
3510         else {
3511                 printf("Unknown parameter\n");
3512                 return;
3513         }
3514
3515         init_port_config();
3516
3517         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3518 }
3519
3520 cmdline_parse_token_string_t cmd_config_threshold_port =
3521         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3522 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3523         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3524                                                                 "config");
3525 cmdline_parse_token_string_t cmd_config_threshold_all =
3526         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3527 cmdline_parse_token_string_t cmd_config_threshold_name =
3528         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3529                                                 "txfreet#txrst#rxfreet");
3530 cmdline_parse_token_num_t cmd_config_threshold_value =
3531         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3532
3533 cmdline_parse_inst_t cmd_config_threshold = {
3534         .f = cmd_config_threshold_parsed,
3535         .data = NULL,
3536         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3537         .tokens = {
3538                 (void *)&cmd_config_threshold_port,
3539                 (void *)&cmd_config_threshold_keyword,
3540                 (void *)&cmd_config_threshold_all,
3541                 (void *)&cmd_config_threshold_name,
3542                 (void *)&cmd_config_threshold_value,
3543                 NULL,
3544         },
3545 };
3546
3547 /* *** stop *** */
3548 struct cmd_stop_result {
3549         cmdline_fixed_string_t stop;
3550 };
3551
3552 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3553                             __rte_unused struct cmdline *cl,
3554                             __rte_unused void *data)
3555 {
3556         stop_packet_forwarding();
3557 }
3558
3559 cmdline_parse_token_string_t cmd_stop_stop =
3560         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3561
3562 cmdline_parse_inst_t cmd_stop = {
3563         .f = cmd_stop_parsed,
3564         .data = NULL,
3565         .help_str = "stop: Stop packet forwarding",
3566         .tokens = {
3567                 (void *)&cmd_stop_stop,
3568                 NULL,
3569         },
3570 };
3571
3572 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3573
3574 unsigned int
3575 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3576                 unsigned int *parsed_items, int check_unique_values)
3577 {
3578         unsigned int nb_item;
3579         unsigned int value;
3580         unsigned int i;
3581         unsigned int j;
3582         int value_ok;
3583         char c;
3584
3585         /*
3586          * First parse all items in the list and store their value.
3587          */
3588         value = 0;
3589         nb_item = 0;
3590         value_ok = 0;
3591         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3592                 c = str[i];
3593                 if ((c >= '0') && (c <= '9')) {
3594                         value = (unsigned int) (value * 10 + (c - '0'));
3595                         value_ok = 1;
3596                         continue;
3597                 }
3598                 if (c != ',') {
3599                         printf("character %c is not a decimal digit\n", c);
3600                         return 0;
3601                 }
3602                 if (! value_ok) {
3603                         printf("No valid value before comma\n");
3604                         return 0;
3605                 }
3606                 if (nb_item < max_items) {
3607                         parsed_items[nb_item] = value;
3608                         value_ok = 0;
3609                         value = 0;
3610                 }
3611                 nb_item++;
3612         }
3613         if (nb_item >= max_items) {
3614                 printf("Number of %s = %u > %u (maximum items)\n",
3615                        item_name, nb_item + 1, max_items);
3616                 return 0;
3617         }
3618         parsed_items[nb_item++] = value;
3619         if (! check_unique_values)
3620                 return nb_item;
3621
3622         /*
3623          * Then, check that all values in the list are differents.
3624          * No optimization here...
3625          */
3626         for (i = 0; i < nb_item; i++) {
3627                 for (j = i + 1; j < nb_item; j++) {
3628                         if (parsed_items[j] == parsed_items[i]) {
3629                                 printf("duplicated %s %u at index %u and %u\n",
3630                                        item_name, parsed_items[i], i, j);
3631                                 return 0;
3632                         }
3633                 }
3634         }
3635         return nb_item;
3636 }
3637
3638 struct cmd_set_list_result {
3639         cmdline_fixed_string_t cmd_keyword;
3640         cmdline_fixed_string_t list_name;
3641         cmdline_fixed_string_t list_of_items;
3642 };
3643
3644 static void cmd_set_list_parsed(void *parsed_result,
3645                                 __rte_unused struct cmdline *cl,
3646                                 __rte_unused void *data)
3647 {
3648         struct cmd_set_list_result *res;
3649         union {
3650                 unsigned int lcorelist[RTE_MAX_LCORE];
3651                 unsigned int portlist[RTE_MAX_ETHPORTS];
3652         } parsed_items;
3653         unsigned int nb_item;
3654
3655         if (test_done == 0) {
3656                 printf("Please stop forwarding first\n");
3657                 return;
3658         }
3659
3660         res = parsed_result;
3661         if (!strcmp(res->list_name, "corelist")) {
3662                 nb_item = parse_item_list(res->list_of_items, "core",
3663                                           RTE_MAX_LCORE,
3664                                           parsed_items.lcorelist, 1);
3665                 if (nb_item > 0) {
3666                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3667                         fwd_config_setup();
3668                 }
3669                 return;
3670         }
3671         if (!strcmp(res->list_name, "portlist")) {
3672                 nb_item = parse_item_list(res->list_of_items, "port",
3673                                           RTE_MAX_ETHPORTS,
3674                                           parsed_items.portlist, 1);
3675                 if (nb_item > 0) {
3676                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3677                         fwd_config_setup();
3678                 }
3679         }
3680 }
3681
3682 cmdline_parse_token_string_t cmd_set_list_keyword =
3683         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3684                                  "set");
3685 cmdline_parse_token_string_t cmd_set_list_name =
3686         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3687                                  "corelist#portlist");
3688 cmdline_parse_token_string_t cmd_set_list_of_items =
3689         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3690                                  NULL);
3691
3692 cmdline_parse_inst_t cmd_set_fwd_list = {
3693         .f = cmd_set_list_parsed,
3694         .data = NULL,
3695         .help_str = "set corelist|portlist <list0[,list1]*>",
3696         .tokens = {
3697                 (void *)&cmd_set_list_keyword,
3698                 (void *)&cmd_set_list_name,
3699                 (void *)&cmd_set_list_of_items,
3700                 NULL,
3701         },
3702 };
3703
3704 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3705
3706 struct cmd_setmask_result {
3707         cmdline_fixed_string_t set;
3708         cmdline_fixed_string_t mask;
3709         uint64_t hexavalue;
3710 };
3711
3712 static void cmd_set_mask_parsed(void *parsed_result,
3713                                 __rte_unused struct cmdline *cl,
3714                                 __rte_unused void *data)
3715 {
3716         struct cmd_setmask_result *res = parsed_result;
3717
3718         if (test_done == 0) {
3719                 printf("Please stop forwarding first\n");
3720                 return;
3721         }
3722         if (!strcmp(res->mask, "coremask")) {
3723                 set_fwd_lcores_mask(res->hexavalue);
3724                 fwd_config_setup();
3725         } else if (!strcmp(res->mask, "portmask")) {
3726                 set_fwd_ports_mask(res->hexavalue);
3727                 fwd_config_setup();
3728         }
3729 }
3730
3731 cmdline_parse_token_string_t cmd_setmask_set =
3732         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3733 cmdline_parse_token_string_t cmd_setmask_mask =
3734         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3735                                  "coremask#portmask");
3736 cmdline_parse_token_num_t cmd_setmask_value =
3737         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3738
3739 cmdline_parse_inst_t cmd_set_fwd_mask = {
3740         .f = cmd_set_mask_parsed,
3741         .data = NULL,
3742         .help_str = "set coremask|portmask <hexadecimal value>",
3743         .tokens = {
3744                 (void *)&cmd_setmask_set,
3745                 (void *)&cmd_setmask_mask,
3746                 (void *)&cmd_setmask_value,
3747                 NULL,
3748         },
3749 };
3750
3751 /*
3752  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3753  */
3754 struct cmd_set_result {
3755         cmdline_fixed_string_t set;
3756         cmdline_fixed_string_t what;
3757         uint16_t value;
3758 };
3759
3760 static void cmd_set_parsed(void *parsed_result,
3761                            __rte_unused struct cmdline *cl,
3762                            __rte_unused void *data)
3763 {
3764         struct cmd_set_result *res = parsed_result;
3765         if (!strcmp(res->what, "nbport")) {
3766                 set_fwd_ports_number(res->value);
3767                 fwd_config_setup();
3768         } else if (!strcmp(res->what, "nbcore")) {
3769                 set_fwd_lcores_number(res->value);
3770                 fwd_config_setup();
3771         } else if (!strcmp(res->what, "burst"))
3772                 set_nb_pkt_per_burst(res->value);
3773         else if (!strcmp(res->what, "verbose"))
3774                 set_verbose_level(res->value);
3775 }
3776
3777 cmdline_parse_token_string_t cmd_set_set =
3778         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3779 cmdline_parse_token_string_t cmd_set_what =
3780         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3781                                  "nbport#nbcore#burst#verbose");
3782 cmdline_parse_token_num_t cmd_set_value =
3783         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3784
3785 cmdline_parse_inst_t cmd_set_numbers = {
3786         .f = cmd_set_parsed,
3787         .data = NULL,
3788         .help_str = "set nbport|nbcore|burst|verbose <value>",
3789         .tokens = {
3790                 (void *)&cmd_set_set,
3791                 (void *)&cmd_set_what,
3792                 (void *)&cmd_set_value,
3793                 NULL,
3794         },
3795 };
3796
3797 /* *** SET LOG LEVEL CONFIGURATION *** */
3798
3799 struct cmd_set_log_result {
3800         cmdline_fixed_string_t set;
3801         cmdline_fixed_string_t log;
3802         cmdline_fixed_string_t type;
3803         uint32_t level;
3804 };
3805
3806 static void
3807 cmd_set_log_parsed(void *parsed_result,
3808                    __rte_unused struct cmdline *cl,
3809                    __rte_unused void *data)
3810 {
3811         struct cmd_set_log_result *res;
3812         int ret;
3813
3814         res = parsed_result;
3815         if (!strcmp(res->type, "global"))
3816                 rte_log_set_global_level(res->level);
3817         else {
3818                 ret = rte_log_set_level_regexp(res->type, res->level);
3819                 if (ret < 0)
3820                         printf("Unable to set log level\n");
3821         }
3822 }
3823
3824 cmdline_parse_token_string_t cmd_set_log_set =
3825         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3826 cmdline_parse_token_string_t cmd_set_log_log =
3827         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3828 cmdline_parse_token_string_t cmd_set_log_type =
3829         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3830 cmdline_parse_token_num_t cmd_set_log_level =
3831         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3832
3833 cmdline_parse_inst_t cmd_set_log = {
3834         .f = cmd_set_log_parsed,
3835         .data = NULL,
3836         .help_str = "set log global|<type> <level>",
3837         .tokens = {
3838                 (void *)&cmd_set_log_set,
3839                 (void *)&cmd_set_log_log,
3840                 (void *)&cmd_set_log_type,
3841                 (void *)&cmd_set_log_level,
3842                 NULL,
3843         },
3844 };
3845
3846 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3847
3848 struct cmd_set_txpkts_result {
3849         cmdline_fixed_string_t cmd_keyword;
3850         cmdline_fixed_string_t txpkts;
3851         cmdline_fixed_string_t seg_lengths;
3852 };
3853
3854 static void
3855 cmd_set_txpkts_parsed(void *parsed_result,
3856                       __rte_unused struct cmdline *cl,
3857                       __rte_unused void *data)
3858 {
3859         struct cmd_set_txpkts_result *res;
3860         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3861         unsigned int nb_segs;
3862
3863         res = parsed_result;
3864         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3865                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3866         if (nb_segs > 0)
3867                 set_tx_pkt_segments(seg_lengths, nb_segs);
3868 }
3869
3870 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3871         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3872                                  cmd_keyword, "set");
3873 cmdline_parse_token_string_t cmd_set_txpkts_name =
3874         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3875                                  txpkts, "txpkts");
3876 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3877         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3878                                  seg_lengths, NULL);
3879
3880 cmdline_parse_inst_t cmd_set_txpkts = {
3881         .f = cmd_set_txpkts_parsed,
3882         .data = NULL,
3883         .help_str = "set txpkts <len0[,len1]*>",
3884         .tokens = {
3885                 (void *)&cmd_set_txpkts_keyword,
3886                 (void *)&cmd_set_txpkts_name,
3887                 (void *)&cmd_set_txpkts_lengths,
3888                 NULL,
3889         },
3890 };
3891
3892 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3893
3894 struct cmd_set_txsplit_result {
3895         cmdline_fixed_string_t cmd_keyword;
3896         cmdline_fixed_string_t txsplit;
3897         cmdline_fixed_string_t mode;
3898 };
3899
3900 static void
3901 cmd_set_txsplit_parsed(void *parsed_result,
3902                       __rte_unused struct cmdline *cl,
3903                       __rte_unused void *data)
3904 {
3905         struct cmd_set_txsplit_result *res;
3906
3907         res = parsed_result;
3908         set_tx_pkt_split(res->mode);
3909 }
3910
3911 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3912         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3913                                  cmd_keyword, "set");
3914 cmdline_parse_token_string_t cmd_set_txsplit_name =
3915         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3916                                  txsplit, "txsplit");
3917 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3918         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3919                                  mode, NULL);
3920
3921 cmdline_parse_inst_t cmd_set_txsplit = {
3922         .f = cmd_set_txsplit_parsed,
3923         .data = NULL,
3924         .help_str = "set txsplit on|off|rand",
3925         .tokens = {
3926                 (void *)&cmd_set_txsplit_keyword,
3927                 (void *)&cmd_set_txsplit_name,
3928                 (void *)&cmd_set_txsplit_mode,
3929                 NULL,
3930         },
3931 };
3932
3933 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3934 struct cmd_rx_vlan_filter_all_result {
3935         cmdline_fixed_string_t rx_vlan;
3936         cmdline_fixed_string_t what;
3937         cmdline_fixed_string_t all;
3938         portid_t port_id;
3939 };
3940
3941 static void
3942 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3943                               __rte_unused struct cmdline *cl,
3944                               __rte_unused void *data)
3945 {
3946         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3947
3948         if (!strcmp(res->what, "add"))
3949                 rx_vlan_all_filter_set(res->port_id, 1);
3950         else
3951                 rx_vlan_all_filter_set(res->port_id, 0);
3952 }
3953
3954 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3955         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3956                                  rx_vlan, "rx_vlan");
3957 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3958         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3959                                  what, "add#rm");
3960 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3961         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3962                                  all, "all");
3963 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3964         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3965                               port_id, UINT16);
3966
3967 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3968         .f = cmd_rx_vlan_filter_all_parsed,
3969         .data = NULL,
3970         .help_str = "rx_vlan add|rm all <port_id>: "
3971                 "Add/Remove all identifiers to/from the set of VLAN "
3972                 "identifiers filtered by a port",
3973         .tokens = {
3974                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3975                 (void *)&cmd_rx_vlan_filter_all_what,
3976                 (void *)&cmd_rx_vlan_filter_all_all,
3977                 (void *)&cmd_rx_vlan_filter_all_portid,
3978                 NULL,
3979         },
3980 };
3981
3982 /* *** VLAN OFFLOAD SET ON A PORT *** */
3983 struct cmd_vlan_offload_result {
3984         cmdline_fixed_string_t vlan;
3985         cmdline_fixed_string_t set;
3986         cmdline_fixed_string_t vlan_type;
3987         cmdline_fixed_string_t what;
3988         cmdline_fixed_string_t on;
3989         cmdline_fixed_string_t port_id;
3990 };
3991
3992 static void
3993 cmd_vlan_offload_parsed(void *parsed_result,
3994                           __rte_unused struct cmdline *cl,
3995                           __rte_unused void *data)
3996 {
3997         int on;
3998         struct cmd_vlan_offload_result *res = parsed_result;
3999         char *str;
4000         int i, len = 0;
4001         portid_t port_id = 0;
4002         unsigned int tmp;
4003
4004         str = res->port_id;
4005         len = strnlen(str, STR_TOKEN_SIZE);
4006         i = 0;
4007         /* Get port_id first */
4008         while(i < len){
4009                 if(str[i] == ',')
4010                         break;
4011
4012                 i++;
4013         }
4014         str[i]='\0';
4015         tmp = strtoul(str, NULL, 0);
4016         /* If port_id greater that what portid_t can represent, return */
4017         if(tmp >= RTE_MAX_ETHPORTS)
4018                 return;
4019         port_id = (portid_t)tmp;
4020
4021         if (!strcmp(res->on, "on"))
4022                 on = 1;
4023         else
4024                 on = 0;
4025
4026         if (!strcmp(res->what, "strip"))
4027                 rx_vlan_strip_set(port_id,  on);
4028         else if(!strcmp(res->what, "stripq")){
4029                 uint16_t queue_id = 0;
4030
4031                 /* No queue_id, return */
4032                 if(i + 1 >= len) {
4033                         printf("must specify (port,queue_id)\n");
4034                         return;
4035                 }
4036                 tmp = strtoul(str + i + 1, NULL, 0);
4037                 /* If queue_id greater that what 16-bits can represent, return */
4038                 if(tmp > 0xffff)
4039                         return;
4040
4041                 queue_id = (uint16_t)tmp;
4042                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4043         }
4044         else if (!strcmp(res->what, "filter"))
4045                 rx_vlan_filter_set(port_id, on);
4046         else if (!strcmp(res->what, "qinq_strip"))
4047                 rx_vlan_qinq_strip_set(port_id, on);
4048         else
4049                 vlan_extend_set(port_id, on);
4050
4051         return;
4052 }
4053
4054 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4055         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4056                                  vlan, "vlan");
4057 cmdline_parse_token_string_t cmd_vlan_offload_set =
4058         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4059                                  set, "set");
4060 cmdline_parse_token_string_t cmd_vlan_offload_what =
4061         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4062                                 what, "strip#filter#qinq_strip#extend#stripq");
4063 cmdline_parse_token_string_t cmd_vlan_offload_on =
4064         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4065                               on, "on#off");
4066 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4067         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4068                               port_id, NULL);
4069
4070 cmdline_parse_inst_t cmd_vlan_offload = {
4071         .f = cmd_vlan_offload_parsed,
4072         .data = NULL,
4073         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4074                 "<port_id[,queue_id]>: "
4075                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4076         .tokens = {
4077                 (void *)&cmd_vlan_offload_vlan,
4078                 (void *)&cmd_vlan_offload_set,
4079                 (void *)&cmd_vlan_offload_what,
4080                 (void *)&cmd_vlan_offload_on,
4081                 (void *)&cmd_vlan_offload_portid,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** VLAN TPID SET ON A PORT *** */
4087 struct cmd_vlan_tpid_result {
4088         cmdline_fixed_string_t vlan;
4089         cmdline_fixed_string_t set;
4090         cmdline_fixed_string_t vlan_type;
4091         cmdline_fixed_string_t what;
4092         uint16_t tp_id;
4093         portid_t port_id;
4094 };
4095
4096 static void
4097 cmd_vlan_tpid_parsed(void *parsed_result,
4098                           __rte_unused struct cmdline *cl,
4099                           __rte_unused void *data)
4100 {
4101         struct cmd_vlan_tpid_result *res = parsed_result;
4102         enum rte_vlan_type vlan_type;
4103
4104         if (!strcmp(res->vlan_type, "inner"))
4105                 vlan_type = ETH_VLAN_TYPE_INNER;
4106         else if (!strcmp(res->vlan_type, "outer"))
4107                 vlan_type = ETH_VLAN_TYPE_OUTER;
4108         else {
4109                 printf("Unknown vlan type\n");
4110                 return;
4111         }
4112         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4113 }
4114
4115 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4116         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4117                                  vlan, "vlan");
4118 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4119         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4120                                  set, "set");
4121 cmdline_parse_token_string_t cmd_vlan_type =
4122         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4123                                  vlan_type, "inner#outer");
4124 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4125         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4126                                  what, "tpid");
4127 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4128         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4129                               tp_id, UINT16);
4130 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4131         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4132                               port_id, UINT16);
4133
4134 cmdline_parse_inst_t cmd_vlan_tpid = {
4135         .f = cmd_vlan_tpid_parsed,
4136         .data = NULL,
4137         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4138                 "Set the VLAN Ether type",
4139         .tokens = {
4140                 (void *)&cmd_vlan_tpid_vlan,
4141                 (void *)&cmd_vlan_tpid_set,
4142                 (void *)&cmd_vlan_type,
4143                 (void *)&cmd_vlan_tpid_what,
4144                 (void *)&cmd_vlan_tpid_tpid,
4145                 (void *)&cmd_vlan_tpid_portid,
4146                 NULL,
4147         },
4148 };
4149
4150 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4151 struct cmd_rx_vlan_filter_result {
4152         cmdline_fixed_string_t rx_vlan;
4153         cmdline_fixed_string_t what;
4154         uint16_t vlan_id;
4155         portid_t port_id;
4156 };
4157
4158 static void
4159 cmd_rx_vlan_filter_parsed(void *parsed_result,
4160                           __rte_unused struct cmdline *cl,
4161                           __rte_unused void *data)
4162 {
4163         struct cmd_rx_vlan_filter_result *res = parsed_result;
4164
4165         if (!strcmp(res->what, "add"))
4166                 rx_vft_set(res->port_id, res->vlan_id, 1);
4167         else
4168                 rx_vft_set(res->port_id, res->vlan_id, 0);
4169 }
4170
4171 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4172         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4173                                  rx_vlan, "rx_vlan");
4174 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4175         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4176                                  what, "add#rm");
4177 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4178         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4179                               vlan_id, UINT16);
4180 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4181         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4182                               port_id, UINT16);
4183
4184 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4185         .f = cmd_rx_vlan_filter_parsed,
4186         .data = NULL,
4187         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4188                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4189                 "identifiers filtered by a port",
4190         .tokens = {
4191                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4192                 (void *)&cmd_rx_vlan_filter_what,
4193                 (void *)&cmd_rx_vlan_filter_vlanid,
4194                 (void *)&cmd_rx_vlan_filter_portid,
4195                 NULL,
4196         },
4197 };
4198
4199 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4200 struct cmd_tx_vlan_set_result {
4201         cmdline_fixed_string_t tx_vlan;
4202         cmdline_fixed_string_t set;
4203         portid_t port_id;
4204         uint16_t vlan_id;
4205 };
4206
4207 static void
4208 cmd_tx_vlan_set_parsed(void *parsed_result,
4209                        __rte_unused struct cmdline *cl,
4210                        __rte_unused void *data)
4211 {
4212         struct cmd_tx_vlan_set_result *res = parsed_result;
4213
4214         if (!port_is_stopped(res->port_id)) {
4215                 printf("Please stop port %d first\n", res->port_id);
4216                 return;
4217         }
4218
4219         tx_vlan_set(res->port_id, res->vlan_id);
4220
4221         cmd_reconfig_device_queue(res->port_id, 1, 1);
4222 }
4223
4224 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4225         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4226                                  tx_vlan, "tx_vlan");
4227 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4228         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4229                                  set, "set");
4230 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4231         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4232                               port_id, UINT16);
4233 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4234         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4235                               vlan_id, UINT16);
4236
4237 cmdline_parse_inst_t cmd_tx_vlan_set = {
4238         .f = cmd_tx_vlan_set_parsed,
4239         .data = NULL,
4240         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4241                 "Enable hardware insertion of a single VLAN header "
4242                 "with a given TAG Identifier in packets sent on a port",
4243         .tokens = {
4244                 (void *)&cmd_tx_vlan_set_tx_vlan,
4245                 (void *)&cmd_tx_vlan_set_set,
4246                 (void *)&cmd_tx_vlan_set_portid,
4247                 (void *)&cmd_tx_vlan_set_vlanid,
4248                 NULL,
4249         },
4250 };
4251
4252 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4253 struct cmd_tx_vlan_set_qinq_result {
4254         cmdline_fixed_string_t tx_vlan;
4255         cmdline_fixed_string_t set;
4256         portid_t port_id;
4257         uint16_t vlan_id;
4258         uint16_t vlan_id_outer;
4259 };
4260
4261 static void
4262 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4263                             __rte_unused struct cmdline *cl,
4264                             __rte_unused void *data)
4265 {
4266         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4267
4268         if (!port_is_stopped(res->port_id)) {
4269                 printf("Please stop port %d first\n", res->port_id);
4270                 return;
4271         }
4272
4273         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4274
4275         cmd_reconfig_device_queue(res->port_id, 1, 1);
4276 }
4277
4278 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4279         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4280                 tx_vlan, "tx_vlan");
4281 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4282         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4283                 set, "set");
4284 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4285         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4286                 port_id, UINT16);
4287 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4288         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4289                 vlan_id, UINT16);
4290 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4291         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4292                 vlan_id_outer, UINT16);
4293
4294 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4295         .f = cmd_tx_vlan_set_qinq_parsed,
4296         .data = NULL,
4297         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4298                 "Enable hardware insertion of double VLAN header "
4299                 "with given TAG Identifiers in packets sent on a port",
4300         .tokens = {
4301                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4302                 (void *)&cmd_tx_vlan_set_qinq_set,
4303                 (void *)&cmd_tx_vlan_set_qinq_portid,
4304                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4305                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4306                 NULL,
4307         },
4308 };
4309
4310 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4311 struct cmd_tx_vlan_set_pvid_result {
4312         cmdline_fixed_string_t tx_vlan;
4313         cmdline_fixed_string_t set;
4314         cmdline_fixed_string_t pvid;
4315         portid_t port_id;
4316         uint16_t vlan_id;
4317         cmdline_fixed_string_t mode;
4318 };
4319
4320 static void
4321 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4322                             __rte_unused struct cmdline *cl,
4323                             __rte_unused void *data)
4324 {
4325         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4326
4327         if (strcmp(res->mode, "on") == 0)
4328                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4329         else
4330                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4331 }
4332
4333 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4334         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4335                                  tx_vlan, "tx_vlan");
4336 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4337         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4338                                  set, "set");
4339 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4340         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4341                                  pvid, "pvid");
4342 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4343         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4344                              port_id, UINT16);
4345 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4346         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4347                               vlan_id, UINT16);
4348 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4349         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4350                                  mode, "on#off");
4351
4352 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4353         .f = cmd_tx_vlan_set_pvid_parsed,
4354         .data = NULL,
4355         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4356         .tokens = {
4357                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4358                 (void *)&cmd_tx_vlan_set_pvid_set,
4359                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4360                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4361                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4362                 (void *)&cmd_tx_vlan_set_pvid_mode,
4363                 NULL,
4364         },
4365 };
4366
4367 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4368 struct cmd_tx_vlan_reset_result {
4369         cmdline_fixed_string_t tx_vlan;
4370         cmdline_fixed_string_t reset;
4371         portid_t port_id;
4372 };
4373
4374 static void
4375 cmd_tx_vlan_reset_parsed(void *parsed_result,
4376                          __rte_unused struct cmdline *cl,
4377                          __rte_unused void *data)
4378 {
4379         struct cmd_tx_vlan_reset_result *res = parsed_result;
4380
4381         if (!port_is_stopped(res->port_id)) {
4382                 printf("Please stop port %d first\n", res->port_id);
4383                 return;
4384         }
4385
4386         tx_vlan_reset(res->port_id);
4387
4388         cmd_reconfig_device_queue(res->port_id, 1, 1);
4389 }
4390
4391 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4392         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4393                                  tx_vlan, "tx_vlan");
4394 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4395         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4396                                  reset, "reset");
4397 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4398         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4399                               port_id, UINT16);
4400
4401 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4402         .f = cmd_tx_vlan_reset_parsed,
4403         .data = NULL,
4404         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4405                 "VLAN header in packets sent on a port",
4406         .tokens = {
4407                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4408                 (void *)&cmd_tx_vlan_reset_reset,
4409                 (void *)&cmd_tx_vlan_reset_portid,
4410                 NULL,
4411         },
4412 };
4413
4414
4415 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4416 struct cmd_csum_result {
4417         cmdline_fixed_string_t csum;
4418         cmdline_fixed_string_t mode;
4419         cmdline_fixed_string_t proto;
4420         cmdline_fixed_string_t hwsw;
4421         portid_t port_id;
4422 };
4423
4424 static void
4425 csum_show(int port_id)
4426 {
4427         struct rte_eth_dev_info dev_info;
4428         uint64_t tx_offloads;
4429         int ret;
4430
4431         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4432         printf("Parse tunnel is %s\n",
4433                 (ports[port_id].parse_tunnel) ? "on" : "off");
4434         printf("IP checksum offload is %s\n",
4435                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4436         printf("UDP checksum offload is %s\n",
4437                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4438         printf("TCP checksum offload is %s\n",
4439                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4440         printf("SCTP checksum offload is %s\n",
4441                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4442         printf("Outer-Ip checksum offload is %s\n",
4443                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4444         printf("Outer-Udp checksum offload is %s\n",
4445                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4446
4447         /* display warnings if configuration is not supported by the NIC */
4448         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4449         if (ret != 0)
4450                 return;
4451
4452         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4453                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4454                 printf("Warning: hardware IP checksum enabled but not "
4455                         "supported by port %d\n", port_id);
4456         }
4457         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4458                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4459                 printf("Warning: hardware UDP checksum enabled but not "
4460                         "supported by port %d\n", port_id);
4461         }
4462         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4463                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4464                 printf("Warning: hardware TCP checksum enabled but not "
4465                         "supported by port %d\n", port_id);
4466         }
4467         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4468                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4469                 printf("Warning: hardware SCTP checksum enabled but not "
4470                         "supported by port %d\n", port_id);
4471         }
4472         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4473                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4474                 printf("Warning: hardware outer IP checksum enabled but not "
4475                         "supported by port %d\n", port_id);
4476         }
4477         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4478                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4479                         == 0) {
4480                 printf("Warning: hardware outer UDP checksum enabled but not "
4481                         "supported by port %d\n", port_id);
4482         }
4483 }
4484
4485 static void
4486 cmd_config_queue_tx_offloads(struct rte_port *port)
4487 {
4488         int k;
4489
4490         /* Apply queue tx offloads configuration */
4491         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4492                 port->tx_conf[k].offloads =
4493                         port->dev_conf.txmode.offloads;
4494 }
4495
4496 static void
4497 cmd_csum_parsed(void *parsed_result,
4498                        __rte_unused struct cmdline *cl,
4499                        __rte_unused void *data)
4500 {
4501         struct cmd_csum_result *res = parsed_result;
4502         int hw = 0;
4503         uint64_t csum_offloads = 0;
4504         struct rte_eth_dev_info dev_info;
4505         int ret;
4506
4507         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4508                 printf("invalid port %d\n", res->port_id);
4509                 return;
4510         }
4511         if (!port_is_stopped(res->port_id)) {
4512                 printf("Please stop port %d first\n", res->port_id);
4513                 return;
4514         }
4515
4516         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4517         if (ret != 0)
4518                 return;
4519
4520         if (!strcmp(res->mode, "set")) {
4521
4522                 if (!strcmp(res->hwsw, "hw"))
4523                         hw = 1;
4524
4525                 if (!strcmp(res->proto, "ip")) {
4526                         if (hw == 0 || (dev_info.tx_offload_capa &
4527                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4528                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4529                         } else {
4530                                 printf("IP checksum offload is not supported "
4531                                        "by port %u\n", res->port_id);
4532                         }
4533                 } else if (!strcmp(res->proto, "udp")) {
4534                         if (hw == 0 || (dev_info.tx_offload_capa &
4535                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4536                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4537                         } else {
4538                                 printf("UDP checksum offload is not supported "
4539                                        "by port %u\n", res->port_id);
4540                         }
4541                 } else if (!strcmp(res->proto, "tcp")) {
4542                         if (hw == 0 || (dev_info.tx_offload_capa &
4543                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4544                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4545                         } else {
4546                                 printf("TCP checksum offload is not supported "
4547                                        "by port %u\n", res->port_id);
4548                         }
4549                 } else if (!strcmp(res->proto, "sctp")) {
4550                         if (hw == 0 || (dev_info.tx_offload_capa &
4551                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4552                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4553                         } else {
4554                                 printf("SCTP checksum offload is not supported "
4555                                        "by port %u\n", res->port_id);
4556                         }
4557                 } else if (!strcmp(res->proto, "outer-ip")) {
4558                         if (hw == 0 || (dev_info.tx_offload_capa &
4559                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4560                                 csum_offloads |=
4561                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4562                         } else {
4563                                 printf("Outer IP checksum offload is not "
4564                                        "supported by port %u\n", res->port_id);
4565                         }
4566                 } else if (!strcmp(res->proto, "outer-udp")) {
4567                         if (hw == 0 || (dev_info.tx_offload_capa &
4568                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4569                                 csum_offloads |=
4570                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4571                         } else {
4572                                 printf("Outer UDP checksum offload is not "
4573                                        "supported by port %u\n", res->port_id);
4574                         }
4575                 }
4576
4577                 if (hw) {
4578                         ports[res->port_id].dev_conf.txmode.offloads |=
4579                                                         csum_offloads;
4580                 } else {
4581                         ports[res->port_id].dev_conf.txmode.offloads &=
4582                                                         (~csum_offloads);
4583                 }
4584                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4585         }
4586         csum_show(res->port_id);
4587
4588         cmd_reconfig_device_queue(res->port_id, 1, 1);
4589 }
4590
4591 cmdline_parse_token_string_t cmd_csum_csum =
4592         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4593                                 csum, "csum");
4594 cmdline_parse_token_string_t cmd_csum_mode =
4595         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4596                                 mode, "set");
4597 cmdline_parse_token_string_t cmd_csum_proto =
4598         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4599                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4600 cmdline_parse_token_string_t cmd_csum_hwsw =
4601         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4602                                 hwsw, "hw#sw");
4603 cmdline_parse_token_num_t cmd_csum_portid =
4604         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4605                                 port_id, UINT16);
4606
4607 cmdline_parse_inst_t cmd_csum_set = {
4608         .f = cmd_csum_parsed,
4609         .data = NULL,
4610         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4611                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4612                 "using csum forward engine",
4613         .tokens = {
4614                 (void *)&cmd_csum_csum,
4615                 (void *)&cmd_csum_mode,
4616                 (void *)&cmd_csum_proto,
4617                 (void *)&cmd_csum_hwsw,
4618                 (void *)&cmd_csum_portid,
4619                 NULL,
4620         },
4621 };
4622
4623 cmdline_parse_token_string_t cmd_csum_mode_show =
4624         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4625                                 mode, "show");
4626
4627 cmdline_parse_inst_t cmd_csum_show = {
4628         .f = cmd_csum_parsed,
4629         .data = NULL,
4630         .help_str = "csum show <port_id>: Show checksum offload configuration",
4631         .tokens = {
4632                 (void *)&cmd_csum_csum,
4633                 (void *)&cmd_csum_mode_show,
4634                 (void *)&cmd_csum_portid,
4635                 NULL,
4636         },
4637 };
4638
4639 /* Enable/disable tunnel parsing */
4640 struct cmd_csum_tunnel_result {
4641         cmdline_fixed_string_t csum;
4642         cmdline_fixed_string_t parse;
4643         cmdline_fixed_string_t onoff;
4644         portid_t port_id;
4645 };
4646
4647 static void
4648 cmd_csum_tunnel_parsed(void *parsed_result,
4649                        __rte_unused struct cmdline *cl,
4650                        __rte_unused void *data)
4651 {
4652         struct cmd_csum_tunnel_result *res = parsed_result;
4653
4654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4655                 return;
4656
4657         if (!strcmp(res->onoff, "on"))
4658                 ports[res->port_id].parse_tunnel = 1;
4659         else
4660                 ports[res->port_id].parse_tunnel = 0;
4661
4662         csum_show(res->port_id);
4663 }
4664
4665 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4666         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4667                                 csum, "csum");
4668 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4669         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4670                                 parse, "parse-tunnel");
4671 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4672         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4673                                 onoff, "on#off");
4674 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4675         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4676                                 port_id, UINT16);
4677
4678 cmdline_parse_inst_t cmd_csum_tunnel = {
4679         .f = cmd_csum_tunnel_parsed,
4680         .data = NULL,
4681         .help_str = "csum parse-tunnel on|off <port_id>: "
4682                 "Enable/Disable parsing of tunnels for csum engine",
4683         .tokens = {
4684                 (void *)&cmd_csum_tunnel_csum,
4685                 (void *)&cmd_csum_tunnel_parse,
4686                 (void *)&cmd_csum_tunnel_onoff,
4687                 (void *)&cmd_csum_tunnel_portid,
4688                 NULL,
4689         },
4690 };
4691
4692 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4693 struct cmd_tso_set_result {
4694         cmdline_fixed_string_t tso;
4695         cmdline_fixed_string_t mode;
4696         uint16_t tso_segsz;
4697         portid_t port_id;
4698 };
4699
4700 static void
4701 cmd_tso_set_parsed(void *parsed_result,
4702                        __rte_unused struct cmdline *cl,
4703                        __rte_unused void *data)
4704 {
4705         struct cmd_tso_set_result *res = parsed_result;
4706         struct rte_eth_dev_info dev_info;
4707         int ret;
4708
4709         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4710                 return;
4711         if (!port_is_stopped(res->port_id)) {
4712                 printf("Please stop port %d first\n", res->port_id);
4713                 return;
4714         }
4715
4716         if (!strcmp(res->mode, "set"))
4717                 ports[res->port_id].tso_segsz = res->tso_segsz;
4718
4719         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4720         if (ret != 0)
4721                 return;
4722
4723         if ((ports[res->port_id].tso_segsz != 0) &&
4724                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4725                 printf("Error: TSO is not supported by port %d\n",
4726                        res->port_id);
4727                 return;
4728         }
4729
4730         if (ports[res->port_id].tso_segsz == 0) {
4731                 ports[res->port_id].dev_conf.txmode.offloads &=
4732                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4733                 printf("TSO for non-tunneled packets is disabled\n");
4734         } else {
4735                 ports[res->port_id].dev_conf.txmode.offloads |=
4736                                                 DEV_TX_OFFLOAD_TCP_TSO;
4737                 printf("TSO segment size for non-tunneled packets is %d\n",
4738                         ports[res->port_id].tso_segsz);
4739         }
4740         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4741
4742         /* display warnings if configuration is not supported by the NIC */
4743         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4744         if (ret != 0)
4745                 return;
4746
4747         if ((ports[res->port_id].tso_segsz != 0) &&
4748                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4749                 printf("Warning: TSO enabled but not "
4750                         "supported by port %d\n", res->port_id);
4751         }
4752
4753         cmd_reconfig_device_queue(res->port_id, 1, 1);
4754 }
4755
4756 cmdline_parse_token_string_t cmd_tso_set_tso =
4757         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4758                                 tso, "tso");
4759 cmdline_parse_token_string_t cmd_tso_set_mode =
4760         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4761                                 mode, "set");
4762 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4763         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4764                                 tso_segsz, UINT16);
4765 cmdline_parse_token_num_t cmd_tso_set_portid =
4766         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4767                                 port_id, UINT16);
4768
4769 cmdline_parse_inst_t cmd_tso_set = {
4770         .f = cmd_tso_set_parsed,
4771         .data = NULL,
4772         .help_str = "tso set <tso_segsz> <port_id>: "
4773                 "Set TSO segment size of non-tunneled packets for csum engine "
4774                 "(0 to disable)",
4775         .tokens = {
4776                 (void *)&cmd_tso_set_tso,
4777                 (void *)&cmd_tso_set_mode,
4778                 (void *)&cmd_tso_set_tso_segsz,
4779                 (void *)&cmd_tso_set_portid,
4780                 NULL,
4781         },
4782 };
4783
4784 cmdline_parse_token_string_t cmd_tso_show_mode =
4785         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4786                                 mode, "show");
4787
4788
4789 cmdline_parse_inst_t cmd_tso_show = {
4790         .f = cmd_tso_set_parsed,
4791         .data = NULL,
4792         .help_str = "tso show <port_id>: "
4793                 "Show TSO segment size of non-tunneled packets for csum engine",
4794         .tokens = {
4795                 (void *)&cmd_tso_set_tso,
4796                 (void *)&cmd_tso_show_mode,
4797                 (void *)&cmd_tso_set_portid,
4798                 NULL,
4799         },
4800 };
4801
4802 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4803 struct cmd_tunnel_tso_set_result {
4804         cmdline_fixed_string_t tso;
4805         cmdline_fixed_string_t mode;
4806         uint16_t tso_segsz;
4807         portid_t port_id;
4808 };
4809
4810 static struct rte_eth_dev_info
4811 check_tunnel_tso_nic_support(portid_t port_id)
4812 {
4813         struct rte_eth_dev_info dev_info;
4814
4815         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4816                 return dev_info;
4817
4818         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4819                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4820                        "not enabled for port %d\n", port_id);
4821         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4822                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4823                        "not enabled for port %d\n", port_id);
4824         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4825                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4826                        "not enabled for port %d\n", port_id);
4827         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4828                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4829                        "not enabled for port %d\n", port_id);
4830         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4831                 printf("Warning: IP TUNNEL TSO not supported therefore "
4832                        "not enabled for port %d\n", port_id);
4833         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4834                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4835                        "not enabled for port %d\n", port_id);
4836         return dev_info;
4837 }
4838
4839 static void
4840 cmd_tunnel_tso_set_parsed(void *parsed_result,
4841                           __rte_unused struct cmdline *cl,
4842                           __rte_unused void *data)
4843 {
4844         struct cmd_tunnel_tso_set_result *res = parsed_result;
4845         struct rte_eth_dev_info dev_info;
4846
4847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4848                 return;
4849         if (!port_is_stopped(res->port_id)) {
4850                 printf("Please stop port %d first\n", res->port_id);
4851                 return;
4852         }
4853
4854         if (!strcmp(res->mode, "set"))
4855                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4856
4857         dev_info = check_tunnel_tso_nic_support(res->port_id);
4858         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4859                 ports[res->port_id].dev_conf.txmode.offloads &=
4860                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4861                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4862                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4863                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4864                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4865                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4866                 printf("TSO for tunneled packets is disabled\n");
4867         } else {
4868                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4869                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4870                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4871                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4872                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4873                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4874
4875                 ports[res->port_id].dev_conf.txmode.offloads |=
4876                         (tso_offloads & dev_info.tx_offload_capa);
4877                 printf("TSO segment size for tunneled packets is %d\n",
4878                         ports[res->port_id].tunnel_tso_segsz);
4879
4880                 /* Below conditions are needed to make it work:
4881                  * (1) tunnel TSO is supported by the NIC;
4882                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4883                  * are recognized;
4884                  * (3) for tunneled pkts with outer L3 of IPv4,
4885                  * "csum set outer-ip" must be set to hw, because after tso,
4886                  * total_len of outer IP header is changed, and the checksum
4887                  * of outer IP header calculated by sw should be wrong; that
4888                  * is not necessary for IPv6 tunneled pkts because there's no
4889                  * checksum in IP header anymore.
4890                  */
4891
4892                 if (!ports[res->port_id].parse_tunnel)
4893                         printf("Warning: csum parse_tunnel must be set "
4894                                 "so that tunneled packets are recognized\n");
4895                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4896                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4897                         printf("Warning: csum set outer-ip must be set to hw "
4898                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4899         }
4900
4901         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4902         cmd_reconfig_device_queue(res->port_id, 1, 1);
4903 }
4904
4905 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4906         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4907                                 tso, "tunnel_tso");
4908 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4909         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4910                                 mode, "set");
4911 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4912         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4913                                 tso_segsz, UINT16);
4914 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4915         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4916                                 port_id, UINT16);
4917
4918 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4919         .f = cmd_tunnel_tso_set_parsed,
4920         .data = NULL,
4921         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4922                 "Set TSO segment size of tunneled packets for csum engine "
4923                 "(0 to disable)",
4924         .tokens = {
4925                 (void *)&cmd_tunnel_tso_set_tso,
4926                 (void *)&cmd_tunnel_tso_set_mode,
4927                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4928                 (void *)&cmd_tunnel_tso_set_portid,
4929                 NULL,
4930         },
4931 };
4932
4933 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4934         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4935                                 mode, "show");
4936
4937
4938 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4939         .f = cmd_tunnel_tso_set_parsed,
4940         .data = NULL,
4941         .help_str = "tunnel_tso show <port_id> "
4942                 "Show TSO segment size of tunneled packets for csum engine",
4943         .tokens = {
4944                 (void *)&cmd_tunnel_tso_set_tso,
4945                 (void *)&cmd_tunnel_tso_show_mode,
4946                 (void *)&cmd_tunnel_tso_set_portid,
4947                 NULL,
4948         },
4949 };
4950
4951 /* *** SET GRO FOR A PORT *** */
4952 struct cmd_gro_enable_result {
4953         cmdline_fixed_string_t cmd_set;
4954         cmdline_fixed_string_t cmd_port;
4955         cmdline_fixed_string_t cmd_keyword;
4956         cmdline_fixed_string_t cmd_onoff;
4957         portid_t cmd_pid;
4958 };
4959
4960 static void
4961 cmd_gro_enable_parsed(void *parsed_result,
4962                 __rte_unused struct cmdline *cl,
4963                 __rte_unused void *data)
4964 {
4965         struct cmd_gro_enable_result *res;
4966
4967         res = parsed_result;
4968         if (!strcmp(res->cmd_keyword, "gro"))
4969                 setup_gro(res->cmd_onoff, res->cmd_pid);
4970 }
4971
4972 cmdline_parse_token_string_t cmd_gro_enable_set =
4973         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4974                         cmd_set, "set");
4975 cmdline_parse_token_string_t cmd_gro_enable_port =
4976         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4977                         cmd_keyword, "port");
4978 cmdline_parse_token_num_t cmd_gro_enable_pid =
4979         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4980                         cmd_pid, UINT16);
4981 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4982         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4983                         cmd_keyword, "gro");
4984 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4985         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4986                         cmd_onoff, "on#off");
4987
4988 cmdline_parse_inst_t cmd_gro_enable = {
4989         .f = cmd_gro_enable_parsed,
4990         .data = NULL,
4991         .help_str = "set port <port_id> gro on|off",
4992         .tokens = {
4993                 (void *)&cmd_gro_enable_set,
4994                 (void *)&cmd_gro_enable_port,
4995                 (void *)&cmd_gro_enable_pid,
4996                 (void *)&cmd_gro_enable_keyword,
4997                 (void *)&cmd_gro_enable_onoff,
4998                 NULL,
4999         },
5000 };
5001
5002 /* *** DISPLAY GRO CONFIGURATION *** */
5003 struct cmd_gro_show_result {
5004         cmdline_fixed_string_t cmd_show;
5005         cmdline_fixed_string_t cmd_port;
5006         cmdline_fixed_string_t cmd_keyword;
5007         portid_t cmd_pid;
5008 };
5009
5010 static void
5011 cmd_gro_show_parsed(void *parsed_result,
5012                 __rte_unused struct cmdline *cl,
5013                 __rte_unused void *data)
5014 {
5015         struct cmd_gro_show_result *res;
5016
5017         res = parsed_result;
5018         if (!strcmp(res->cmd_keyword, "gro"))
5019                 show_gro(res->cmd_pid);
5020 }
5021
5022 cmdline_parse_token_string_t cmd_gro_show_show =
5023         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5024                         cmd_show, "show");
5025 cmdline_parse_token_string_t cmd_gro_show_port =
5026         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5027                         cmd_port, "port");
5028 cmdline_parse_token_num_t cmd_gro_show_pid =
5029         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5030                         cmd_pid, UINT16);
5031 cmdline_parse_token_string_t cmd_gro_show_keyword =
5032         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5033                         cmd_keyword, "gro");
5034
5035 cmdline_parse_inst_t cmd_gro_show = {
5036         .f = cmd_gro_show_parsed,
5037         .data = NULL,
5038         .help_str = "show port <port_id> gro",
5039         .tokens = {
5040                 (void *)&cmd_gro_show_show,
5041                 (void *)&cmd_gro_show_port,
5042                 (void *)&cmd_gro_show_pid,
5043                 (void *)&cmd_gro_show_keyword,
5044                 NULL,
5045         },
5046 };
5047
5048 /* *** SET FLUSH CYCLES FOR GRO *** */
5049 struct cmd_gro_flush_result {
5050         cmdline_fixed_string_t cmd_set;
5051         cmdline_fixed_string_t cmd_keyword;
5052         cmdline_fixed_string_t cmd_flush;
5053         uint8_t cmd_cycles;
5054 };
5055
5056 static void
5057 cmd_gro_flush_parsed(void *parsed_result,
5058                 __rte_unused struct cmdline *cl,
5059                 __rte_unused void *data)
5060 {
5061         struct cmd_gro_flush_result *res;
5062
5063         res = parsed_result;
5064         if ((!strcmp(res->cmd_keyword, "gro")) &&
5065                         (!strcmp(res->cmd_flush, "flush")))
5066                 setup_gro_flush_cycles(res->cmd_cycles);
5067 }
5068
5069 cmdline_parse_token_string_t cmd_gro_flush_set =
5070         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5071                         cmd_set, "set");
5072 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5073         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5074                         cmd_keyword, "gro");
5075 cmdline_parse_token_string_t cmd_gro_flush_flush =
5076         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5077                         cmd_flush, "flush");
5078 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5079         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5080                         cmd_cycles, UINT8);
5081
5082 cmdline_parse_inst_t cmd_gro_flush = {
5083         .f = cmd_gro_flush_parsed,
5084         .data = NULL,
5085         .help_str = "set gro flush <cycles>",
5086         .tokens = {
5087                 (void *)&cmd_gro_flush_set,
5088                 (void *)&cmd_gro_flush_keyword,
5089                 (void *)&cmd_gro_flush_flush,
5090                 (void *)&cmd_gro_flush_cycles,
5091                 NULL,
5092         },
5093 };
5094
5095 /* *** ENABLE/DISABLE GSO *** */
5096 struct cmd_gso_enable_result {
5097         cmdline_fixed_string_t cmd_set;
5098         cmdline_fixed_string_t cmd_port;
5099         cmdline_fixed_string_t cmd_keyword;
5100         cmdline_fixed_string_t cmd_mode;
5101         portid_t cmd_pid;
5102 };
5103
5104 static void
5105 cmd_gso_enable_parsed(void *parsed_result,
5106                 __rte_unused struct cmdline *cl,
5107                 __rte_unused void *data)
5108 {
5109         struct cmd_gso_enable_result *res;
5110
5111         res = parsed_result;
5112         if (!strcmp(res->cmd_keyword, "gso"))
5113                 setup_gso(res->cmd_mode, res->cmd_pid);
5114 }
5115
5116 cmdline_parse_token_string_t cmd_gso_enable_set =
5117         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5118                         cmd_set, "set");
5119 cmdline_parse_token_string_t cmd_gso_enable_port =
5120         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5121                         cmd_port, "port");
5122 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5123         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5124                         cmd_keyword, "gso");
5125 cmdline_parse_token_string_t cmd_gso_enable_mode =
5126         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5127                         cmd_mode, "on#off");
5128 cmdline_parse_token_num_t cmd_gso_enable_pid =
5129         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5130                         cmd_pid, UINT16);
5131
5132 cmdline_parse_inst_t cmd_gso_enable = {
5133         .f = cmd_gso_enable_parsed,
5134         .data = NULL,
5135         .help_str = "set port <port_id> gso on|off",
5136         .tokens = {
5137                 (void *)&cmd_gso_enable_set,
5138                 (void *)&cmd_gso_enable_port,
5139                 (void *)&cmd_gso_enable_pid,
5140                 (void *)&cmd_gso_enable_keyword,
5141                 (void *)&cmd_gso_enable_mode,
5142                 NULL,
5143         },
5144 };
5145
5146 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5147 struct cmd_gso_size_result {
5148         cmdline_fixed_string_t cmd_set;
5149         cmdline_fixed_string_t cmd_keyword;
5150         cmdline_fixed_string_t cmd_segsz;
5151         uint16_t cmd_size;
5152 };
5153
5154 static void
5155 cmd_gso_size_parsed(void *parsed_result,
5156                        __rte_unused struct cmdline *cl,
5157                        __rte_unused void *data)
5158 {
5159         struct cmd_gso_size_result *res = parsed_result;
5160
5161         if (test_done == 0) {
5162                 printf("Before setting GSO segsz, please first"
5163                                 " stop forwarding\n");
5164                 return;
5165         }
5166
5167         if (!strcmp(res->cmd_keyword, "gso") &&
5168                         !strcmp(res->cmd_segsz, "segsz")) {
5169                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5170                         printf("gso_size should be larger than %zu."
5171                                         " Please input a legal value\n",
5172                                         RTE_GSO_SEG_SIZE_MIN);
5173                 else
5174                         gso_max_segment_size = res->cmd_size;
5175         }
5176 }
5177
5178 cmdline_parse_token_string_t cmd_gso_size_set =
5179         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5180                                 cmd_set, "set");
5181 cmdline_parse_token_string_t cmd_gso_size_keyword =
5182         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5183                                 cmd_keyword, "gso");
5184 cmdline_parse_token_string_t cmd_gso_size_segsz =
5185         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5186                                 cmd_segsz, "segsz");
5187 cmdline_parse_token_num_t cmd_gso_size_size =
5188         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5189                                 cmd_size, UINT16);
5190
5191 cmdline_parse_inst_t cmd_gso_size = {
5192         .f = cmd_gso_size_parsed,
5193         .data = NULL,
5194         .help_str = "set gso segsz <length>",
5195         .tokens = {
5196                 (void *)&cmd_gso_size_set,
5197                 (void *)&cmd_gso_size_keyword,
5198                 (void *)&cmd_gso_size_segsz,
5199                 (void *)&cmd_gso_size_size,
5200                 NULL,
5201         },
5202 };
5203
5204 /* *** SHOW GSO CONFIGURATION *** */
5205 struct cmd_gso_show_result {
5206         cmdline_fixed_string_t cmd_show;
5207         cmdline_fixed_string_t cmd_port;
5208         cmdline_fixed_string_t cmd_keyword;
5209         portid_t cmd_pid;
5210 };
5211
5212 static void
5213 cmd_gso_show_parsed(void *parsed_result,
5214                        __rte_unused struct cmdline *cl,
5215                        __rte_unused void *data)
5216 {
5217         struct cmd_gso_show_result *res = parsed_result;
5218
5219         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5220                 printf("invalid port id %u\n", res->cmd_pid);
5221                 return;
5222         }
5223         if (!strcmp(res->cmd_keyword, "gso")) {
5224                 if (gso_ports[res->cmd_pid].enable) {
5225                         printf("Max GSO'd packet size: %uB\n"
5226                                         "Supported GSO types: TCP/IPv4, "
5227                                         "UDP/IPv4, VxLAN with inner "
5228                                         "TCP/IPv4 packet, GRE with inner "
5229                                         "TCP/IPv4 packet\n",
5230                                         gso_max_segment_size);
5231                 } else
5232                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5233         }
5234 }
5235
5236 cmdline_parse_token_string_t cmd_gso_show_show =
5237 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5238                 cmd_show, "show");
5239 cmdline_parse_token_string_t cmd_gso_show_port =
5240 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5241                 cmd_port, "port");
5242 cmdline_parse_token_string_t cmd_gso_show_keyword =
5243         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5244                                 cmd_keyword, "gso");
5245 cmdline_parse_token_num_t cmd_gso_show_pid =
5246         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5247                                 cmd_pid, UINT16);
5248
5249 cmdline_parse_inst_t cmd_gso_show = {
5250         .f = cmd_gso_show_parsed,
5251         .data = NULL,
5252         .help_str = "show port <port_id> gso",
5253         .tokens = {
5254                 (void *)&cmd_gso_show_show,
5255                 (void *)&cmd_gso_show_port,
5256                 (void *)&cmd_gso_show_pid,
5257                 (void *)&cmd_gso_show_keyword,
5258                 NULL,
5259         },
5260 };
5261
5262 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5263 struct cmd_set_flush_rx {
5264         cmdline_fixed_string_t set;
5265         cmdline_fixed_string_t flush_rx;
5266         cmdline_fixed_string_t mode;
5267 };
5268
5269 static void
5270 cmd_set_flush_rx_parsed(void *parsed_result,
5271                 __rte_unused struct cmdline *cl,
5272                 __rte_unused void *data)
5273 {
5274         struct cmd_set_flush_rx *res = parsed_result;
5275         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5276 }
5277
5278 cmdline_parse_token_string_t cmd_setflushrx_set =
5279         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5280                         set, "set");
5281 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5282         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5283                         flush_rx, "flush_rx");
5284 cmdline_parse_token_string_t cmd_setflushrx_mode =
5285         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5286                         mode, "on#off");
5287
5288
5289 cmdline_parse_inst_t cmd_set_flush_rx = {
5290         .f = cmd_set_flush_rx_parsed,
5291         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5292         .data = NULL,
5293         .tokens = {
5294                 (void *)&cmd_setflushrx_set,
5295                 (void *)&cmd_setflushrx_flush_rx,
5296                 (void *)&cmd_setflushrx_mode,
5297                 NULL,
5298         },
5299 };
5300
5301 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5302 struct cmd_set_link_check {
5303         cmdline_fixed_string_t set;
5304         cmdline_fixed_string_t link_check;
5305         cmdline_fixed_string_t mode;
5306 };
5307
5308 static void
5309 cmd_set_link_check_parsed(void *parsed_result,
5310                 __rte_unused struct cmdline *cl,
5311                 __rte_unused void *data)
5312 {
5313         struct cmd_set_link_check *res = parsed_result;
5314         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5315 }
5316
5317 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5318         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5319                         set, "set");
5320 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5321         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5322                         link_check, "link_check");
5323 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5324         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5325                         mode, "on#off");
5326
5327
5328 cmdline_parse_inst_t cmd_set_link_check = {
5329         .f = cmd_set_link_check_parsed,
5330         .help_str = "set link_check on|off: Enable/Disable link status check "
5331                     "when starting/stopping a port",
5332         .data = NULL,
5333         .tokens = {
5334                 (void *)&cmd_setlinkcheck_set,
5335                 (void *)&cmd_setlinkcheck_link_check,
5336                 (void *)&cmd_setlinkcheck_mode,
5337                 NULL,
5338         },
5339 };
5340
5341 /* *** SET NIC BYPASS MODE *** */
5342 struct cmd_set_bypass_mode_result {
5343         cmdline_fixed_string_t set;
5344         cmdline_fixed_string_t bypass;
5345         cmdline_fixed_string_t mode;
5346         cmdline_fixed_string_t value;
5347         portid_t port_id;
5348 };
5349
5350 static void
5351 cmd_set_bypass_mode_parsed(void *parsed_result,
5352                 __rte_unused struct cmdline *cl,
5353                 __rte_unused void *data)
5354 {
5355         struct cmd_set_bypass_mode_result *res = parsed_result;
5356         portid_t port_id = res->port_id;
5357         int32_t rc = -EINVAL;
5358
5359 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5360         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5361
5362         if (!strcmp(res->value, "bypass"))
5363                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5364         else if (!strcmp(res->value, "isolate"))
5365                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5366         else
5367                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5368
5369         /* Set the bypass mode for the relevant port. */
5370         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5371 #endif
5372         if (rc != 0)
5373                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5374 }
5375
5376 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5377         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5378                         set, "set");
5379 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5380         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5381                         bypass, "bypass");
5382 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5383         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5384                         mode, "mode");
5385 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5386         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5387                         value, "normal#bypass#isolate");
5388 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5389         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5390                                 port_id, UINT16);
5391
5392 cmdline_parse_inst_t cmd_set_bypass_mode = {
5393         .f = cmd_set_bypass_mode_parsed,
5394         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5395                     "Set the NIC bypass mode for port_id",
5396         .data = NULL,
5397         .tokens = {
5398                 (void *)&cmd_setbypass_mode_set,
5399                 (void *)&cmd_setbypass_mode_bypass,
5400                 (void *)&cmd_setbypass_mode_mode,
5401                 (void *)&cmd_setbypass_mode_value,
5402                 (void *)&cmd_setbypass_mode_port,
5403                 NULL,
5404         },
5405 };
5406
5407 /* *** SET NIC BYPASS EVENT *** */
5408 struct cmd_set_bypass_event_result {
5409         cmdline_fixed_string_t set;
5410         cmdline_fixed_string_t bypass;
5411         cmdline_fixed_string_t event;
5412         cmdline_fixed_string_t event_value;
5413         cmdline_fixed_string_t mode;
5414         cmdline_fixed_string_t mode_value;
5415         portid_t port_id;
5416 };
5417
5418 static void
5419 cmd_set_bypass_event_parsed(void *parsed_result,
5420                 __rte_unused struct cmdline *cl,
5421                 __rte_unused void *data)
5422 {
5423         int32_t rc = -EINVAL;
5424         struct cmd_set_bypass_event_result *res = parsed_result;
5425         portid_t port_id = res->port_id;
5426
5427 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5428         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5429         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5430
5431         if (!strcmp(res->event_value, "timeout"))
5432                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5433         else if (!strcmp(res->event_value, "os_on"))
5434                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5435         else if (!strcmp(res->event_value, "os_off"))
5436                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5437         else if (!strcmp(res->event_value, "power_on"))
5438                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5439         else if (!strcmp(res->event_value, "power_off"))
5440                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5441         else
5442                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5443
5444         if (!strcmp(res->mode_value, "bypass"))
5445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5446         else if (!strcmp(res->mode_value, "isolate"))
5447                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5448         else
5449                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5450
5451         /* Set the watchdog timeout. */
5452         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5453
5454                 rc = -EINVAL;
5455                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5456                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5457                                                            bypass_timeout);
5458                 }
5459                 if (rc != 0) {
5460                         printf("Failed to set timeout value %u "
5461                         "for port %d, errto code: %d.\n",
5462                         bypass_timeout, port_id, rc);
5463                 }
5464         }
5465
5466         /* Set the bypass event to transition to bypass mode. */
5467         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5468                                               bypass_mode);
5469 #endif
5470
5471         if (rc != 0)
5472                 printf("\t Failed to set bypass event for port = %d.\n",
5473                        port_id);
5474 }
5475
5476 cmdline_parse_token_string_t cmd_setbypass_event_set =
5477         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5478                         set, "set");
5479 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5480         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5481                         bypass, "bypass");
5482 cmdline_parse_token_string_t cmd_setbypass_event_event =
5483         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5484                         event, "event");
5485 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5486         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5487                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5488 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5489         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5490                         mode, "mode");
5491 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5493                         mode_value, "normal#bypass#isolate");
5494 cmdline_parse_token_num_t cmd_setbypass_event_port =
5495         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5496                                 port_id, UINT16);
5497
5498 cmdline_parse_inst_t cmd_set_bypass_event = {
5499         .f = cmd_set_bypass_event_parsed,
5500         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5501                 "power_off mode normal|bypass|isolate <port_id>: "
5502                 "Set the NIC bypass event mode for port_id",
5503         .data = NULL,
5504         .tokens = {
5505                 (void *)&cmd_setbypass_event_set,
5506                 (void *)&cmd_setbypass_event_bypass,
5507                 (void *)&cmd_setbypass_event_event,
5508                 (void *)&cmd_setbypass_event_event_value,
5509                 (void *)&cmd_setbypass_event_mode,
5510                 (void *)&cmd_setbypass_event_mode_value,
5511                 (void *)&cmd_setbypass_event_port,
5512                 NULL,
5513         },
5514 };
5515
5516
5517 /* *** SET NIC BYPASS TIMEOUT *** */
5518 struct cmd_set_bypass_timeout_result {
5519         cmdline_fixed_string_t set;
5520         cmdline_fixed_string_t bypass;
5521         cmdline_fixed_string_t timeout;
5522         cmdline_fixed_string_t value;
5523 };
5524
5525 static void
5526 cmd_set_bypass_timeout_parsed(void *parsed_result,
5527                 __rte_unused struct cmdline *cl,
5528                 __rte_unused void *data)
5529 {
5530         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5531
5532 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5533         if (!strcmp(res->value, "1.5"))
5534                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5535         else if (!strcmp(res->value, "2"))
5536                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5537         else if (!strcmp(res->value, "3"))
5538                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5539         else if (!strcmp(res->value, "4"))
5540                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5541         else if (!strcmp(res->value, "8"))
5542                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5543         else if (!strcmp(res->value, "16"))
5544                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5545         else if (!strcmp(res->value, "32"))
5546                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5547         else
5548                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5549 #endif
5550 }
5551
5552 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5554                         set, "set");
5555 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5557                         bypass, "bypass");
5558 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5560                         timeout, "timeout");
5561 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5563                         value, "0#1.5#2#3#4#8#16#32");
5564
5565 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5566         .f = cmd_set_bypass_timeout_parsed,
5567         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5568                 "Set the NIC bypass watchdog timeout in seconds",
5569         .data = NULL,
5570         .tokens = {
5571                 (void *)&cmd_setbypass_timeout_set,
5572                 (void *)&cmd_setbypass_timeout_bypass,
5573                 (void *)&cmd_setbypass_timeout_timeout,
5574                 (void *)&cmd_setbypass_timeout_value,
5575                 NULL,
5576         },
5577 };
5578
5579 /* *** SHOW NIC BYPASS MODE *** */
5580 struct cmd_show_bypass_config_result {
5581         cmdline_fixed_string_t show;
5582         cmdline_fixed_string_t bypass;
5583         cmdline_fixed_string_t config;
5584         portid_t port_id;
5585 };
5586
5587 static void
5588 cmd_show_bypass_config_parsed(void *parsed_result,
5589                 __rte_unused struct cmdline *cl,
5590                 __rte_unused void *data)
5591 {
5592         struct cmd_show_bypass_config_result *res = parsed_result;
5593         portid_t port_id = res->port_id;
5594         int rc = -EINVAL;
5595 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5596         uint32_t event_mode;
5597         uint32_t bypass_mode;
5598         uint32_t timeout = bypass_timeout;
5599         unsigned int i;
5600
5601         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5602                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5603         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5604                 {"UNKNOWN", "normal", "bypass", "isolate"};
5605         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5606                 "NONE",
5607                 "OS/board on",
5608                 "power supply on",
5609                 "OS/board off",
5610                 "power supply off",
5611                 "timeout"};
5612
5613         /* Display the bypass mode.*/
5614         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5615                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5616                 return;
5617         }
5618         else {
5619                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5620                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5621
5622                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5623         }
5624
5625         /* Display the bypass timeout.*/
5626         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5627                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5628
5629         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5630
5631         /* Display the bypass events and associated modes. */
5632         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5633
5634                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5635                         printf("\tFailed to get bypass mode for event = %s\n",
5636                                 events[i]);
5637                 } else {
5638                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5639                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5640
5641                         printf("\tbypass event: %-16s = %s\n", events[i],
5642                                 modes[event_mode]);
5643                 }
5644         }
5645 #endif
5646         if (rc != 0)
5647                 printf("\tFailed to get bypass configuration for port = %d\n",
5648                        port_id);
5649 }
5650
5651 cmdline_parse_token_string_t cmd_showbypass_config_show =
5652         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5653                         show, "show");
5654 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5655         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5656                         bypass, "bypass");
5657 cmdline_parse_token_string_t cmd_showbypass_config_config =
5658         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5659                         config, "config");
5660 cmdline_parse_token_num_t cmd_showbypass_config_port =
5661         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5662                                 port_id, UINT16);
5663
5664 cmdline_parse_inst_t cmd_show_bypass_config = {
5665         .f = cmd_show_bypass_config_parsed,
5666         .help_str = "show bypass config <port_id>: "
5667                     "Show the NIC bypass config for port_id",
5668         .data = NULL,
5669         .tokens = {
5670                 (void *)&cmd_showbypass_config_show,
5671                 (void *)&cmd_showbypass_config_bypass,
5672                 (void *)&cmd_showbypass_config_config,
5673                 (void *)&cmd_showbypass_config_port,
5674                 NULL,
5675         },
5676 };
5677
5678 #ifdef RTE_LIBRTE_PMD_BOND
5679 /* *** SET BONDING MODE *** */
5680 struct cmd_set_bonding_mode_result {
5681         cmdline_fixed_string_t set;
5682         cmdline_fixed_string_t bonding;
5683         cmdline_fixed_string_t mode;
5684         uint8_t value;
5685         portid_t port_id;
5686 };
5687
5688 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5689                 __rte_unused  struct cmdline *cl,
5690                 __rte_unused void *data)
5691 {
5692         struct cmd_set_bonding_mode_result *res = parsed_result;
5693         portid_t port_id = res->port_id;
5694
5695         /* Set the bonding mode for the relevant port. */
5696         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5697                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5698 }
5699
5700 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5701 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5702                 set, "set");
5703 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5704 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5705                 bonding, "bonding");
5706 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5707 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5708                 mode, "mode");
5709 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5710 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5711                 value, UINT8);
5712 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5713 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5714                 port_id, UINT16);
5715
5716 cmdline_parse_inst_t cmd_set_bonding_mode = {
5717                 .f = cmd_set_bonding_mode_parsed,
5718                 .help_str = "set bonding mode <mode_value> <port_id>: "
5719                         "Set the bonding mode for port_id",
5720                 .data = NULL,
5721                 .tokens = {
5722                                 (void *) &cmd_setbonding_mode_set,
5723                                 (void *) &cmd_setbonding_mode_bonding,
5724                                 (void *) &cmd_setbonding_mode_mode,
5725                                 (void *) &cmd_setbonding_mode_value,
5726                                 (void *) &cmd_setbonding_mode_port,
5727                                 NULL
5728                 }
5729 };
5730
5731 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5732 struct cmd_set_bonding_lacp_dedicated_queues_result {
5733         cmdline_fixed_string_t set;
5734         cmdline_fixed_string_t bonding;
5735         cmdline_fixed_string_t lacp;
5736         cmdline_fixed_string_t dedicated_queues;
5737         portid_t port_id;
5738         cmdline_fixed_string_t mode;
5739 };
5740
5741 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5742                 __rte_unused  struct cmdline *cl,
5743                 __rte_unused void *data)
5744 {
5745         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5746         portid_t port_id = res->port_id;
5747         struct rte_port *port;
5748
5749         port = &ports[port_id];
5750
5751         /** Check if the port is not started **/
5752         if (port->port_status != RTE_PORT_STOPPED) {
5753                 printf("Please stop port %d first\n", port_id);
5754                 return;
5755         }
5756
5757         if (!strcmp(res->mode, "enable")) {
5758                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5759                         printf("Dedicate queues for LACP control packets"
5760                                         " enabled\n");
5761                 else
5762                         printf("Enabling dedicate queues for LACP control "
5763                                         "packets on port %d failed\n", port_id);
5764         } else if (!strcmp(res->mode, "disable")) {
5765                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5766                         printf("Dedicated queues for LACP control packets "
5767                                         "disabled\n");
5768                 else
5769                         printf("Disabling dedicated queues for LACP control "
5770                                         "traffic on port %d failed\n", port_id);
5771         }
5772 }
5773
5774 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5775 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5776                 set, "set");
5777 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5778 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5779                 bonding, "bonding");
5780 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5781 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5782                 lacp, "lacp");
5783 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5784 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5785                 dedicated_queues, "dedicated_queues");
5786 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5787 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5788                 port_id, UINT16);
5789 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5790 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5791                 mode, "enable#disable");
5792
5793 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5794                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5795                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5796                         "enable|disable: "
5797                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5798                 .data = NULL,
5799                 .tokens = {
5800                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5801                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5802                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5803                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5804                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5805                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5806                         NULL
5807                 }
5808 };
5809
5810 /* *** SET BALANCE XMIT POLICY *** */
5811 struct cmd_set_bonding_balance_xmit_policy_result {
5812         cmdline_fixed_string_t set;
5813         cmdline_fixed_string_t bonding;
5814         cmdline_fixed_string_t balance_xmit_policy;
5815         portid_t port_id;
5816         cmdline_fixed_string_t policy;
5817 };
5818
5819 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5820                 __rte_unused  struct cmdline *cl,
5821                 __rte_unused void *data)
5822 {
5823         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5824         portid_t port_id = res->port_id;
5825         uint8_t policy;
5826
5827         if (!strcmp(res->policy, "l2")) {
5828                 policy = BALANCE_XMIT_POLICY_LAYER2;
5829         } else if (!strcmp(res->policy, "l23")) {
5830                 policy = BALANCE_XMIT_POLICY_LAYER23;
5831         } else if (!strcmp(res->policy, "l34")) {
5832                 policy = BALANCE_XMIT_POLICY_LAYER34;
5833         } else {
5834                 printf("\t Invalid xmit policy selection");
5835                 return;
5836         }
5837
5838         /* Set the bonding mode for the relevant port. */
5839         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5840                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5841                                 port_id);
5842         }
5843 }
5844
5845 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5846 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5847                 set, "set");
5848 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5849 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5850                 bonding, "bonding");
5851 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5852 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5853                 balance_xmit_policy, "balance_xmit_policy");
5854 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5855 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5856                 port_id, UINT16);
5857 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5858 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5859                 policy, "l2#l23#l34");
5860
5861 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5862                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5863                 .help_str = "set bonding balance_xmit_policy <port_id> "
5864                         "l2|l23|l34: "
5865                         "Set the bonding balance_xmit_policy for port_id",
5866                 .data = NULL,
5867                 .tokens = {
5868                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5869                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5870                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5871                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5872                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5873                                 NULL
5874                 }
5875 };
5876
5877 /* *** SHOW NIC BONDING CONFIGURATION *** */
5878 struct cmd_show_bonding_config_result {
5879         cmdline_fixed_string_t show;
5880         cmdline_fixed_string_t bonding;
5881         cmdline_fixed_string_t config;
5882         portid_t port_id;
5883 };
5884
5885 static void cmd_show_bonding_config_parsed(void *parsed_result,
5886                 __rte_unused  struct cmdline *cl,
5887                 __rte_unused void *data)
5888 {
5889         struct cmd_show_bonding_config_result *res = parsed_result;
5890         int bonding_mode, agg_mode;
5891         portid_t slaves[RTE_MAX_ETHPORTS];
5892         int num_slaves, num_active_slaves;
5893         int primary_id;
5894         int i;
5895         portid_t port_id = res->port_id;
5896
5897         /* Display the bonding mode.*/
5898         bonding_mode = rte_eth_bond_mode_get(port_id);
5899         if (bonding_mode < 0) {
5900                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5901                 return;
5902         } else
5903                 printf("\tBonding mode: %d\n", bonding_mode);
5904
5905         if (bonding_mode == BONDING_MODE_BALANCE) {
5906                 int balance_xmit_policy;
5907
5908                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5909                 if (balance_xmit_policy < 0) {
5910                         printf("\tFailed to get balance xmit policy for port = %d\n",
5911                                         port_id);
5912                         return;
5913                 } else {
5914                         printf("\tBalance Xmit Policy: ");
5915
5916                         switch (balance_xmit_policy) {
5917                         case BALANCE_XMIT_POLICY_LAYER2:
5918                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5919                                 break;
5920                         case BALANCE_XMIT_POLICY_LAYER23:
5921                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5922                                 break;
5923                         case BALANCE_XMIT_POLICY_LAYER34:
5924                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5925                                 break;
5926                         }
5927                         printf("\n");
5928                 }
5929         }
5930
5931         if (bonding_mode == BONDING_MODE_8023AD) {
5932                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5933                 printf("\tIEEE802.3AD Aggregator Mode: ");
5934                 switch (agg_mode) {
5935                 case AGG_BANDWIDTH:
5936                         printf("bandwidth");
5937                         break;
5938                 case AGG_STABLE:
5939                         printf("stable");
5940                         break;
5941                 case AGG_COUNT:
5942                         printf("count");
5943                         break;
5944                 }
5945                 printf("\n");
5946         }
5947
5948         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5949
5950         if (num_slaves < 0) {
5951                 printf("\tFailed to get slave list for port = %d\n", port_id);
5952                 return;
5953         }
5954         if (num_slaves > 0) {
5955                 printf("\tSlaves (%d): [", num_slaves);
5956                 for (i = 0; i < num_slaves - 1; i++)
5957                         printf("%d ", slaves[i]);
5958
5959                 printf("%d]\n", slaves[num_slaves - 1]);
5960         } else {
5961                 printf("\tSlaves: []\n");
5962
5963         }
5964
5965         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5966                         RTE_MAX_ETHPORTS);
5967
5968         if (num_active_slaves < 0) {
5969                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5970                 return;
5971         }
5972         if (num_active_slaves > 0) {
5973                 printf("\tActive Slaves (%d): [", num_active_slaves);
5974                 for (i = 0; i < num_active_slaves - 1; i++)
5975                         printf("%d ", slaves[i]);
5976
5977                 printf("%d]\n", slaves[num_active_slaves - 1]);
5978
5979         } else {
5980                 printf("\tActive Slaves: []\n");
5981
5982         }
5983
5984         primary_id = rte_eth_bond_primary_get(port_id);
5985         if (primary_id < 0) {
5986                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5987                 return;
5988         } else
5989                 printf("\tPrimary: [%d]\n", primary_id);
5990
5991 }
5992
5993 cmdline_parse_token_string_t cmd_showbonding_config_show =
5994 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5995                 show, "show");
5996 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5997 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5998                 bonding, "bonding");
5999 cmdline_parse_token_string_t cmd_showbonding_config_config =
6000 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6001                 config, "config");
6002 cmdline_parse_token_num_t cmd_showbonding_config_port =
6003 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6004                 port_id, UINT16);
6005
6006 cmdline_parse_inst_t cmd_show_bonding_config = {
6007                 .f = cmd_show_bonding_config_parsed,
6008                 .help_str = "show bonding config <port_id>: "
6009                         "Show the bonding config for port_id",
6010                 .data = NULL,
6011                 .tokens = {
6012                                 (void *)&cmd_showbonding_config_show,
6013                                 (void *)&cmd_showbonding_config_bonding,
6014                                 (void *)&cmd_showbonding_config_config,
6015                                 (void *)&cmd_showbonding_config_port,
6016                                 NULL
6017                 }
6018 };
6019
6020 /* *** SET BONDING PRIMARY *** */
6021 struct cmd_set_bonding_primary_result {
6022         cmdline_fixed_string_t set;
6023         cmdline_fixed_string_t bonding;
6024         cmdline_fixed_string_t primary;
6025         portid_t slave_id;
6026         portid_t port_id;
6027 };
6028
6029 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6030                 __rte_unused  struct cmdline *cl,
6031                 __rte_unused void *data)
6032 {
6033         struct cmd_set_bonding_primary_result *res = parsed_result;
6034         portid_t master_port_id = res->port_id;
6035         portid_t slave_port_id = res->slave_id;
6036
6037         /* Set the primary slave for a bonded device. */
6038         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6039                 printf("\t Failed to set primary slave for port = %d.\n",
6040                                 master_port_id);
6041                 return;
6042         }
6043         init_port_config();
6044 }
6045
6046 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6048                 set, "set");
6049 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6051                 bonding, "bonding");
6052 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6054                 primary, "primary");
6055 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6056 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6057                 slave_id, UINT16);
6058 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6059 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6060                 port_id, UINT16);
6061
6062 cmdline_parse_inst_t cmd_set_bonding_primary = {
6063                 .f = cmd_set_bonding_primary_parsed,
6064                 .help_str = "set bonding primary <slave_id> <port_id>: "
6065                         "Set the primary slave for port_id",
6066                 .data = NULL,
6067                 .tokens = {
6068                                 (void *)&cmd_setbonding_primary_set,
6069                                 (void *)&cmd_setbonding_primary_bonding,
6070                                 (void *)&cmd_setbonding_primary_primary,
6071                                 (void *)&cmd_setbonding_primary_slave,
6072                                 (void *)&cmd_setbonding_primary_port,
6073                                 NULL
6074                 }
6075 };
6076
6077 /* *** ADD SLAVE *** */
6078 struct cmd_add_bonding_slave_result {
6079         cmdline_fixed_string_t add;
6080         cmdline_fixed_string_t bonding;
6081         cmdline_fixed_string_t slave;
6082         portid_t slave_id;
6083         portid_t port_id;
6084 };
6085
6086 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6087                 __rte_unused  struct cmdline *cl,
6088                 __rte_unused void *data)
6089 {
6090         struct cmd_add_bonding_slave_result *res = parsed_result;
6091         portid_t master_port_id = res->port_id;
6092         portid_t slave_port_id = res->slave_id;
6093
6094         /* add the slave for a bonded device. */
6095         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6096                 printf("\t Failed to add slave %d to master port = %d.\n",
6097                                 slave_port_id, master_port_id);
6098                 return;
6099         }
6100         init_port_config();
6101         set_port_slave_flag(slave_port_id);
6102 }
6103
6104 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6105 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6106                 add, "add");
6107 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6108 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6109                 bonding, "bonding");
6110 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6111 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6112                 slave, "slave");
6113 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6114 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6115                 slave_id, UINT16);
6116 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6117 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6118                 port_id, UINT16);
6119
6120 cmdline_parse_inst_t cmd_add_bonding_slave = {
6121                 .f = cmd_add_bonding_slave_parsed,
6122                 .help_str = "add bonding slave <slave_id> <port_id>: "
6123                         "Add a slave device to a bonded device",
6124                 .data = NULL,
6125                 .tokens = {
6126                                 (void *)&cmd_addbonding_slave_add,
6127                                 (void *)&cmd_addbonding_slave_bonding,
6128                                 (void *)&cmd_addbonding_slave_slave,
6129                                 (void *)&cmd_addbonding_slave_slaveid,
6130                                 (void *)&cmd_addbonding_slave_port,
6131                                 NULL
6132                 }
6133 };
6134
6135 /* *** REMOVE SLAVE *** */
6136 struct cmd_remove_bonding_slave_result {
6137         cmdline_fixed_string_t remove;
6138         cmdline_fixed_string_t bonding;
6139         cmdline_fixed_string_t slave;
6140         portid_t slave_id;
6141         portid_t port_id;
6142 };
6143
6144 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6145                 __rte_unused  struct cmdline *cl,
6146                 __rte_unused void *data)
6147 {
6148         struct cmd_remove_bonding_slave_result *res = parsed_result;
6149         portid_t master_port_id = res->port_id;
6150         portid_t slave_port_id = res->slave_id;
6151
6152         /* remove the slave from a bonded device. */
6153         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6154                 printf("\t Failed to remove slave %d from master port = %d.\n",
6155                                 slave_port_id, master_port_id);
6156                 return;
6157         }
6158         init_port_config();
6159         clear_port_slave_flag(slave_port_id);
6160 }
6161
6162 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6163                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6164                                 remove, "remove");
6165 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6166                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6167                                 bonding, "bonding");
6168 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6169                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6170                                 slave, "slave");
6171 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6172                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6173                                 slave_id, UINT16);
6174 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6175                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6176                                 port_id, UINT16);
6177
6178 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6179                 .f = cmd_remove_bonding_slave_parsed,
6180                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6181                         "Remove a slave device from a bonded device",
6182                 .data = NULL,
6183                 .tokens = {
6184                                 (void *)&cmd_removebonding_slave_remove,
6185                                 (void *)&cmd_removebonding_slave_bonding,
6186                                 (void *)&cmd_removebonding_slave_slave,
6187                                 (void *)&cmd_removebonding_slave_slaveid,
6188                                 (void *)&cmd_removebonding_slave_port,
6189                                 NULL
6190                 }
6191 };
6192
6193 /* *** CREATE BONDED DEVICE *** */
6194 struct cmd_create_bonded_device_result {
6195         cmdline_fixed_string_t create;
6196         cmdline_fixed_string_t bonded;
6197         cmdline_fixed_string_t device;
6198         uint8_t mode;
6199         uint8_t socket;
6200 };
6201
6202 static int bond_dev_num = 0;
6203
6204 static void cmd_create_bonded_device_parsed(void *parsed_result,
6205                 __rte_unused  struct cmdline *cl,
6206                 __rte_unused void *data)
6207 {
6208         struct cmd_create_bonded_device_result *res = parsed_result;
6209         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6210         int port_id;
6211         int ret;
6212
6213         if (test_done == 0) {
6214                 printf("Please stop forwarding first\n");
6215                 return;
6216         }
6217
6218         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6219                         bond_dev_num++);
6220
6221         /* Create a new bonded device. */
6222         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6223         if (port_id < 0) {
6224                 printf("\t Failed to create bonded device.\n");
6225                 return;
6226         } else {
6227                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6228                                 port_id);
6229
6230                 /* Update number of ports */
6231                 nb_ports = rte_eth_dev_count_avail();
6232                 reconfig(port_id, res->socket);
6233                 ret = rte_eth_promiscuous_enable(port_id);
6234                 if (ret != 0)
6235                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6236                                 port_id, rte_strerror(-ret));
6237
6238                 ports[port_id].need_setup = 0;
6239                 ports[port_id].port_status = RTE_PORT_STOPPED;
6240         }
6241
6242 }
6243
6244 cmdline_parse_token_string_t cmd_createbonded_device_create =
6245                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6246                                 create, "create");
6247 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6248                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6249                                 bonded, "bonded");
6250 cmdline_parse_token_string_t cmd_createbonded_device_device =
6251                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6252                                 device, "device");
6253 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6254                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6255                                 mode, UINT8);
6256 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6257                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6258                                 socket, UINT8);
6259
6260 cmdline_parse_inst_t cmd_create_bonded_device = {
6261                 .f = cmd_create_bonded_device_parsed,
6262                 .help_str = "create bonded device <mode> <socket>: "
6263                         "Create a new bonded device with specific bonding mode and socket",
6264                 .data = NULL,
6265                 .tokens = {
6266                                 (void *)&cmd_createbonded_device_create,
6267                                 (void *)&cmd_createbonded_device_bonded,
6268                                 (void *)&cmd_createbonded_device_device,
6269                                 (void *)&cmd_createbonded_device_mode,
6270                                 (void *)&cmd_createbonded_device_socket,
6271                                 NULL
6272                 }
6273 };
6274
6275 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6276 struct cmd_set_bond_mac_addr_result {
6277         cmdline_fixed_string_t set;
6278         cmdline_fixed_string_t bonding;
6279         cmdline_fixed_string_t mac_addr;
6280         uint16_t port_num;
6281         struct rte_ether_addr address;
6282 };
6283
6284 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6285                 __rte_unused  struct cmdline *cl,
6286                 __rte_unused void *data)
6287 {
6288         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6289         int ret;
6290
6291         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6292                 return;
6293
6294         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6295
6296         /* check the return value and print it if is < 0 */
6297         if (ret < 0)
6298                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6299 }
6300
6301 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6302                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6303 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6304                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6305                                 "bonding");
6306 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6307                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6308                                 "mac_addr");
6309 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6310                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6311                                 port_num, UINT16);
6312 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6313                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6314
6315 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6316                 .f = cmd_set_bond_mac_addr_parsed,
6317                 .data = (void *) 0,
6318                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6319                 .tokens = {
6320                                 (void *)&cmd_set_bond_mac_addr_set,
6321                                 (void *)&cmd_set_bond_mac_addr_bonding,
6322                                 (void *)&cmd_set_bond_mac_addr_mac,
6323                                 (void *)&cmd_set_bond_mac_addr_portnum,
6324                                 (void *)&cmd_set_bond_mac_addr_addr,
6325                                 NULL
6326                 }
6327 };
6328
6329
6330 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6331 struct cmd_set_bond_mon_period_result {
6332         cmdline_fixed_string_t set;
6333         cmdline_fixed_string_t bonding;
6334         cmdline_fixed_string_t mon_period;
6335         uint16_t port_num;
6336         uint32_t period_ms;
6337 };
6338
6339 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6340                 __rte_unused  struct cmdline *cl,
6341                 __rte_unused void *data)
6342 {
6343         struct cmd_set_bond_mon_period_result *res = parsed_result;
6344         int ret;
6345
6346         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6347
6348         /* check the return value and print it if is < 0 */
6349         if (ret < 0)
6350                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6351 }
6352
6353 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6354                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6355                                 set, "set");
6356 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6357                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6358                                 bonding, "bonding");
6359 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6360                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6361                                 mon_period,     "mon_period");
6362 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6363                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6364                                 port_num, UINT16);
6365 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6366                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6367                                 period_ms, UINT32);
6368
6369 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6370                 .f = cmd_set_bond_mon_period_parsed,
6371                 .data = (void *) 0,
6372                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6373                 .tokens = {
6374                                 (void *)&cmd_set_bond_mon_period_set,
6375                                 (void *)&cmd_set_bond_mon_period_bonding,
6376                                 (void *)&cmd_set_bond_mon_period_mon_period,
6377                                 (void *)&cmd_set_bond_mon_period_portnum,
6378                                 (void *)&cmd_set_bond_mon_period_period_ms,
6379                                 NULL
6380                 }
6381 };
6382
6383
6384
6385 struct cmd_set_bonding_agg_mode_policy_result {
6386         cmdline_fixed_string_t set;
6387         cmdline_fixed_string_t bonding;
6388         cmdline_fixed_string_t agg_mode;
6389         uint16_t port_num;
6390         cmdline_fixed_string_t policy;
6391 };
6392
6393
6394 static void
6395 cmd_set_bonding_agg_mode(void *parsed_result,
6396                 __rte_unused struct cmdline *cl,
6397                 __rte_unused void *data)
6398 {
6399         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6400         uint8_t policy = AGG_BANDWIDTH;
6401
6402         if (!strcmp(res->policy, "bandwidth"))
6403                 policy = AGG_BANDWIDTH;
6404         else if (!strcmp(res->policy, "stable"))
6405                 policy = AGG_STABLE;
6406         else if (!strcmp(res->policy, "count"))
6407                 policy = AGG_COUNT;
6408
6409         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6410 }
6411
6412
6413 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6414         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6415                                 set, "set");
6416 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6417         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6418                                 bonding, "bonding");
6419
6420 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6421         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6422                                 agg_mode, "agg_mode");
6423
6424 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6425         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6426                                 port_num, UINT16);
6427
6428 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6429         TOKEN_STRING_INITIALIZER(
6430                         struct cmd_set_bonding_balance_xmit_policy_result,
6431                 policy, "stable#bandwidth#count");
6432
6433 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6434         .f = cmd_set_bonding_agg_mode,
6435         .data = (void *) 0,
6436         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6437         .tokens = {
6438                         (void *)&cmd_set_bonding_agg_mode_set,
6439                         (void *)&cmd_set_bonding_agg_mode_bonding,
6440                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6441                         (void *)&cmd_set_bonding_agg_mode_portnum,
6442                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6443                         NULL
6444                 }
6445 };
6446
6447
6448 #endif /* RTE_LIBRTE_PMD_BOND */
6449
6450 /* *** SET FORWARDING MODE *** */
6451 struct cmd_set_fwd_mode_result {
6452         cmdline_fixed_string_t set;
6453         cmdline_fixed_string_t fwd;
6454         cmdline_fixed_string_t mode;
6455 };
6456
6457 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6458                                     __rte_unused struct cmdline *cl,
6459                                     __rte_unused void *data)
6460 {
6461         struct cmd_set_fwd_mode_result *res = parsed_result;
6462
6463         retry_enabled = 0;
6464         set_pkt_forwarding_mode(res->mode);
6465 }
6466
6467 cmdline_parse_token_string_t cmd_setfwd_set =
6468         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6469 cmdline_parse_token_string_t cmd_setfwd_fwd =
6470         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6471 cmdline_parse_token_string_t cmd_setfwd_mode =
6472         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6473                 "" /* defined at init */);
6474
6475 cmdline_parse_inst_t cmd_set_fwd_mode = {
6476         .f = cmd_set_fwd_mode_parsed,
6477         .data = NULL,
6478         .help_str = NULL, /* defined at init */
6479         .tokens = {
6480                 (void *)&cmd_setfwd_set,
6481                 (void *)&cmd_setfwd_fwd,
6482                 (void *)&cmd_setfwd_mode,
6483                 NULL,
6484         },
6485 };
6486
6487 static void cmd_set_fwd_mode_init(void)
6488 {
6489         char *modes, *c;
6490         static char token[128];
6491         static char help[256];
6492         cmdline_parse_token_string_t *token_struct;
6493
6494         modes = list_pkt_forwarding_modes();
6495         snprintf(help, sizeof(help), "set fwd %s: "
6496                 "Set packet forwarding mode", modes);
6497         cmd_set_fwd_mode.help_str = help;
6498
6499         /* string token separator is # */
6500         for (c = token; *modes != '\0'; modes++)
6501                 if (*modes == '|')
6502                         *c++ = '#';
6503                 else
6504                         *c++ = *modes;
6505         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6506         token_struct->string_data.str = token;
6507 }
6508
6509 /* *** SET RETRY FORWARDING MODE *** */
6510 struct cmd_set_fwd_retry_mode_result {
6511         cmdline_fixed_string_t set;
6512         cmdline_fixed_string_t fwd;
6513         cmdline_fixed_string_t mode;
6514         cmdline_fixed_string_t retry;
6515 };
6516
6517 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6518                             __rte_unused struct cmdline *cl,
6519                             __rte_unused void *data)
6520 {
6521         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6522
6523         retry_enabled = 1;
6524         set_pkt_forwarding_mode(res->mode);
6525 }
6526
6527 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6528         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6529                         set, "set");
6530 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6531         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6532                         fwd, "fwd");
6533 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6535                         mode,
6536                 "" /* defined at init */);
6537 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6538         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6539                         retry, "retry");
6540
6541 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6542         .f = cmd_set_fwd_retry_mode_parsed,
6543         .data = NULL,
6544         .help_str = NULL, /* defined at init */
6545         .tokens = {
6546                 (void *)&cmd_setfwd_retry_set,
6547                 (void *)&cmd_setfwd_retry_fwd,
6548                 (void *)&cmd_setfwd_retry_mode,
6549                 (void *)&cmd_setfwd_retry_retry,
6550                 NULL,
6551         },
6552 };
6553
6554 static void cmd_set_fwd_retry_mode_init(void)
6555 {
6556         char *modes, *c;
6557         static char token[128];
6558         static char help[256];
6559         cmdline_parse_token_string_t *token_struct;
6560
6561         modes = list_pkt_forwarding_retry_modes();
6562         snprintf(help, sizeof(help), "set fwd %s retry: "
6563                 "Set packet forwarding mode with retry", modes);
6564         cmd_set_fwd_retry_mode.help_str = help;
6565
6566         /* string token separator is # */
6567         for (c = token; *modes != '\0'; modes++)
6568                 if (*modes == '|')
6569                         *c++ = '#';
6570                 else
6571                         *c++ = *modes;
6572         token_struct = (cmdline_parse_token_string_t *)
6573                 cmd_set_fwd_retry_mode.tokens[2];
6574         token_struct->string_data.str = token;
6575 }
6576
6577 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6578 struct cmd_set_burst_tx_retry_result {
6579         cmdline_fixed_string_t set;
6580         cmdline_fixed_string_t burst;
6581         cmdline_fixed_string_t tx;
6582         cmdline_fixed_string_t delay;
6583         uint32_t time;
6584         cmdline_fixed_string_t retry;
6585         uint32_t retry_num;
6586 };
6587
6588 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6589                                         __rte_unused struct cmdline *cl,
6590                                         __rte_unused void *data)
6591 {
6592         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6593
6594         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6595                 && !strcmp(res->tx, "tx")) {
6596                 if (!strcmp(res->delay, "delay"))
6597                         burst_tx_delay_time = res->time;
6598                 if (!strcmp(res->retry, "retry"))
6599                         burst_tx_retry_num = res->retry_num;
6600         }
6601
6602 }
6603
6604 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6605         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6606 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6608                                  "burst");
6609 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6610         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6611 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6612         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6613 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6614         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6615 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6616         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6617 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6618         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6619
6620 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6621         .f = cmd_set_burst_tx_retry_parsed,
6622         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6623         .tokens = {
6624                 (void *)&cmd_set_burst_tx_retry_set,
6625                 (void *)&cmd_set_burst_tx_retry_burst,
6626                 (void *)&cmd_set_burst_tx_retry_tx,
6627                 (void *)&cmd_set_burst_tx_retry_delay,
6628                 (void *)&cmd_set_burst_tx_retry_time,
6629                 (void *)&cmd_set_burst_tx_retry_retry,
6630                 (void *)&cmd_set_burst_tx_retry_retry_num,
6631                 NULL,
6632         },
6633 };
6634
6635 /* *** SET PROMISC MODE *** */
6636 struct cmd_set_promisc_mode_result {
6637         cmdline_fixed_string_t set;
6638         cmdline_fixed_string_t promisc;
6639         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6640         uint16_t port_num;               /* valid if "allports" argument == 0 */
6641         cmdline_fixed_string_t mode;
6642 };
6643
6644 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6645                                         __rte_unused struct cmdline *cl,
6646                                         void *allports)
6647 {
6648         struct cmd_set_promisc_mode_result *res = parsed_result;
6649         int enable;
6650         portid_t i;
6651
6652         if (!strcmp(res->mode, "on"))
6653                 enable = 1;
6654         else
6655                 enable = 0;
6656
6657         /* all ports */
6658         if (allports) {
6659                 RTE_ETH_FOREACH_DEV(i)
6660                         eth_set_promisc_mode(i, enable);
6661         } else {
6662                 eth_set_promisc_mode(res->port_num, enable);
6663         }
6664 }
6665
6666 cmdline_parse_token_string_t cmd_setpromisc_set =
6667         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6668 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6669         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6670                                  "promisc");
6671 cmdline_parse_token_string_t cmd_setpromisc_portall =
6672         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6673                                  "all");
6674 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6675         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6676                               UINT16);
6677 cmdline_parse_token_string_t cmd_setpromisc_mode =
6678         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6679                                  "on#off");
6680
6681 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6682         .f = cmd_set_promisc_mode_parsed,
6683         .data = (void *)1,
6684         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6685         .tokens = {
6686                 (void *)&cmd_setpromisc_set,
6687                 (void *)&cmd_setpromisc_promisc,
6688                 (void *)&cmd_setpromisc_portall,
6689                 (void *)&cmd_setpromisc_mode,
6690                 NULL,
6691         },
6692 };
6693
6694 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6695         .f = cmd_set_promisc_mode_parsed,
6696         .data = (void *)0,
6697         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6698         .tokens = {
6699                 (void *)&cmd_setpromisc_set,
6700                 (void *)&cmd_setpromisc_promisc,
6701                 (void *)&cmd_setpromisc_portnum,
6702                 (void *)&cmd_setpromisc_mode,
6703                 NULL,
6704         },
6705 };
6706
6707 /* *** SET ALLMULTI MODE *** */
6708 struct cmd_set_allmulti_mode_result {
6709         cmdline_fixed_string_t set;
6710         cmdline_fixed_string_t allmulti;
6711         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6712         uint16_t port_num;               /* valid if "allports" argument == 0 */
6713         cmdline_fixed_string_t mode;
6714 };
6715
6716 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6717                                         __rte_unused struct cmdline *cl,
6718                                         void *allports)
6719 {
6720         struct cmd_set_allmulti_mode_result *res = parsed_result;
6721         int enable;
6722         portid_t i;
6723
6724         if (!strcmp(res->mode, "on"))
6725                 enable = 1;
6726         else
6727                 enable = 0;
6728
6729         /* all ports */
6730         if (allports) {
6731                 RTE_ETH_FOREACH_DEV(i) {
6732                         eth_set_allmulticast_mode(i, enable);
6733                 }
6734         }
6735         else {
6736                 eth_set_allmulticast_mode(res->port_num, enable);
6737         }
6738 }
6739
6740 cmdline_parse_token_string_t cmd_setallmulti_set =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6742 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6743         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6744                                  "allmulti");
6745 cmdline_parse_token_string_t cmd_setallmulti_portall =
6746         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6747                                  "all");
6748 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6749         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6750                               UINT16);
6751 cmdline_parse_token_string_t cmd_setallmulti_mode =
6752         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6753                                  "on#off");
6754
6755 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6756         .f = cmd_set_allmulti_mode_parsed,
6757         .data = (void *)1,
6758         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6759         .tokens = {
6760                 (void *)&cmd_setallmulti_set,
6761                 (void *)&cmd_setallmulti_allmulti,
6762                 (void *)&cmd_setallmulti_portall,
6763                 (void *)&cmd_setallmulti_mode,
6764                 NULL,
6765         },
6766 };
6767
6768 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6769         .f = cmd_set_allmulti_mode_parsed,
6770         .data = (void *)0,
6771         .help_str = "set allmulti <port_id> on|off: "
6772                 "Set allmulti mode on port_id",
6773         .tokens = {
6774                 (void *)&cmd_setallmulti_set,
6775                 (void *)&cmd_setallmulti_allmulti,
6776                 (void *)&cmd_setallmulti_portnum,
6777                 (void *)&cmd_setallmulti_mode,
6778                 NULL,
6779         },
6780 };
6781
6782 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6783 struct cmd_link_flow_ctrl_set_result {
6784         cmdline_fixed_string_t set;
6785         cmdline_fixed_string_t flow_ctrl;
6786         cmdline_fixed_string_t rx;
6787         cmdline_fixed_string_t rx_lfc_mode;
6788         cmdline_fixed_string_t tx;
6789         cmdline_fixed_string_t tx_lfc_mode;
6790         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6791         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6792         cmdline_fixed_string_t autoneg_str;
6793         cmdline_fixed_string_t autoneg;
6794         cmdline_fixed_string_t hw_str;
6795         uint32_t high_water;
6796         cmdline_fixed_string_t lw_str;
6797         uint32_t low_water;
6798         cmdline_fixed_string_t pt_str;
6799         uint16_t pause_time;
6800         cmdline_fixed_string_t xon_str;
6801         uint16_t send_xon;
6802         portid_t port_id;
6803 };
6804
6805 cmdline_parse_token_string_t cmd_lfc_set_set =
6806         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6807                                 set, "set");
6808 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6809         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6810                                 flow_ctrl, "flow_ctrl");
6811 cmdline_parse_token_string_t cmd_lfc_set_rx =
6812         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6813                                 rx, "rx");
6814 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6815         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6816                                 rx_lfc_mode, "on#off");
6817 cmdline_parse_token_string_t cmd_lfc_set_tx =
6818         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6819                                 tx, "tx");
6820 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6822                                 tx_lfc_mode, "on#off");
6823 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6824         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6825                                 hw_str, "high_water");
6826 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6827         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6828                                 high_water, UINT32);
6829 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6830         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6831                                 lw_str, "low_water");
6832 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6833         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6834                                 low_water, UINT32);
6835 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6836         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6837                                 pt_str, "pause_time");
6838 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6839         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6840                                 pause_time, UINT16);
6841 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6842         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6843                                 xon_str, "send_xon");
6844 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6845         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6846                                 send_xon, UINT16);
6847 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6848         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6849                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6850 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6851         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6852                                 mac_ctrl_frame_fwd_mode, "on#off");
6853 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6854         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6855                                 autoneg_str, "autoneg");
6856 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6857         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6858                                 autoneg, "on#off");
6859 cmdline_parse_token_num_t cmd_lfc_set_portid =
6860         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6861                                 port_id, UINT16);
6862
6863 /* forward declaration */
6864 static void
6865 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6866                               void *data);
6867
6868 cmdline_parse_inst_t cmd_link_flow_control_set = {
6869         .f = cmd_link_flow_ctrl_set_parsed,
6870         .data = NULL,
6871         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6872                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6873                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6874         .tokens = {
6875                 (void *)&cmd_lfc_set_set,
6876                 (void *)&cmd_lfc_set_flow_ctrl,
6877                 (void *)&cmd_lfc_set_rx,
6878                 (void *)&cmd_lfc_set_rx_mode,
6879                 (void *)&cmd_lfc_set_tx,
6880                 (void *)&cmd_lfc_set_tx_mode,
6881                 (void *)&cmd_lfc_set_high_water,
6882                 (void *)&cmd_lfc_set_low_water,
6883                 (void *)&cmd_lfc_set_pause_time,
6884                 (void *)&cmd_lfc_set_send_xon,
6885                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6886                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6887                 (void *)&cmd_lfc_set_autoneg_str,
6888                 (void *)&cmd_lfc_set_autoneg,
6889                 (void *)&cmd_lfc_set_portid,
6890                 NULL,
6891         },
6892 };
6893
6894 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6895         .f = cmd_link_flow_ctrl_set_parsed,
6896         .data = (void *)&cmd_link_flow_control_set_rx,
6897         .help_str = "set flow_ctrl rx on|off <port_id>: "
6898                 "Change rx flow control parameter",
6899         .tokens = {
6900                 (void *)&cmd_lfc_set_set,
6901                 (void *)&cmd_lfc_set_flow_ctrl,
6902                 (void *)&cmd_lfc_set_rx,
6903                 (void *)&cmd_lfc_set_rx_mode,
6904                 (void *)&cmd_lfc_set_portid,
6905                 NULL,
6906         },
6907 };
6908
6909 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6910         .f = cmd_link_flow_ctrl_set_parsed,
6911         .data = (void *)&cmd_link_flow_control_set_tx,
6912         .help_str = "set flow_ctrl tx on|off <port_id>: "
6913                 "Change tx flow control parameter",
6914         .tokens = {
6915                 (void *)&cmd_lfc_set_set,
6916                 (void *)&cmd_lfc_set_flow_ctrl,
6917                 (void *)&cmd_lfc_set_tx,
6918                 (void *)&cmd_lfc_set_tx_mode,
6919                 (void *)&cmd_lfc_set_portid,
6920                 NULL,
6921         },
6922 };
6923
6924 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6925         .f = cmd_link_flow_ctrl_set_parsed,
6926         .data = (void *)&cmd_link_flow_control_set_hw,
6927         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6928                 "Change high water flow control parameter",
6929         .tokens = {
6930                 (void *)&cmd_lfc_set_set,
6931                 (void *)&cmd_lfc_set_flow_ctrl,
6932                 (void *)&cmd_lfc_set_high_water_str,
6933                 (void *)&cmd_lfc_set_high_water,
6934                 (void *)&cmd_lfc_set_portid,
6935                 NULL,
6936         },
6937 };
6938
6939 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6940         .f = cmd_link_flow_ctrl_set_parsed,
6941         .data = (void *)&cmd_link_flow_control_set_lw,
6942         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6943                 "Change low water flow control parameter",
6944         .tokens = {
6945                 (void *)&cmd_lfc_set_set,
6946                 (void *)&cmd_lfc_set_flow_ctrl,
6947                 (void *)&cmd_lfc_set_low_water_str,
6948                 (void *)&cmd_lfc_set_low_water,
6949                 (void *)&cmd_lfc_set_portid,
6950                 NULL,
6951         },
6952 };
6953
6954 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6955         .f = cmd_link_flow_ctrl_set_parsed,
6956         .data = (void *)&cmd_link_flow_control_set_pt,
6957         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6958                 "Change pause time flow control parameter",
6959         .tokens = {
6960                 (void *)&cmd_lfc_set_set,
6961                 (void *)&cmd_lfc_set_flow_ctrl,
6962                 (void *)&cmd_lfc_set_pause_time_str,
6963                 (void *)&cmd_lfc_set_pause_time,
6964                 (void *)&cmd_lfc_set_portid,
6965                 NULL,
6966         },
6967 };
6968
6969 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6970         .f = cmd_link_flow_ctrl_set_parsed,
6971         .data = (void *)&cmd_link_flow_control_set_xon,
6972         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6973                 "Change send_xon flow control parameter",
6974         .tokens = {
6975                 (void *)&cmd_lfc_set_set,
6976                 (void *)&cmd_lfc_set_flow_ctrl,
6977                 (void *)&cmd_lfc_set_send_xon_str,
6978                 (void *)&cmd_lfc_set_send_xon,
6979                 (void *)&cmd_lfc_set_portid,
6980                 NULL,
6981         },
6982 };
6983
6984 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6985         .f = cmd_link_flow_ctrl_set_parsed,
6986         .data = (void *)&cmd_link_flow_control_set_macfwd,
6987         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6988                 "Change mac ctrl fwd flow control parameter",
6989         .tokens = {
6990                 (void *)&cmd_lfc_set_set,
6991                 (void *)&cmd_lfc_set_flow_ctrl,
6992                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6993                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6994                 (void *)&cmd_lfc_set_portid,
6995                 NULL,
6996         },
6997 };
6998
6999 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7000         .f = cmd_link_flow_ctrl_set_parsed,
7001         .data = (void *)&cmd_link_flow_control_set_autoneg,
7002         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7003                 "Change autoneg flow control parameter",
7004         .tokens = {
7005                 (void *)&cmd_lfc_set_set,
7006                 (void *)&cmd_lfc_set_flow_ctrl,
7007                 (void *)&cmd_lfc_set_autoneg_str,
7008                 (void *)&cmd_lfc_set_autoneg,
7009                 (void *)&cmd_lfc_set_portid,
7010                 NULL,
7011         },
7012 };
7013
7014 static void
7015 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7016                               __rte_unused struct cmdline *cl,
7017                               void *data)
7018 {
7019         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7020         cmdline_parse_inst_t *cmd = data;
7021         struct rte_eth_fc_conf fc_conf;
7022         int rx_fc_en = 0;
7023         int tx_fc_en = 0;
7024         int ret;
7025
7026         /*
7027          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7028          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7029          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7030          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7031          */
7032         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7033                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7034         };
7035
7036         /* Partial command line, retrieve current configuration */
7037         if (cmd) {
7038                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7039                 if (ret != 0) {
7040                         printf("cannot get current flow ctrl parameters, return"
7041                                "code = %d\n", ret);
7042                         return;
7043                 }
7044
7045                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7046                     (fc_conf.mode == RTE_FC_FULL))
7047                         rx_fc_en = 1;
7048                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7049                     (fc_conf.mode == RTE_FC_FULL))
7050                         tx_fc_en = 1;
7051         }
7052
7053         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7054                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7055
7056         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7057                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7058
7059         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7060
7061         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7062                 fc_conf.high_water = res->high_water;
7063
7064         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7065                 fc_conf.low_water = res->low_water;
7066
7067         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7068                 fc_conf.pause_time = res->pause_time;
7069
7070         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7071                 fc_conf.send_xon = res->send_xon;
7072
7073         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7074                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7075                         fc_conf.mac_ctrl_frame_fwd = 1;
7076                 else
7077                         fc_conf.mac_ctrl_frame_fwd = 0;
7078         }
7079
7080         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7081                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7082
7083         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7084         if (ret != 0)
7085                 printf("bad flow contrl parameter, return code = %d \n", ret);
7086 }
7087
7088 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7089 struct cmd_priority_flow_ctrl_set_result {
7090         cmdline_fixed_string_t set;
7091         cmdline_fixed_string_t pfc_ctrl;
7092         cmdline_fixed_string_t rx;
7093         cmdline_fixed_string_t rx_pfc_mode;
7094         cmdline_fixed_string_t tx;
7095         cmdline_fixed_string_t tx_pfc_mode;
7096         uint32_t high_water;
7097         uint32_t low_water;
7098         uint16_t pause_time;
7099         uint8_t  priority;
7100         portid_t port_id;
7101 };
7102
7103 static void
7104 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7105                        __rte_unused struct cmdline *cl,
7106                        __rte_unused void *data)
7107 {
7108         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7109         struct rte_eth_pfc_conf pfc_conf;
7110         int rx_fc_enable, tx_fc_enable;
7111         int ret;
7112
7113         /*
7114          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7115          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7116          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7117          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7118          */
7119         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7120                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7121         };
7122
7123         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7124         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7125         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7126         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7127         pfc_conf.fc.high_water = res->high_water;
7128         pfc_conf.fc.low_water  = res->low_water;
7129         pfc_conf.fc.pause_time = res->pause_time;
7130         pfc_conf.priority      = res->priority;
7131
7132         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7133         if (ret != 0)
7134                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7135 }
7136
7137 cmdline_parse_token_string_t cmd_pfc_set_set =
7138         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7139                                 set, "set");
7140 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7141         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7142                                 pfc_ctrl, "pfc_ctrl");
7143 cmdline_parse_token_string_t cmd_pfc_set_rx =
7144         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7145                                 rx, "rx");
7146 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7147         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7148                                 rx_pfc_mode, "on#off");
7149 cmdline_parse_token_string_t cmd_pfc_set_tx =
7150         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7151                                 tx, "tx");
7152 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7153         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7154                                 tx_pfc_mode, "on#off");
7155 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7156         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7157                                 high_water, UINT32);
7158 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7159         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7160                                 low_water, UINT32);
7161 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7162         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7163                                 pause_time, UINT16);
7164 cmdline_parse_token_num_t cmd_pfc_set_priority =
7165         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7166                                 priority, UINT8);
7167 cmdline_parse_token_num_t cmd_pfc_set_portid =
7168         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7169                                 port_id, UINT16);
7170
7171 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7172         .f = cmd_priority_flow_ctrl_set_parsed,
7173         .data = NULL,
7174         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7175                 "<pause_time> <priority> <port_id>: "
7176                 "Configure the Ethernet priority flow control",
7177         .tokens = {
7178                 (void *)&cmd_pfc_set_set,
7179                 (void *)&cmd_pfc_set_flow_ctrl,
7180                 (void *)&cmd_pfc_set_rx,
7181                 (void *)&cmd_pfc_set_rx_mode,
7182                 (void *)&cmd_pfc_set_tx,
7183                 (void *)&cmd_pfc_set_tx_mode,
7184                 (void *)&cmd_pfc_set_high_water,
7185                 (void *)&cmd_pfc_set_low_water,
7186                 (void *)&cmd_pfc_set_pause_time,
7187                 (void *)&cmd_pfc_set_priority,
7188                 (void *)&cmd_pfc_set_portid,
7189                 NULL,
7190         },
7191 };
7192
7193 /* *** RESET CONFIGURATION *** */
7194 struct cmd_reset_result {
7195         cmdline_fixed_string_t reset;
7196         cmdline_fixed_string_t def;
7197 };
7198
7199 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7200                              struct cmdline *cl,
7201                              __rte_unused void *data)
7202 {
7203         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7204         set_def_fwd_config();
7205 }
7206
7207 cmdline_parse_token_string_t cmd_reset_set =
7208         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7209 cmdline_parse_token_string_t cmd_reset_def =
7210         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7211                                  "default");
7212
7213 cmdline_parse_inst_t cmd_reset = {
7214         .f = cmd_reset_parsed,
7215         .data = NULL,
7216         .help_str = "set default: Reset default forwarding configuration",
7217         .tokens = {
7218                 (void *)&cmd_reset_set,
7219                 (void *)&cmd_reset_def,
7220                 NULL,
7221         },
7222 };
7223
7224 /* *** START FORWARDING *** */
7225 struct cmd_start_result {
7226         cmdline_fixed_string_t start;
7227 };
7228
7229 cmdline_parse_token_string_t cmd_start_start =
7230         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7231
7232 static void cmd_start_parsed(__rte_unused void *parsed_result,
7233                              __rte_unused struct cmdline *cl,
7234                              __rte_unused void *data)
7235 {
7236         start_packet_forwarding(0);
7237 }
7238
7239 cmdline_parse_inst_t cmd_start = {
7240         .f = cmd_start_parsed,
7241         .data = NULL,
7242         .help_str = "start: Start packet forwarding",
7243         .tokens = {
7244                 (void *)&cmd_start_start,
7245                 NULL,
7246         },
7247 };
7248
7249 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7250 struct cmd_start_tx_first_result {
7251         cmdline_fixed_string_t start;
7252         cmdline_fixed_string_t tx_first;
7253 };
7254
7255 static void
7256 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7257                           __rte_unused struct cmdline *cl,
7258                           __rte_unused void *data)
7259 {
7260         start_packet_forwarding(1);
7261 }
7262
7263 cmdline_parse_token_string_t cmd_start_tx_first_start =
7264         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7265                                  "start");
7266 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7267         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7268                                  tx_first, "tx_first");
7269
7270 cmdline_parse_inst_t cmd_start_tx_first = {
7271         .f = cmd_start_tx_first_parsed,
7272         .data = NULL,
7273         .help_str = "start tx_first: Start packet forwarding, "
7274                 "after sending 1 burst of packets",
7275         .tokens = {
7276                 (void *)&cmd_start_tx_first_start,
7277                 (void *)&cmd_start_tx_first_tx_first,
7278                 NULL,
7279         },
7280 };
7281
7282 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7283 struct cmd_start_tx_first_n_result {
7284         cmdline_fixed_string_t start;
7285         cmdline_fixed_string_t tx_first;
7286         uint32_t tx_num;
7287 };
7288
7289 static void
7290 cmd_start_tx_first_n_parsed(void *parsed_result,
7291                           __rte_unused struct cmdline *cl,
7292                           __rte_unused void *data)
7293 {
7294         struct cmd_start_tx_first_n_result *res = parsed_result;
7295
7296         start_packet_forwarding(res->tx_num);
7297 }
7298
7299 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7300         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7301                         start, "start");
7302 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7303         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7304                         tx_first, "tx_first");
7305 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7306         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7307                         tx_num, UINT32);
7308
7309 cmdline_parse_inst_t cmd_start_tx_first_n = {
7310         .f = cmd_start_tx_first_n_parsed,
7311         .data = NULL,
7312         .help_str = "start tx_first <num>: "
7313                 "packet forwarding, after sending <num> bursts of packets",
7314         .tokens = {
7315                 (void *)&cmd_start_tx_first_n_start,
7316                 (void *)&cmd_start_tx_first_n_tx_first,
7317                 (void *)&cmd_start_tx_first_n_tx_num,
7318                 NULL,
7319         },
7320 };
7321
7322 /* *** SET LINK UP *** */
7323 struct cmd_set_link_up_result {
7324         cmdline_fixed_string_t set;
7325         cmdline_fixed_string_t link_up;
7326         cmdline_fixed_string_t port;
7327         portid_t port_id;
7328 };
7329
7330 cmdline_parse_token_string_t cmd_set_link_up_set =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7332 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7333         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7334                                 "link-up");
7335 cmdline_parse_token_string_t cmd_set_link_up_port =
7336         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7337 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7338         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7339
7340 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7341                              __rte_unused struct cmdline *cl,
7342                              __rte_unused void *data)
7343 {
7344         struct cmd_set_link_up_result *res = parsed_result;
7345         dev_set_link_up(res->port_id);
7346 }
7347
7348 cmdline_parse_inst_t cmd_set_link_up = {
7349         .f = cmd_set_link_up_parsed,
7350         .data = NULL,
7351         .help_str = "set link-up port <port id>",
7352         .tokens = {
7353                 (void *)&cmd_set_link_up_set,
7354                 (void *)&cmd_set_link_up_link_up,
7355                 (void *)&cmd_set_link_up_port,
7356                 (void *)&cmd_set_link_up_port_id,
7357                 NULL,
7358         },
7359 };
7360
7361 /* *** SET LINK DOWN *** */
7362 struct cmd_set_link_down_result {
7363         cmdline_fixed_string_t set;
7364         cmdline_fixed_string_t link_down;
7365         cmdline_fixed_string_t port;
7366         portid_t port_id;
7367 };
7368
7369 cmdline_parse_token_string_t cmd_set_link_down_set =
7370         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7371 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7372         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7373                                 "link-down");
7374 cmdline_parse_token_string_t cmd_set_link_down_port =
7375         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7376 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7377         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7378
7379 static void cmd_set_link_down_parsed(
7380                                 __rte_unused void *parsed_result,
7381                                 __rte_unused struct cmdline *cl,
7382                                 __rte_unused void *data)
7383 {
7384         struct cmd_set_link_down_result *res = parsed_result;
7385         dev_set_link_down(res->port_id);
7386 }
7387
7388 cmdline_parse_inst_t cmd_set_link_down = {
7389         .f = cmd_set_link_down_parsed,
7390         .data = NULL,
7391         .help_str = "set link-down port <port id>",
7392         .tokens = {
7393                 (void *)&cmd_set_link_down_set,
7394                 (void *)&cmd_set_link_down_link_down,
7395                 (void *)&cmd_set_link_down_port,
7396                 (void *)&cmd_set_link_down_port_id,
7397                 NULL,
7398         },
7399 };
7400
7401 /* *** SHOW CFG *** */
7402 struct cmd_showcfg_result {
7403         cmdline_fixed_string_t show;
7404         cmdline_fixed_string_t cfg;
7405         cmdline_fixed_string_t what;
7406 };
7407
7408 static void cmd_showcfg_parsed(void *parsed_result,
7409                                __rte_unused struct cmdline *cl,
7410                                __rte_unused void *data)
7411 {
7412         struct cmd_showcfg_result *res = parsed_result;
7413         if (!strcmp(res->what, "rxtx"))
7414                 rxtx_config_display();
7415         else if (!strcmp(res->what, "cores"))
7416                 fwd_lcores_config_display();
7417         else if (!strcmp(res->what, "fwd"))
7418                 pkt_fwd_config_display(&cur_fwd_config);
7419         else if (!strcmp(res->what, "txpkts"))
7420                 show_tx_pkt_segments();
7421 }
7422
7423 cmdline_parse_token_string_t cmd_showcfg_show =
7424         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7425 cmdline_parse_token_string_t cmd_showcfg_port =
7426         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7427 cmdline_parse_token_string_t cmd_showcfg_what =
7428         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7429                                  "rxtx#cores#fwd#txpkts");
7430
7431 cmdline_parse_inst_t cmd_showcfg = {
7432         .f = cmd_showcfg_parsed,
7433         .data = NULL,
7434         .help_str = "show config rxtx|cores|fwd|txpkts",
7435         .tokens = {
7436                 (void *)&cmd_showcfg_show,
7437                 (void *)&cmd_showcfg_port,
7438                 (void *)&cmd_showcfg_what,
7439                 NULL,
7440         },
7441 };
7442
7443 /* *** SHOW ALL PORT INFO *** */
7444 struct cmd_showportall_result {
7445         cmdline_fixed_string_t show;
7446         cmdline_fixed_string_t port;
7447         cmdline_fixed_string_t what;
7448         cmdline_fixed_string_t all;
7449 };
7450
7451 static void cmd_showportall_parsed(void *parsed_result,
7452                                 __rte_unused struct cmdline *cl,
7453                                 __rte_unused void *data)
7454 {
7455         portid_t i;
7456
7457         struct cmd_showportall_result *res = parsed_result;
7458         if (!strcmp(res->show, "clear")) {
7459                 if (!strcmp(res->what, "stats"))
7460                         RTE_ETH_FOREACH_DEV(i)
7461                                 nic_stats_clear(i);
7462                 else if (!strcmp(res->what, "xstats"))
7463                         RTE_ETH_FOREACH_DEV(i)
7464                                 nic_xstats_clear(i);
7465         } else if (!strcmp(res->what, "info"))
7466                 RTE_ETH_FOREACH_DEV(i)
7467                         port_infos_display(i);
7468         else if (!strcmp(res->what, "summary")) {
7469                 port_summary_header_display();
7470                 RTE_ETH_FOREACH_DEV(i)
7471                         port_summary_display(i);
7472         }
7473         else if (!strcmp(res->what, "stats"))
7474                 RTE_ETH_FOREACH_DEV(i)
7475                         nic_stats_display(i);
7476         else if (!strcmp(res->what, "xstats"))
7477                 RTE_ETH_FOREACH_DEV(i)
7478                         nic_xstats_display(i);
7479         else if (!strcmp(res->what, "fdir"))
7480                 RTE_ETH_FOREACH_DEV(i)
7481                         fdir_get_infos(i);
7482         else if (!strcmp(res->what, "stat_qmap"))
7483                 RTE_ETH_FOREACH_DEV(i)
7484                         nic_stats_mapping_display(i);
7485         else if (!strcmp(res->what, "dcb_tc"))
7486                 RTE_ETH_FOREACH_DEV(i)
7487                         port_dcb_info_display(i);
7488         else if (!strcmp(res->what, "cap"))
7489                 RTE_ETH_FOREACH_DEV(i)
7490                         port_offload_cap_display(i);
7491 }
7492
7493 cmdline_parse_token_string_t cmd_showportall_show =
7494         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7495                                  "show#clear");
7496 cmdline_parse_token_string_t cmd_showportall_port =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7498 cmdline_parse_token_string_t cmd_showportall_what =
7499         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7500                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7501 cmdline_parse_token_string_t cmd_showportall_all =
7502         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7503 cmdline_parse_inst_t cmd_showportall = {
7504         .f = cmd_showportall_parsed,
7505         .data = NULL,
7506         .help_str = "show|clear port "
7507                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7508         .tokens = {
7509                 (void *)&cmd_showportall_show,
7510                 (void *)&cmd_showportall_port,
7511                 (void *)&cmd_showportall_what,
7512                 (void *)&cmd_showportall_all,
7513                 NULL,
7514         },
7515 };
7516
7517 /* *** SHOW PORT INFO *** */
7518 struct cmd_showport_result {
7519         cmdline_fixed_string_t show;
7520         cmdline_fixed_string_t port;
7521         cmdline_fixed_string_t what;
7522         uint16_t portnum;
7523 };
7524
7525 static void cmd_showport_parsed(void *parsed_result,
7526                                 __rte_unused struct cmdline *cl,
7527                                 __rte_unused void *data)
7528 {
7529         struct cmd_showport_result *res = parsed_result;
7530         if (!strcmp(res->show, "clear")) {
7531                 if (!strcmp(res->what, "stats"))
7532                         nic_stats_clear(res->portnum);
7533                 else if (!strcmp(res->what, "xstats"))
7534                         nic_xstats_clear(res->portnum);
7535         } else if (!strcmp(res->what, "info"))
7536                 port_infos_display(res->portnum);
7537         else if (!strcmp(res->what, "summary")) {
7538                 port_summary_header_display();
7539                 port_summary_display(res->portnum);
7540         }
7541         else if (!strcmp(res->what, "stats"))
7542                 nic_stats_display(res->portnum);
7543         else if (!strcmp(res->what, "xstats"))
7544                 nic_xstats_display(res->portnum);
7545         else if (!strcmp(res->what, "fdir"))
7546                  fdir_get_infos(res->portnum);
7547         else if (!strcmp(res->what, "stat_qmap"))
7548                 nic_stats_mapping_display(res->portnum);
7549         else if (!strcmp(res->what, "dcb_tc"))
7550                 port_dcb_info_display(res->portnum);
7551         else if (!strcmp(res->what, "cap"))
7552                 port_offload_cap_display(res->portnum);
7553 }
7554
7555 cmdline_parse_token_string_t cmd_showport_show =
7556         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7557                                  "show#clear");
7558 cmdline_parse_token_string_t cmd_showport_port =
7559         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7560 cmdline_parse_token_string_t cmd_showport_what =
7561         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7562                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7563 cmdline_parse_token_num_t cmd_showport_portnum =
7564         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7565
7566 cmdline_parse_inst_t cmd_showport = {
7567         .f = cmd_showport_parsed,
7568         .data = NULL,
7569         .help_str = "show|clear port "
7570                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7571                 "<port_id>",
7572         .tokens = {
7573                 (void *)&cmd_showport_show,
7574                 (void *)&cmd_showport_port,
7575                 (void *)&cmd_showport_what,
7576                 (void *)&cmd_showport_portnum,
7577                 NULL,
7578         },
7579 };
7580
7581 /* *** SHOW DEVICE INFO *** */
7582 struct cmd_showdevice_result {
7583         cmdline_fixed_string_t show;
7584         cmdline_fixed_string_t device;
7585         cmdline_fixed_string_t what;
7586         cmdline_fixed_string_t identifier;
7587 };
7588
7589 static void cmd_showdevice_parsed(void *parsed_result,
7590                                 __rte_unused struct cmdline *cl,
7591                                 __rte_unused void *data)
7592 {
7593         struct cmd_showdevice_result *res = parsed_result;
7594         if (!strcmp(res->what, "info")) {
7595                 if (!strcmp(res->identifier, "all"))
7596                         device_infos_display(NULL);
7597                 else
7598                         device_infos_display(res->identifier);
7599         }
7600 }
7601
7602 cmdline_parse_token_string_t cmd_showdevice_show =
7603         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7604                                  "show");
7605 cmdline_parse_token_string_t cmd_showdevice_device =
7606         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7607 cmdline_parse_token_string_t cmd_showdevice_what =
7608         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7609                                  "info");
7610 cmdline_parse_token_string_t cmd_showdevice_identifier =
7611         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7612                         identifier, NULL);
7613
7614 cmdline_parse_inst_t cmd_showdevice = {
7615         .f = cmd_showdevice_parsed,
7616         .data = NULL,
7617         .help_str = "show device info <identifier>|all",
7618         .tokens = {
7619                 (void *)&cmd_showdevice_show,
7620                 (void *)&cmd_showdevice_device,
7621                 (void *)&cmd_showdevice_what,
7622                 (void *)&cmd_showdevice_identifier,
7623                 NULL,
7624         },
7625 };
7626 /* *** SHOW QUEUE INFO *** */
7627 struct cmd_showqueue_result {
7628         cmdline_fixed_string_t show;
7629         cmdline_fixed_string_t type;
7630         cmdline_fixed_string_t what;
7631         uint16_t portnum;
7632         uint16_t queuenum;
7633 };
7634
7635 static void
7636 cmd_showqueue_parsed(void *parsed_result,
7637         __rte_unused struct cmdline *cl,
7638         __rte_unused void *data)
7639 {
7640         struct cmd_showqueue_result *res = parsed_result;
7641
7642         if (!strcmp(res->type, "rxq"))
7643                 rx_queue_infos_display(res->portnum, res->queuenum);
7644         else if (!strcmp(res->type, "txq"))
7645                 tx_queue_infos_display(res->portnum, res->queuenum);
7646 }
7647
7648 cmdline_parse_token_string_t cmd_showqueue_show =
7649         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7650 cmdline_parse_token_string_t cmd_showqueue_type =
7651         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7652 cmdline_parse_token_string_t cmd_showqueue_what =
7653         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7654 cmdline_parse_token_num_t cmd_showqueue_portnum =
7655         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7656 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7657         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7658
7659 cmdline_parse_inst_t cmd_showqueue = {
7660         .f = cmd_showqueue_parsed,
7661         .data = NULL,
7662         .help_str = "show rxq|txq info <port_id> <queue_id>",
7663         .tokens = {
7664                 (void *)&cmd_showqueue_show,
7665                 (void *)&cmd_showqueue_type,
7666                 (void *)&cmd_showqueue_what,
7667                 (void *)&cmd_showqueue_portnum,
7668                 (void *)&cmd_showqueue_queuenum,
7669                 NULL,
7670         },
7671 };
7672
7673 /* show/clear fwd engine statistics */
7674 struct fwd_result {
7675         cmdline_fixed_string_t action;
7676         cmdline_fixed_string_t fwd;
7677         cmdline_fixed_string_t stats;
7678         cmdline_fixed_string_t all;
7679 };
7680
7681 cmdline_parse_token_string_t cmd_fwd_action =
7682         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7683 cmdline_parse_token_string_t cmd_fwd_fwd =
7684         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7685 cmdline_parse_token_string_t cmd_fwd_stats =
7686         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7687 cmdline_parse_token_string_t cmd_fwd_all =
7688         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7689
7690 static void
7691 cmd_showfwdall_parsed(void *parsed_result,
7692                       __rte_unused struct cmdline *cl,
7693                       __rte_unused void *data)
7694 {
7695         struct fwd_result *res = parsed_result;
7696
7697         if (!strcmp(res->action, "show"))
7698                 fwd_stats_display();
7699         else
7700                 fwd_stats_reset();
7701 }
7702
7703 static cmdline_parse_inst_t cmd_showfwdall = {
7704         .f = cmd_showfwdall_parsed,
7705         .data = NULL,
7706         .help_str = "show|clear fwd stats all",
7707         .tokens = {
7708                 (void *)&cmd_fwd_action,
7709                 (void *)&cmd_fwd_fwd,
7710                 (void *)&cmd_fwd_stats,
7711                 (void *)&cmd_fwd_all,
7712                 NULL,
7713         },
7714 };
7715
7716 /* *** READ PORT REGISTER *** */
7717 struct cmd_read_reg_result {
7718         cmdline_fixed_string_t read;
7719         cmdline_fixed_string_t reg;
7720         portid_t port_id;
7721         uint32_t reg_off;
7722 };
7723
7724 static void
7725 cmd_read_reg_parsed(void *parsed_result,
7726                     __rte_unused struct cmdline *cl,
7727                     __rte_unused void *data)
7728 {
7729         struct cmd_read_reg_result *res = parsed_result;
7730         port_reg_display(res->port_id, res->reg_off);
7731 }
7732
7733 cmdline_parse_token_string_t cmd_read_reg_read =
7734         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7735 cmdline_parse_token_string_t cmd_read_reg_reg =
7736         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7737 cmdline_parse_token_num_t cmd_read_reg_port_id =
7738         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7739 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7740         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7741
7742 cmdline_parse_inst_t cmd_read_reg = {
7743         .f = cmd_read_reg_parsed,
7744         .data = NULL,
7745         .help_str = "read reg <port_id> <reg_off>",
7746         .tokens = {
7747                 (void *)&cmd_read_reg_read,
7748                 (void *)&cmd_read_reg_reg,
7749                 (void *)&cmd_read_reg_port_id,
7750                 (void *)&cmd_read_reg_reg_off,
7751                 NULL,
7752         },
7753 };
7754
7755 /* *** READ PORT REGISTER BIT FIELD *** */
7756 struct cmd_read_reg_bit_field_result {
7757         cmdline_fixed_string_t read;
7758         cmdline_fixed_string_t regfield;
7759         portid_t port_id;
7760         uint32_t reg_off;
7761         uint8_t bit1_pos;
7762         uint8_t bit2_pos;
7763 };
7764
7765 static void
7766 cmd_read_reg_bit_field_parsed(void *parsed_result,
7767                               __rte_unused struct cmdline *cl,
7768                               __rte_unused void *data)
7769 {
7770         struct cmd_read_reg_bit_field_result *res = parsed_result;
7771         port_reg_bit_field_display(res->port_id, res->reg_off,
7772                                    res->bit1_pos, res->bit2_pos);
7773 }
7774
7775 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7776         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7777                                  "read");
7778 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7779         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7780                                  regfield, "regfield");
7781 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7782         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7783                               UINT16);
7784 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7785         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7786                               UINT32);
7787 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7788         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7789                               UINT8);
7790 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7791         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7792                               UINT8);
7793
7794 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7795         .f = cmd_read_reg_bit_field_parsed,
7796         .data = NULL,
7797         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7798         "Read register bit field between bit_x and bit_y included",
7799         .tokens = {
7800                 (void *)&cmd_read_reg_bit_field_read,
7801                 (void *)&cmd_read_reg_bit_field_regfield,
7802                 (void *)&cmd_read_reg_bit_field_port_id,
7803                 (void *)&cmd_read_reg_bit_field_reg_off,
7804                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7805                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7806                 NULL,
7807         },
7808 };
7809
7810 /* *** READ PORT REGISTER BIT *** */
7811 struct cmd_read_reg_bit_result {
7812         cmdline_fixed_string_t read;
7813         cmdline_fixed_string_t regbit;
7814         portid_t port_id;
7815         uint32_t reg_off;
7816         uint8_t bit_pos;
7817 };
7818
7819 static void
7820 cmd_read_reg_bit_parsed(void *parsed_result,
7821                         __rte_unused struct cmdline *cl,
7822                         __rte_unused void *data)
7823 {
7824         struct cmd_read_reg_bit_result *res = parsed_result;
7825         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7826 }
7827
7828 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7829         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7830 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7831         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7832                                  regbit, "regbit");
7833 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7834         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7835 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7836         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7837 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7838         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7839
7840 cmdline_parse_inst_t cmd_read_reg_bit = {
7841         .f = cmd_read_reg_bit_parsed,
7842         .data = NULL,
7843         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7844         .tokens = {
7845                 (void *)&cmd_read_reg_bit_read,
7846                 (void *)&cmd_read_reg_bit_regbit,
7847                 (void *)&cmd_read_reg_bit_port_id,
7848                 (void *)&cmd_read_reg_bit_reg_off,
7849                 (void *)&cmd_read_reg_bit_bit_pos,
7850                 NULL,
7851         },
7852 };
7853
7854 /* *** WRITE PORT REGISTER *** */
7855 struct cmd_write_reg_result {
7856         cmdline_fixed_string_t write;
7857         cmdline_fixed_string_t reg;
7858         portid_t port_id;
7859         uint32_t reg_off;
7860         uint32_t value;
7861 };
7862
7863 static void
7864 cmd_write_reg_parsed(void *parsed_result,
7865                      __rte_unused struct cmdline *cl,
7866                      __rte_unused void *data)
7867 {
7868         struct cmd_write_reg_result *res = parsed_result;
7869         port_reg_set(res->port_id, res->reg_off, res->value);
7870 }
7871
7872 cmdline_parse_token_string_t cmd_write_reg_write =
7873         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7874 cmdline_parse_token_string_t cmd_write_reg_reg =
7875         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7876 cmdline_parse_token_num_t cmd_write_reg_port_id =
7877         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7878 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7879         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7880 cmdline_parse_token_num_t cmd_write_reg_value =
7881         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7882
7883 cmdline_parse_inst_t cmd_write_reg = {
7884         .f = cmd_write_reg_parsed,
7885         .data = NULL,
7886         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7887         .tokens = {
7888                 (void *)&cmd_write_reg_write,
7889                 (void *)&cmd_write_reg_reg,
7890                 (void *)&cmd_write_reg_port_id,
7891                 (void *)&cmd_write_reg_reg_off,
7892                 (void *)&cmd_write_reg_value,
7893                 NULL,
7894         },
7895 };
7896
7897 /* *** WRITE PORT REGISTER BIT FIELD *** */
7898 struct cmd_write_reg_bit_field_result {
7899         cmdline_fixed_string_t write;
7900         cmdline_fixed_string_t regfield;
7901         portid_t port_id;
7902         uint32_t reg_off;
7903         uint8_t bit1_pos;
7904         uint8_t bit2_pos;
7905         uint32_t value;
7906 };
7907
7908 static void
7909 cmd_write_reg_bit_field_parsed(void *parsed_result,
7910                                __rte_unused struct cmdline *cl,
7911                                __rte_unused void *data)
7912 {
7913         struct cmd_write_reg_bit_field_result *res = parsed_result;
7914         port_reg_bit_field_set(res->port_id, res->reg_off,
7915                           res->bit1_pos, res->bit2_pos, res->value);
7916 }
7917
7918 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7919         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7920                                  "write");
7921 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7922         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7923                                  regfield, "regfield");
7924 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7925         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7926                               UINT16);
7927 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7928         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7929                               UINT32);
7930 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7931         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7932                               UINT8);
7933 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7934         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7935                               UINT8);
7936 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7937         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7938                               UINT32);
7939
7940 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7941         .f = cmd_write_reg_bit_field_parsed,
7942         .data = NULL,
7943         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7944                 "<reg_value>: "
7945                 "Set register bit field between bit_x and bit_y included",
7946         .tokens = {
7947                 (void *)&cmd_write_reg_bit_field_write,
7948                 (void *)&cmd_write_reg_bit_field_regfield,
7949                 (void *)&cmd_write_reg_bit_field_port_id,
7950                 (void *)&cmd_write_reg_bit_field_reg_off,
7951                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7952                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7953                 (void *)&cmd_write_reg_bit_field_value,
7954                 NULL,
7955         },
7956 };
7957
7958 /* *** WRITE PORT REGISTER BIT *** */
7959 struct cmd_write_reg_bit_result {
7960         cmdline_fixed_string_t write;
7961         cmdline_fixed_string_t regbit;
7962         portid_t port_id;
7963         uint32_t reg_off;
7964         uint8_t bit_pos;
7965         uint8_t value;
7966 };
7967
7968 static void
7969 cmd_write_reg_bit_parsed(void *parsed_result,
7970                          __rte_unused struct cmdline *cl,
7971                          __rte_unused void *data)
7972 {
7973         struct cmd_write_reg_bit_result *res = parsed_result;
7974         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7975 }
7976
7977 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7978         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7979                                  "write");
7980 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7981         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7982                                  regbit, "regbit");
7983 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7985 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7986         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7987 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7988         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7989 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7990         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7991
7992 cmdline_parse_inst_t cmd_write_reg_bit = {
7993         .f = cmd_write_reg_bit_parsed,
7994         .data = NULL,
7995         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7996                 "0 <= bit_x <= 31",
7997         .tokens = {
7998                 (void *)&cmd_write_reg_bit_write,
7999                 (void *)&cmd_write_reg_bit_regbit,
8000                 (void *)&cmd_write_reg_bit_port_id,
8001                 (void *)&cmd_write_reg_bit_reg_off,
8002                 (void *)&cmd_write_reg_bit_bit_pos,
8003                 (void *)&cmd_write_reg_bit_value,
8004                 NULL,
8005         },
8006 };
8007
8008 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8009 struct cmd_read_rxd_txd_result {
8010         cmdline_fixed_string_t read;
8011         cmdline_fixed_string_t rxd_txd;
8012         portid_t port_id;
8013         uint16_t queue_id;
8014         uint16_t desc_id;
8015 };
8016
8017 static void
8018 cmd_read_rxd_txd_parsed(void *parsed_result,
8019                         __rte_unused struct cmdline *cl,
8020                         __rte_unused void *data)
8021 {
8022         struct cmd_read_rxd_txd_result *res = parsed_result;
8023
8024         if (!strcmp(res->rxd_txd, "rxd"))
8025                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8026         else if (!strcmp(res->rxd_txd, "txd"))
8027                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8028 }
8029
8030 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8031         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8032 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8033         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8034                                  "rxd#txd");
8035 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8036         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8037 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8038         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8039 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8040         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8041
8042 cmdline_parse_inst_t cmd_read_rxd_txd = {
8043         .f = cmd_read_rxd_txd_parsed,
8044         .data = NULL,
8045         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8046         .tokens = {
8047                 (void *)&cmd_read_rxd_txd_read,
8048                 (void *)&cmd_read_rxd_txd_rxd_txd,
8049                 (void *)&cmd_read_rxd_txd_port_id,
8050                 (void *)&cmd_read_rxd_txd_queue_id,
8051                 (void *)&cmd_read_rxd_txd_desc_id,
8052                 NULL,
8053         },
8054 };
8055
8056 /* *** QUIT *** */
8057 struct cmd_quit_result {
8058         cmdline_fixed_string_t quit;
8059 };
8060
8061 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8062                             struct cmdline *cl,
8063                             __rte_unused void *data)
8064 {
8065         cmdline_quit(cl);
8066 }
8067
8068 cmdline_parse_token_string_t cmd_quit_quit =
8069         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8070
8071 cmdline_parse_inst_t cmd_quit = {
8072         .f = cmd_quit_parsed,
8073         .data = NULL,
8074         .help_str = "quit: Exit application",
8075         .tokens = {
8076                 (void *)&cmd_quit_quit,
8077                 NULL,
8078         },
8079 };
8080
8081 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8082 struct cmd_mac_addr_result {
8083         cmdline_fixed_string_t mac_addr_cmd;
8084         cmdline_fixed_string_t what;
8085         uint16_t port_num;
8086         struct rte_ether_addr address;
8087 };
8088
8089 static void cmd_mac_addr_parsed(void *parsed_result,
8090                 __rte_unused struct cmdline *cl,
8091                 __rte_unused void *data)
8092 {
8093         struct cmd_mac_addr_result *res = parsed_result;
8094         int ret;
8095
8096         if (strcmp(res->what, "add") == 0)
8097                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8098         else if (strcmp(res->what, "set") == 0)
8099                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8100                                                        &res->address);
8101         else
8102                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8103
8104         /* check the return value and print it if is < 0 */
8105         if(ret < 0)
8106                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8107
8108 }
8109
8110 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8111         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8112                                 "mac_addr");
8113 cmdline_parse_token_string_t cmd_mac_addr_what =
8114         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8115                                 "add#remove#set");
8116 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8117                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8118                                         UINT16);
8119 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8120                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8121
8122 cmdline_parse_inst_t cmd_mac_addr = {
8123         .f = cmd_mac_addr_parsed,
8124         .data = (void *)0,
8125         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8126                         "Add/Remove/Set MAC address on port_id",
8127         .tokens = {
8128                 (void *)&cmd_mac_addr_cmd,
8129                 (void *)&cmd_mac_addr_what,
8130                 (void *)&cmd_mac_addr_portnum,
8131                 (void *)&cmd_mac_addr_addr,
8132                 NULL,
8133         },
8134 };
8135
8136 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8137 struct cmd_eth_peer_result {
8138         cmdline_fixed_string_t set;
8139         cmdline_fixed_string_t eth_peer;
8140         portid_t port_id;
8141         cmdline_fixed_string_t peer_addr;
8142 };
8143
8144 static void cmd_set_eth_peer_parsed(void *parsed_result,
8145                         __rte_unused struct cmdline *cl,
8146                         __rte_unused void *data)
8147 {
8148                 struct cmd_eth_peer_result *res = parsed_result;
8149
8150                 if (test_done == 0) {
8151                         printf("Please stop forwarding first\n");
8152                         return;
8153                 }
8154                 if (!strcmp(res->eth_peer, "eth-peer")) {
8155                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8156                         fwd_config_setup();
8157                 }
8158 }
8159 cmdline_parse_token_string_t cmd_eth_peer_set =
8160         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8161 cmdline_parse_token_string_t cmd_eth_peer =
8162         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8163 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8164         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8165 cmdline_parse_token_string_t cmd_eth_peer_addr =
8166         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8167
8168 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8169         .f = cmd_set_eth_peer_parsed,
8170         .data = NULL,
8171         .help_str = "set eth-peer <port_id> <peer_mac>",
8172         .tokens = {
8173                 (void *)&cmd_eth_peer_set,
8174                 (void *)&cmd_eth_peer,
8175                 (void *)&cmd_eth_peer_port_id,
8176                 (void *)&cmd_eth_peer_addr,
8177                 NULL,
8178         },
8179 };
8180
8181 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8182 struct cmd_set_qmap_result {
8183         cmdline_fixed_string_t set;
8184         cmdline_fixed_string_t qmap;
8185         cmdline_fixed_string_t what;
8186         portid_t port_id;
8187         uint16_t queue_id;
8188         uint8_t map_value;
8189 };
8190
8191 static void
8192 cmd_set_qmap_parsed(void *parsed_result,
8193                        __rte_unused struct cmdline *cl,
8194                        __rte_unused void *data)
8195 {
8196         struct cmd_set_qmap_result *res = parsed_result;
8197         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8198
8199         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8200 }
8201
8202 cmdline_parse_token_string_t cmd_setqmap_set =
8203         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8204                                  set, "set");
8205 cmdline_parse_token_string_t cmd_setqmap_qmap =
8206         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8207                                  qmap, "stat_qmap");
8208 cmdline_parse_token_string_t cmd_setqmap_what =
8209         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8210                                  what, "tx#rx");
8211 cmdline_parse_token_num_t cmd_setqmap_portid =
8212         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8213                               port_id, UINT16);
8214 cmdline_parse_token_num_t cmd_setqmap_queueid =
8215         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8216                               queue_id, UINT16);
8217 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8218         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8219                               map_value, UINT8);
8220
8221 cmdline_parse_inst_t cmd_set_qmap = {
8222         .f = cmd_set_qmap_parsed,
8223         .data = NULL,
8224         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8225                 "Set statistics mapping value on tx|rx queue_id of port_id",
8226         .tokens = {
8227                 (void *)&cmd_setqmap_set,
8228                 (void *)&cmd_setqmap_qmap,
8229                 (void *)&cmd_setqmap_what,
8230                 (void *)&cmd_setqmap_portid,
8231                 (void *)&cmd_setqmap_queueid,
8232                 (void *)&cmd_setqmap_mapvalue,
8233                 NULL,
8234         },
8235 };
8236
8237 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8238 struct cmd_set_xstats_hide_zero_result {
8239         cmdline_fixed_string_t keyword;
8240         cmdline_fixed_string_t name;
8241         cmdline_fixed_string_t on_off;
8242 };
8243
8244 static void
8245 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8246                         __rte_unused struct cmdline *cl,
8247                         __rte_unused void *data)
8248 {
8249         struct cmd_set_xstats_hide_zero_result *res;
8250         uint16_t on_off = 0;
8251
8252         res = parsed_result;
8253         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8254         set_xstats_hide_zero(on_off);
8255 }
8256
8257 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8258         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8259                                  keyword, "set");
8260 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8261         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8262                                  name, "xstats-hide-zero");
8263 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8264         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8265                                  on_off, "on#off");
8266
8267 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8268         .f = cmd_set_xstats_hide_zero_parsed,
8269         .data = NULL,
8270         .help_str = "set xstats-hide-zero on|off",
8271         .tokens = {
8272                 (void *)&cmd_set_xstats_hide_zero_keyword,
8273                 (void *)&cmd_set_xstats_hide_zero_name,
8274                 (void *)&cmd_set_xstats_hide_zero_on_off,
8275                 NULL,
8276         },
8277 };
8278
8279 /* *** CONFIGURE UNICAST HASH TABLE *** */
8280 struct cmd_set_uc_hash_table {
8281         cmdline_fixed_string_t set;
8282         cmdline_fixed_string_t port;
8283         portid_t port_id;
8284         cmdline_fixed_string_t what;
8285         struct rte_ether_addr address;
8286         cmdline_fixed_string_t mode;
8287 };
8288
8289 static void
8290 cmd_set_uc_hash_parsed(void *parsed_result,
8291                        __rte_unused struct cmdline *cl,
8292                        __rte_unused void *data)
8293 {
8294         int ret=0;
8295         struct cmd_set_uc_hash_table *res = parsed_result;
8296
8297         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8298
8299         if (strcmp(res->what, "uta") == 0)
8300                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8301                                                 &res->address,(uint8_t)is_on);
8302         if (ret < 0)
8303                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8304
8305 }
8306
8307 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8308         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8309                                  set, "set");
8310 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8311         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8312                                  port, "port");
8313 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8314         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8315                               port_id, UINT16);
8316 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8317         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8318                                  what, "uta");
8319 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8320         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8321                                 address);
8322 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8324                                  mode, "on#off");
8325
8326 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8327         .f = cmd_set_uc_hash_parsed,
8328         .data = NULL,
8329         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8330         .tokens = {
8331                 (void *)&cmd_set_uc_hash_set,
8332                 (void *)&cmd_set_uc_hash_port,
8333                 (void *)&cmd_set_uc_hash_portid,
8334                 (void *)&cmd_set_uc_hash_what,
8335                 (void *)&cmd_set_uc_hash_mac,
8336                 (void *)&cmd_set_uc_hash_mode,
8337                 NULL,
8338         },
8339 };
8340
8341 struct cmd_set_uc_all_hash_table {
8342         cmdline_fixed_string_t set;
8343         cmdline_fixed_string_t port;
8344         portid_t port_id;
8345         cmdline_fixed_string_t what;
8346         cmdline_fixed_string_t value;
8347         cmdline_fixed_string_t mode;
8348 };
8349
8350 static void
8351 cmd_set_uc_all_hash_parsed(void *parsed_result,
8352                        __rte_unused struct cmdline *cl,
8353                        __rte_unused void *data)
8354 {
8355         int ret=0;
8356         struct cmd_set_uc_all_hash_table *res = parsed_result;
8357
8358         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8359
8360         if ((strcmp(res->what, "uta") == 0) &&
8361                 (strcmp(res->value, "all") == 0))
8362                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8363         if (ret < 0)
8364                 printf("bad unicast hash table parameter,"
8365                         "return code = %d \n", ret);
8366 }
8367
8368 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8369         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8370                                  set, "set");
8371 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8372         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8373                                  port, "port");
8374 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8375         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8376                               port_id, UINT16);
8377 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8378         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8379                                  what, "uta");
8380 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8381         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8382                                 value,"all");
8383 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8384         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8385                                  mode, "on#off");
8386
8387 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8388         .f = cmd_set_uc_all_hash_parsed,
8389         .data = NULL,
8390         .help_str = "set port <port_id> uta all on|off",
8391         .tokens = {
8392                 (void *)&cmd_set_uc_all_hash_set,
8393                 (void *)&cmd_set_uc_all_hash_port,
8394                 (void *)&cmd_set_uc_all_hash_portid,
8395                 (void *)&cmd_set_uc_all_hash_what,
8396                 (void *)&cmd_set_uc_all_hash_value,
8397                 (void *)&cmd_set_uc_all_hash_mode,
8398                 NULL,
8399         },
8400 };
8401
8402 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8403 struct cmd_set_vf_macvlan_filter {
8404         cmdline_fixed_string_t set;
8405         cmdline_fixed_string_t port;
8406         portid_t port_id;
8407         cmdline_fixed_string_t vf;
8408         uint8_t vf_id;
8409         struct rte_ether_addr address;
8410         cmdline_fixed_string_t filter_type;
8411         cmdline_fixed_string_t mode;
8412 };
8413
8414 static void
8415 cmd_set_vf_macvlan_parsed(void *parsed_result,
8416                        __rte_unused struct cmdline *cl,
8417                        __rte_unused void *data)
8418 {
8419         int is_on, ret = 0;
8420         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8421         struct rte_eth_mac_filter filter;
8422
8423         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8424
8425         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8426
8427         /* set VF MAC filter */
8428         filter.is_vf = 1;
8429
8430         /* set VF ID */
8431         filter.dst_id = res->vf_id;
8432
8433         if (!strcmp(res->filter_type, "exact-mac"))
8434                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8435         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8436                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8437         else if (!strcmp(res->filter_type, "hashmac"))
8438                 filter.filter_type = RTE_MAC_HASH_MATCH;
8439         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8440                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8441
8442         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8443
8444         if (is_on)
8445                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8446                                         RTE_ETH_FILTER_MACVLAN,
8447                                         RTE_ETH_FILTER_ADD,
8448                                          &filter);
8449         else
8450                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8451                                         RTE_ETH_FILTER_MACVLAN,
8452                                         RTE_ETH_FILTER_DELETE,
8453                                         &filter);
8454
8455         if (ret < 0)
8456                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8457
8458 }
8459
8460 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8461         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8462                                  set, "set");
8463 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8464         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8465                                  port, "port");
8466 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8467         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8468                               port_id, UINT16);
8469 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8470         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8471                                  vf, "vf");
8472 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8473         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8474                                 vf_id, UINT8);
8475 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8476         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8477                                 address);
8478 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8480                                 filter_type, "exact-mac#exact-mac-vlan"
8481                                 "#hashmac#hashmac-vlan");
8482 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8483         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8484                                  mode, "on#off");
8485
8486 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8487         .f = cmd_set_vf_macvlan_parsed,
8488         .data = NULL,
8489         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8490                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8491                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8492                 "hash match rule: hash match of MAC and exact match of VLAN",
8493         .tokens = {
8494                 (void *)&cmd_set_vf_macvlan_set,
8495                 (void *)&cmd_set_vf_macvlan_port,
8496                 (void *)&cmd_set_vf_macvlan_portid,
8497                 (void *)&cmd_set_vf_macvlan_vf,
8498                 (void *)&cmd_set_vf_macvlan_vf_id,
8499                 (void *)&cmd_set_vf_macvlan_mac,
8500                 (void *)&cmd_set_vf_macvlan_filter_type,
8501                 (void *)&cmd_set_vf_macvlan_mode,
8502                 NULL,
8503         },
8504 };
8505
8506 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8507 struct cmd_set_vf_traffic {
8508         cmdline_fixed_string_t set;
8509         cmdline_fixed_string_t port;
8510         portid_t port_id;
8511         cmdline_fixed_string_t vf;
8512         uint8_t vf_id;
8513         cmdline_fixed_string_t what;
8514         cmdline_fixed_string_t mode;
8515 };
8516
8517 static void
8518 cmd_set_vf_traffic_parsed(void *parsed_result,
8519                        __rte_unused struct cmdline *cl,
8520                        __rte_unused void *data)
8521 {
8522         struct cmd_set_vf_traffic *res = parsed_result;
8523         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8524         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8525
8526         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8527 }
8528
8529 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8530         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8531                                  set, "set");
8532 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8534                                  port, "port");
8535 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8536         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8537                               port_id, UINT16);
8538 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8539         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8540                                  vf, "vf");
8541 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8542         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8543                               vf_id, UINT8);
8544 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8545         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8546                                  what, "tx#rx");
8547 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8548         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8549                                  mode, "on#off");
8550
8551 cmdline_parse_inst_t cmd_set_vf_traffic = {
8552         .f = cmd_set_vf_traffic_parsed,
8553         .data = NULL,
8554         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8555         .tokens = {
8556                 (void *)&cmd_setvf_traffic_set,
8557                 (void *)&cmd_setvf_traffic_port,
8558                 (void *)&cmd_setvf_traffic_portid,
8559                 (void *)&cmd_setvf_traffic_vf,
8560                 (void *)&cmd_setvf_traffic_vfid,
8561                 (void *)&cmd_setvf_traffic_what,
8562                 (void *)&cmd_setvf_traffic_mode,
8563                 NULL,
8564         },
8565 };
8566
8567 /* *** CONFIGURE VF RECEIVE MODE *** */
8568 struct cmd_set_vf_rxmode {
8569         cmdline_fixed_string_t set;
8570         cmdline_fixed_string_t port;
8571         portid_t port_id;
8572         cmdline_fixed_string_t vf;
8573         uint8_t vf_id;
8574         cmdline_fixed_string_t what;
8575         cmdline_fixed_string_t mode;
8576         cmdline_fixed_string_t on;
8577 };
8578
8579 static void
8580 cmd_set_vf_rxmode_parsed(void *parsed_result,
8581                        __rte_unused struct cmdline *cl,
8582                        __rte_unused void *data)
8583 {
8584         int ret = -ENOTSUP;
8585         uint16_t vf_rxmode = 0;
8586         struct cmd_set_vf_rxmode *res = parsed_result;
8587
8588         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8589         if (!strcmp(res->what,"rxmode")) {
8590                 if (!strcmp(res->mode, "AUPE"))
8591                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8592                 else if (!strcmp(res->mode, "ROPE"))
8593                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8594                 else if (!strcmp(res->mode, "BAM"))
8595                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8596                 else if (!strncmp(res->mode, "MPE",3))
8597                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8598         }
8599
8600         RTE_SET_USED(is_on);
8601
8602 #ifdef RTE_LIBRTE_IXGBE_PMD
8603         if (ret == -ENOTSUP)
8604                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8605                                                   vf_rxmode, (uint8_t)is_on);
8606 #endif
8607 #ifdef RTE_LIBRTE_BNXT_PMD
8608         if (ret == -ENOTSUP)
8609                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8610                                                  vf_rxmode, (uint8_t)is_on);
8611 #endif
8612         if (ret < 0)
8613                 printf("bad VF receive mode parameter, return code = %d \n",
8614                 ret);
8615 }
8616
8617 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8618         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8619                                  set, "set");
8620 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8621         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8622                                  port, "port");
8623 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8624         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8625                               port_id, UINT16);
8626 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8627         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8628                                  vf, "vf");
8629 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8630         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8631                               vf_id, UINT8);
8632 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8633         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8634                                  what, "rxmode");
8635 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8636         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8637                                  mode, "AUPE#ROPE#BAM#MPE");
8638 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8639         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8640                                  on, "on#off");
8641
8642 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8643         .f = cmd_set_vf_rxmode_parsed,
8644         .data = NULL,
8645         .help_str = "set port <port_id> vf <vf_id> rxmode "
8646                 "AUPE|ROPE|BAM|MPE on|off",
8647         .tokens = {
8648                 (void *)&cmd_set_vf_rxmode_set,
8649                 (void *)&cmd_set_vf_rxmode_port,
8650                 (void *)&cmd_set_vf_rxmode_portid,
8651                 (void *)&cmd_set_vf_rxmode_vf,
8652                 (void *)&cmd_set_vf_rxmode_vfid,
8653                 (void *)&cmd_set_vf_rxmode_what,
8654                 (void *)&cmd_set_vf_rxmode_mode,
8655                 (void *)&cmd_set_vf_rxmode_on,
8656                 NULL,
8657         },
8658 };
8659
8660 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8661 struct cmd_vf_mac_addr_result {
8662         cmdline_fixed_string_t mac_addr_cmd;
8663         cmdline_fixed_string_t what;
8664         cmdline_fixed_string_t port;
8665         uint16_t port_num;
8666         cmdline_fixed_string_t vf;
8667         uint8_t vf_num;
8668         struct rte_ether_addr address;
8669 };
8670
8671 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8672                 __rte_unused struct cmdline *cl,
8673                 __rte_unused void *data)
8674 {
8675         struct cmd_vf_mac_addr_result *res = parsed_result;
8676         int ret = -ENOTSUP;
8677
8678         if (strcmp(res->what, "add") != 0)
8679                 return;
8680
8681 #ifdef RTE_LIBRTE_I40E_PMD
8682         if (ret == -ENOTSUP)
8683                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8684                                                    &res->address);
8685 #endif
8686 #ifdef RTE_LIBRTE_BNXT_PMD
8687         if (ret == -ENOTSUP)
8688                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8689                                                 res->vf_num);
8690 #endif
8691
8692         if(ret < 0)
8693                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8694
8695 }
8696
8697 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8698         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8699                                 mac_addr_cmd,"mac_addr");
8700 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8701         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8702                                 what,"add");
8703 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8704         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8705                                 port,"port");
8706 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8707         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8708                                 port_num, UINT16);
8709 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8710         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8711                                 vf,"vf");
8712 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8713         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8714                                 vf_num, UINT8);
8715 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8716         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8717                                 address);
8718
8719 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8720         .f = cmd_vf_mac_addr_parsed,
8721         .data = (void *)0,
8722         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8723                 "Add MAC address filtering for a VF on port_id",
8724         .tokens = {
8725                 (void *)&cmd_vf_mac_addr_cmd,
8726                 (void *)&cmd_vf_mac_addr_what,
8727                 (void *)&cmd_vf_mac_addr_port,
8728                 (void *)&cmd_vf_mac_addr_portnum,
8729                 (void *)&cmd_vf_mac_addr_vf,
8730                 (void *)&cmd_vf_mac_addr_vfnum,
8731                 (void *)&cmd_vf_mac_addr_addr,
8732                 NULL,
8733         },
8734 };
8735
8736 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8737 struct cmd_vf_rx_vlan_filter {
8738         cmdline_fixed_string_t rx_vlan;
8739         cmdline_fixed_string_t what;
8740         uint16_t vlan_id;
8741         cmdline_fixed_string_t port;
8742         portid_t port_id;
8743         cmdline_fixed_string_t vf;
8744         uint64_t vf_mask;
8745 };
8746
8747 static void
8748 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8749                           __rte_unused struct cmdline *cl,
8750                           __rte_unused void *data)
8751 {
8752         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8753         int ret = -ENOTSUP;
8754
8755         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8756
8757 #ifdef RTE_LIBRTE_IXGBE_PMD
8758         if (ret == -ENOTSUP)
8759                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8760                                 res->vlan_id, res->vf_mask, is_add);
8761 #endif
8762 #ifdef RTE_LIBRTE_I40E_PMD
8763         if (ret == -ENOTSUP)
8764                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8765                                 res->vlan_id, res->vf_mask, is_add);
8766 #endif
8767 #ifdef RTE_LIBRTE_BNXT_PMD
8768         if (ret == -ENOTSUP)
8769                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8770                                 res->vlan_id, res->vf_mask, is_add);
8771 #endif
8772
8773         switch (ret) {
8774         case 0:
8775                 break;
8776         case -EINVAL:
8777                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8778                                 res->vlan_id, res->vf_mask);
8779                 break;
8780         case -ENODEV:
8781                 printf("invalid port_id %d\n", res->port_id);
8782                 break;
8783         case -ENOTSUP:
8784                 printf("function not implemented or supported\n");
8785                 break;
8786         default:
8787                 printf("programming error: (%s)\n", strerror(-ret));
8788         }
8789 }
8790
8791 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8792         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8793                                  rx_vlan, "rx_vlan");
8794 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8795         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8796                                  what, "add#rm");
8797 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8798         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8799                               vlan_id, UINT16);
8800 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8801         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8802                                  port, "port");
8803 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8804         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8805                               port_id, UINT16);
8806 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8807         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8808                                  vf, "vf");
8809 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8810         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8811                               vf_mask, UINT64);
8812
8813 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8814         .f = cmd_vf_rx_vlan_filter_parsed,
8815         .data = NULL,
8816         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8817                 "(vf_mask = hexadecimal VF mask)",
8818         .tokens = {
8819                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8820                 (void *)&cmd_vf_rx_vlan_filter_what,
8821                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8822                 (void *)&cmd_vf_rx_vlan_filter_port,
8823                 (void *)&cmd_vf_rx_vlan_filter_portid,
8824                 (void *)&cmd_vf_rx_vlan_filter_vf,
8825                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8826                 NULL,
8827         },
8828 };
8829
8830 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8831 struct cmd_queue_rate_limit_result {
8832         cmdline_fixed_string_t set;
8833         cmdline_fixed_string_t port;
8834         uint16_t port_num;
8835         cmdline_fixed_string_t queue;
8836         uint8_t queue_num;
8837         cmdline_fixed_string_t rate;
8838         uint16_t rate_num;
8839 };
8840
8841 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8842                 __rte_unused struct cmdline *cl,
8843                 __rte_unused void *data)
8844 {
8845         struct cmd_queue_rate_limit_result *res = parsed_result;
8846         int ret = 0;
8847
8848         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8849                 && (strcmp(res->queue, "queue") == 0)
8850                 && (strcmp(res->rate, "rate") == 0))
8851                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8852                                         res->rate_num);
8853         if (ret < 0)
8854                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8855
8856 }
8857
8858 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8859         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8860                                 set, "set");
8861 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8862         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8863                                 port, "port");
8864 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8865         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8866                                 port_num, UINT16);
8867 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8868         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8869                                 queue, "queue");
8870 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8871         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8872                                 queue_num, UINT8);
8873 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8874         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8875                                 rate, "rate");
8876 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8877         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8878                                 rate_num, UINT16);
8879
8880 cmdline_parse_inst_t cmd_queue_rate_limit = {
8881         .f = cmd_queue_rate_limit_parsed,
8882         .data = (void *)0,
8883         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8884                 "Set rate limit for a queue on port_id",
8885         .tokens = {
8886                 (void *)&cmd_queue_rate_limit_set,
8887                 (void *)&cmd_queue_rate_limit_port,
8888                 (void *)&cmd_queue_rate_limit_portnum,
8889                 (void *)&cmd_queue_rate_limit_queue,
8890                 (void *)&cmd_queue_rate_limit_queuenum,
8891                 (void *)&cmd_queue_rate_limit_rate,
8892                 (void *)&cmd_queue_rate_limit_ratenum,
8893                 NULL,
8894         },
8895 };
8896
8897 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8898 struct cmd_vf_rate_limit_result {
8899         cmdline_fixed_string_t set;
8900         cmdline_fixed_string_t port;
8901         uint16_t port_num;
8902         cmdline_fixed_string_t vf;
8903         uint8_t vf_num;
8904         cmdline_fixed_string_t rate;
8905         uint16_t rate_num;
8906         cmdline_fixed_string_t q_msk;
8907         uint64_t q_msk_val;
8908 };
8909
8910 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8911                 __rte_unused struct cmdline *cl,
8912                 __rte_unused void *data)
8913 {
8914         struct cmd_vf_rate_limit_result *res = parsed_result;
8915         int ret = 0;
8916
8917         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8918                 && (strcmp(res->vf, "vf") == 0)
8919                 && (strcmp(res->rate, "rate") == 0)
8920                 && (strcmp(res->q_msk, "queue_mask") == 0))
8921                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8922                                         res->rate_num, res->q_msk_val);
8923         if (ret < 0)
8924                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8925
8926 }
8927
8928 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8929         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8930                                 set, "set");
8931 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8932         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8933                                 port, "port");
8934 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8935         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8936                                 port_num, UINT16);
8937 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8938         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8939                                 vf, "vf");
8940 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8941         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8942                                 vf_num, UINT8);
8943 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8944         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8945                                 rate, "rate");
8946 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8947         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8948                                 rate_num, UINT16);
8949 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8950         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8951                                 q_msk, "queue_mask");
8952 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8953         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8954                                 q_msk_val, UINT64);
8955
8956 cmdline_parse_inst_t cmd_vf_rate_limit = {
8957         .f = cmd_vf_rate_limit_parsed,
8958         .data = (void *)0,
8959         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8960                 "queue_mask <queue_mask_value>: "
8961                 "Set rate limit for queues of VF on port_id",
8962         .tokens = {
8963                 (void *)&cmd_vf_rate_limit_set,
8964                 (void *)&cmd_vf_rate_limit_port,
8965                 (void *)&cmd_vf_rate_limit_portnum,
8966                 (void *)&cmd_vf_rate_limit_vf,
8967                 (void *)&cmd_vf_rate_limit_vfnum,
8968                 (void *)&cmd_vf_rate_limit_rate,
8969                 (void *)&cmd_vf_rate_limit_ratenum,
8970                 (void *)&cmd_vf_rate_limit_q_msk,
8971                 (void *)&cmd_vf_rate_limit_q_msk_val,
8972                 NULL,
8973         },
8974 };
8975
8976 /* *** ADD TUNNEL FILTER OF A PORT *** */
8977 struct cmd_tunnel_filter_result {
8978         cmdline_fixed_string_t cmd;
8979         cmdline_fixed_string_t what;
8980         portid_t port_id;
8981         struct rte_ether_addr outer_mac;
8982         struct rte_ether_addr inner_mac;
8983         cmdline_ipaddr_t ip_value;
8984         uint16_t inner_vlan;
8985         cmdline_fixed_string_t tunnel_type;
8986         cmdline_fixed_string_t filter_type;
8987         uint32_t tenant_id;
8988         uint16_t queue_num;
8989 };
8990
8991 static void
8992 cmd_tunnel_filter_parsed(void *parsed_result,
8993                           __rte_unused struct cmdline *cl,
8994                           __rte_unused void *data)
8995 {
8996         struct cmd_tunnel_filter_result *res = parsed_result;
8997         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8998         int ret = 0;
8999
9000         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9001
9002         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9003         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9004         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9005
9006         if (res->ip_value.family == AF_INET) {
9007                 tunnel_filter_conf.ip_addr.ipv4_addr =
9008                         res->ip_value.addr.ipv4.s_addr;
9009                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9010         } else {
9011                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9012                         &(res->ip_value.addr.ipv6),
9013                         sizeof(struct in6_addr));
9014                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9015         }
9016
9017         if (!strcmp(res->filter_type, "imac-ivlan"))
9018                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9019         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9020                 tunnel_filter_conf.filter_type =
9021                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9022         else if (!strcmp(res->filter_type, "imac-tenid"))
9023                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9024         else if (!strcmp(res->filter_type, "imac"))
9025                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9026         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9027                 tunnel_filter_conf.filter_type =
9028                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9029         else if (!strcmp(res->filter_type, "oip"))
9030                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9031         else if (!strcmp(res->filter_type, "iip"))
9032                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9033         else {
9034                 printf("The filter type is not supported");
9035                 return;
9036         }
9037
9038         if (!strcmp(res->tunnel_type, "vxlan"))
9039                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9040         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9041                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9042         else if (!strcmp(res->tunnel_type, "nvgre"))
9043                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9044         else if (!strcmp(res->tunnel_type, "ipingre"))
9045                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9046         else {
9047                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9048                 return;
9049         }
9050
9051         tunnel_filter_conf.tenant_id = res->tenant_id;
9052         tunnel_filter_conf.queue_id = res->queue_num;
9053         if (!strcmp(res->what, "add"))
9054                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9055                                         RTE_ETH_FILTER_TUNNEL,
9056                                         RTE_ETH_FILTER_ADD,
9057                                         &tunnel_filter_conf);
9058         else
9059                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9060                                         RTE_ETH_FILTER_TUNNEL,
9061                                         RTE_ETH_FILTER_DELETE,
9062                                         &tunnel_filter_conf);
9063         if (ret < 0)
9064                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9065                                 strerror(-ret));
9066
9067 }
9068 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9069         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9070         cmd, "tunnel_filter");
9071 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9072         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9073         what, "add#rm");
9074 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9075         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9076         port_id, UINT16);
9077 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9078         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9079         outer_mac);
9080 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9081         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9082         inner_mac);
9083 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9084         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9085         inner_vlan, UINT16);
9086 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9087         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9088         ip_value);
9089 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9090         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9091         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9092
9093 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9094         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9095         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9096                 "imac#omac-imac-tenid");
9097 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9098         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9099         tenant_id, UINT32);
9100 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9101         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9102         queue_num, UINT16);
9103
9104 cmdline_parse_inst_t cmd_tunnel_filter = {
9105         .f = cmd_tunnel_filter_parsed,
9106         .data = (void *)0,
9107         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9108                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9109                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9110                 "<queue_id>: Add/Rm tunnel filter of a port",
9111         .tokens = {
9112                 (void *)&cmd_tunnel_filter_cmd,
9113                 (void *)&cmd_tunnel_filter_what,
9114                 (void *)&cmd_tunnel_filter_port_id,
9115                 (void *)&cmd_tunnel_filter_outer_mac,
9116                 (void *)&cmd_tunnel_filter_inner_mac,
9117                 (void *)&cmd_tunnel_filter_ip_value,
9118                 (void *)&cmd_tunnel_filter_innner_vlan,
9119                 (void *)&cmd_tunnel_filter_tunnel_type,
9120                 (void *)&cmd_tunnel_filter_filter_type,
9121                 (void *)&cmd_tunnel_filter_tenant_id,
9122                 (void *)&cmd_tunnel_filter_queue_num,
9123                 NULL,
9124         },
9125 };
9126
9127 /* *** CONFIGURE TUNNEL UDP PORT *** */
9128 struct cmd_tunnel_udp_config {
9129         cmdline_fixed_string_t cmd;
9130         cmdline_fixed_string_t what;
9131         uint16_t udp_port;
9132         portid_t port_id;
9133 };
9134
9135 static void
9136 cmd_tunnel_udp_config_parsed(void *parsed_result,
9137                           __rte_unused struct cmdline *cl,
9138                           __rte_unused void *data)
9139 {
9140         struct cmd_tunnel_udp_config *res = parsed_result;
9141         struct rte_eth_udp_tunnel tunnel_udp;
9142         int ret;
9143
9144         tunnel_udp.udp_port = res->udp_port;
9145
9146         if (!strcmp(res->cmd, "rx_vxlan_port"))
9147                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9148
9149         if (!strcmp(res->what, "add"))
9150                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9151                                                       &tunnel_udp);
9152         else
9153                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9154                                                          &tunnel_udp);
9155
9156         if (ret < 0)
9157                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9158 }
9159
9160 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9161         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9162                                 cmd, "rx_vxlan_port");
9163 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9164         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9165                                 what, "add#rm");
9166 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9167         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9168                                 udp_port, UINT16);
9169 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9170         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9171                                 port_id, UINT16);
9172
9173 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9174         .f = cmd_tunnel_udp_config_parsed,
9175         .data = (void *)0,
9176         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9177                 "Add/Remove a tunneling UDP port filter",
9178         .tokens = {
9179                 (void *)&cmd_tunnel_udp_config_cmd,
9180                 (void *)&cmd_tunnel_udp_config_what,
9181                 (void *)&cmd_tunnel_udp_config_udp_port,
9182                 (void *)&cmd_tunnel_udp_config_port_id,
9183                 NULL,
9184         },
9185 };
9186
9187 struct cmd_config_tunnel_udp_port {
9188         cmdline_fixed_string_t port;
9189         cmdline_fixed_string_t config;
9190         portid_t port_id;
9191         cmdline_fixed_string_t udp_tunnel_port;
9192         cmdline_fixed_string_t action;
9193         cmdline_fixed_string_t tunnel_type;
9194         uint16_t udp_port;
9195 };
9196
9197 static void
9198 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9199                                __rte_unused struct cmdline *cl,
9200                                __rte_unused void *data)
9201 {
9202         struct cmd_config_tunnel_udp_port *res = parsed_result;
9203         struct rte_eth_udp_tunnel tunnel_udp;
9204         int ret = 0;
9205
9206         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9207                 return;
9208
9209         tunnel_udp.udp_port = res->udp_port;
9210
9211         if (!strcmp(res->tunnel_type, "vxlan")) {
9212                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9213         } else if (!strcmp(res->tunnel_type, "geneve")) {
9214                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9215         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9216                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9217         } else {
9218                 printf("Invalid tunnel type\n");
9219                 return;
9220         }
9221
9222         if (!strcmp(res->action, "add"))
9223                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9224                                                       &tunnel_udp);
9225         else
9226                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9227                                                          &tunnel_udp);
9228
9229         if (ret < 0)
9230                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9231 }
9232
9233 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9234         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9235                                  "port");
9236 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9237         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9238                                  "config");
9239 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9240         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9241                               UINT16);
9242 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9243         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9244                                  udp_tunnel_port,
9245                                  "udp_tunnel_port");
9246 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9247         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9248                                  "add#rm");
9249 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9250         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9251                                  "vxlan#geneve#vxlan-gpe");
9252 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9253         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9254                               UINT16);
9255
9256 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9257         .f = cmd_cfg_tunnel_udp_port_parsed,
9258         .data = NULL,
9259         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9260         .tokens = {
9261                 (void *)&cmd_config_tunnel_udp_port_port,
9262                 (void *)&cmd_config_tunnel_udp_port_config,
9263                 (void *)&cmd_config_tunnel_udp_port_port_id,
9264                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9265                 (void *)&cmd_config_tunnel_udp_port_action,
9266                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9267                 (void *)&cmd_config_tunnel_udp_port_value,
9268                 NULL,
9269         },
9270 };
9271
9272 /* *** GLOBAL CONFIG *** */
9273 struct cmd_global_config_result {
9274         cmdline_fixed_string_t cmd;
9275         portid_t port_id;
9276         cmdline_fixed_string_t cfg_type;
9277         uint8_t len;
9278 };
9279
9280 static void
9281 cmd_global_config_parsed(void *parsed_result,
9282                          __rte_unused struct cmdline *cl,
9283                          __rte_unused void *data)
9284 {
9285         struct cmd_global_config_result *res = parsed_result;
9286         struct rte_eth_global_cfg conf;
9287         int ret;
9288
9289         memset(&conf, 0, sizeof(conf));
9290         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9291         conf.cfg.gre_key_len = res->len;
9292         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9293                                       RTE_ETH_FILTER_SET, &conf);
9294 #ifdef RTE_LIBRTE_I40E_PMD
9295         if (ret == -ENOTSUP)
9296                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9297 #endif
9298         if (ret != 0)
9299                 printf("Global config error\n");
9300 }
9301
9302 cmdline_parse_token_string_t cmd_global_config_cmd =
9303         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9304                 "global_config");
9305 cmdline_parse_token_num_t cmd_global_config_port_id =
9306         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9307                                UINT16);
9308 cmdline_parse_token_string_t cmd_global_config_type =
9309         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9310                 cfg_type, "gre-key-len");
9311 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9312         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9313                 len, UINT8);
9314
9315 cmdline_parse_inst_t cmd_global_config = {
9316         .f = cmd_global_config_parsed,
9317         .data = (void *)NULL,
9318         .help_str = "global_config <port_id> gre-key-len <key_len>",
9319         .tokens = {
9320                 (void *)&cmd_global_config_cmd,
9321                 (void *)&cmd_global_config_port_id,
9322                 (void *)&cmd_global_config_type,
9323                 (void *)&cmd_global_config_gre_key_len,
9324                 NULL,
9325         },
9326 };
9327
9328 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9329 struct cmd_set_mirror_mask_result {
9330         cmdline_fixed_string_t set;
9331         cmdline_fixed_string_t port;
9332         portid_t port_id;
9333         cmdline_fixed_string_t mirror;
9334         uint8_t rule_id;
9335         cmdline_fixed_string_t what;
9336         cmdline_fixed_string_t value;
9337         cmdline_fixed_string_t dstpool;
9338         uint8_t dstpool_id;
9339         cmdline_fixed_string_t on;
9340 };
9341
9342 cmdline_parse_token_string_t cmd_mirror_mask_set =
9343         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9344                                 set, "set");
9345 cmdline_parse_token_string_t cmd_mirror_mask_port =
9346         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9347                                 port, "port");
9348 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9349         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9350                                 port_id, UINT16);
9351 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9352         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9353                                 mirror, "mirror-rule");
9354 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9355         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9356                                 rule_id, UINT8);
9357 cmdline_parse_token_string_t cmd_mirror_mask_what =
9358         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9359                                 what, "pool-mirror-up#pool-mirror-down"
9360                                       "#vlan-mirror");
9361 cmdline_parse_token_string_t cmd_mirror_mask_value =
9362         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9363                                 value, NULL);
9364 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9366                                 dstpool, "dst-pool");
9367 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9368         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9369                                 dstpool_id, UINT8);
9370 cmdline_parse_token_string_t cmd_mirror_mask_on =
9371         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9372                                 on, "on#off");
9373
9374 static void
9375 cmd_set_mirror_mask_parsed(void *parsed_result,
9376                        __rte_unused struct cmdline *cl,
9377                        __rte_unused void *data)
9378 {
9379         int ret,nb_item,i;
9380         struct cmd_set_mirror_mask_result *res = parsed_result;
9381         struct rte_eth_mirror_conf mr_conf;
9382
9383         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9384
9385         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9386
9387         mr_conf.dst_pool = res->dstpool_id;
9388
9389         if (!strcmp(res->what, "pool-mirror-up")) {
9390                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9391                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9392         } else if (!strcmp(res->what, "pool-mirror-down")) {
9393                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9394                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9395         } else if (!strcmp(res->what, "vlan-mirror")) {
9396                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9397                 nb_item = parse_item_list(res->value, "vlan",
9398                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9399                 if (nb_item <= 0)
9400                         return;
9401
9402                 for (i = 0; i < nb_item; i++) {
9403                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9404                                 printf("Invalid vlan_id: must be < 4096\n");
9405                                 return;
9406                         }
9407
9408                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9409                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9410                 }
9411         }
9412
9413         if (!strcmp(res->on, "on"))
9414                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9415                                                 res->rule_id, 1);
9416         else
9417                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9418                                                 res->rule_id, 0);
9419         if (ret < 0)
9420                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9421 }
9422
9423 cmdline_parse_inst_t cmd_set_mirror_mask = {
9424                 .f = cmd_set_mirror_mask_parsed,
9425                 .data = NULL,
9426                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9427                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9428                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9429                 .tokens = {
9430                         (void *)&cmd_mirror_mask_set,
9431                         (void *)&cmd_mirror_mask_port,
9432                         (void *)&cmd_mirror_mask_portid,
9433                         (void *)&cmd_mirror_mask_mirror,
9434                         (void *)&cmd_mirror_mask_ruleid,
9435                         (void *)&cmd_mirror_mask_what,
9436                         (void *)&cmd_mirror_mask_value,
9437                         (void *)&cmd_mirror_mask_dstpool,
9438                         (void *)&cmd_mirror_mask_poolid,
9439                         (void *)&cmd_mirror_mask_on,
9440                         NULL,
9441                 },
9442 };
9443
9444 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9445 struct cmd_set_mirror_link_result {
9446         cmdline_fixed_string_t set;
9447         cmdline_fixed_string_t port;
9448         portid_t port_id;
9449         cmdline_fixed_string_t mirror;
9450         uint8_t rule_id;
9451         cmdline_fixed_string_t what;
9452         cmdline_fixed_string_t dstpool;
9453         uint8_t dstpool_id;
9454         cmdline_fixed_string_t on;
9455 };
9456
9457 cmdline_parse_token_string_t cmd_mirror_link_set =
9458         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9459                                  set, "set");
9460 cmdline_parse_token_string_t cmd_mirror_link_port =
9461         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9462                                 port, "port");
9463 cmdline_parse_token_num_t cmd_mirror_link_portid =
9464         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9465                                 port_id, UINT16);
9466 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9467         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9468                                 mirror, "mirror-rule");
9469 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9470         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9471                             rule_id, UINT8);
9472 cmdline_parse_token_string_t cmd_mirror_link_what =
9473         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9474                                 what, "uplink-mirror#downlink-mirror");
9475 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9476         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9477                                 dstpool, "dst-pool");
9478 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9479         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9480                                 dstpool_id, UINT8);
9481 cmdline_parse_token_string_t cmd_mirror_link_on =
9482         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9483                                 on, "on#off");
9484
9485 static void
9486 cmd_set_mirror_link_parsed(void *parsed_result,
9487                        __rte_unused struct cmdline *cl,
9488                        __rte_unused void *data)
9489 {
9490         int ret;
9491         struct cmd_set_mirror_link_result *res = parsed_result;
9492         struct rte_eth_mirror_conf mr_conf;
9493
9494         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9495         if (!strcmp(res->what, "uplink-mirror"))
9496                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9497         else
9498                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9499
9500         mr_conf.dst_pool = res->dstpool_id;
9501
9502         if (!strcmp(res->on, "on"))
9503                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9504                                                 res->rule_id, 1);
9505         else
9506                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9507                                                 res->rule_id, 0);
9508
9509         /* check the return value and print it if is < 0 */
9510         if (ret < 0)
9511                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9512
9513 }
9514
9515 cmdline_parse_inst_t cmd_set_mirror_link = {
9516                 .f = cmd_set_mirror_link_parsed,
9517                 .data = NULL,
9518                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9519                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9520                 .tokens = {
9521                         (void *)&cmd_mirror_link_set,
9522                         (void *)&cmd_mirror_link_port,
9523                         (void *)&cmd_mirror_link_portid,
9524                         (void *)&cmd_mirror_link_mirror,
9525                         (void *)&cmd_mirror_link_ruleid,
9526                         (void *)&cmd_mirror_link_what,
9527                         (void *)&cmd_mirror_link_dstpool,
9528                         (void *)&cmd_mirror_link_poolid,
9529                         (void *)&cmd_mirror_link_on,
9530                         NULL,
9531                 },
9532 };
9533
9534 /* *** RESET VM MIRROR RULE *** */
9535 struct cmd_rm_mirror_rule_result {
9536         cmdline_fixed_string_t reset;
9537         cmdline_fixed_string_t port;
9538         portid_t port_id;
9539         cmdline_fixed_string_t mirror;
9540         uint8_t rule_id;
9541 };
9542
9543 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9544         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9545                                  reset, "reset");
9546 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9547         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9548                                 port, "port");
9549 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9550         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9551                                 port_id, UINT16);
9552 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9553         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9554                                 mirror, "mirror-rule");
9555 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9556         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9557                                 rule_id, UINT8);
9558
9559 static void
9560 cmd_reset_mirror_rule_parsed(void *parsed_result,
9561                        __rte_unused struct cmdline *cl,
9562                        __rte_unused void *data)
9563 {
9564         int ret;
9565         struct cmd_set_mirror_link_result *res = parsed_result;
9566         /* check rule_id */
9567         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9568         if(ret < 0)
9569                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9570 }
9571
9572 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9573                 .f = cmd_reset_mirror_rule_parsed,
9574                 .data = NULL,
9575                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9576                 .tokens = {
9577                         (void *)&cmd_rm_mirror_rule_reset,
9578                         (void *)&cmd_rm_mirror_rule_port,
9579                         (void *)&cmd_rm_mirror_rule_portid,
9580                         (void *)&cmd_rm_mirror_rule_mirror,
9581                         (void *)&cmd_rm_mirror_rule_ruleid,
9582                         NULL,
9583                 },
9584 };
9585
9586 /* ******************************************************************************** */
9587
9588 struct cmd_dump_result {
9589         cmdline_fixed_string_t dump;
9590 };
9591
9592 static void
9593 dump_struct_sizes(void)
9594 {
9595 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9596         DUMP_SIZE(struct rte_mbuf);
9597         DUMP_SIZE(struct rte_mempool);
9598         DUMP_SIZE(struct rte_ring);
9599 #undef DUMP_SIZE
9600 }
9601
9602
9603 /* Dump the socket memory statistics on console */
9604 static void
9605 dump_socket_mem(FILE *f)
9606 {
9607         struct rte_malloc_socket_stats socket_stats;
9608         unsigned int i;
9609         size_t total = 0;
9610         size_t alloc = 0;
9611         size_t free = 0;
9612         unsigned int n_alloc = 0;
9613         unsigned int n_free = 0;
9614         static size_t last_allocs;
9615         static size_t last_total;
9616
9617
9618         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9619                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9620                     !socket_stats.heap_totalsz_bytes)
9621                         continue;
9622                 total += socket_stats.heap_totalsz_bytes;
9623                 alloc += socket_stats.heap_allocsz_bytes;
9624                 free += socket_stats.heap_freesz_bytes;
9625                 n_alloc += socket_stats.alloc_count;
9626                 n_free += socket_stats.free_count;
9627                 fprintf(f,
9628                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9629                         i,
9630                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9631                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9632                         (double)socket_stats.heap_allocsz_bytes * 100 /
9633                         (double)socket_stats.heap_totalsz_bytes,
9634                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9635                         socket_stats.alloc_count,
9636                         socket_stats.free_count);
9637         }
9638         fprintf(f,
9639                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9640                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9641                 (double)alloc * 100 / (double)total,
9642                 (double)free / (1024 * 1024),
9643                 n_alloc, n_free);
9644         if (last_allocs)
9645                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9646                         ((double)total - (double)last_total) / (1024 * 1024),
9647                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9648         last_allocs = alloc;
9649         last_total = total;
9650 }
9651
9652 static void cmd_dump_parsed(void *parsed_result,
9653                             __rte_unused struct cmdline *cl,
9654                             __rte_unused void *data)
9655 {
9656         struct cmd_dump_result *res = parsed_result;
9657
9658         if (!strcmp(res->dump, "dump_physmem"))
9659                 rte_dump_physmem_layout(stdout);
9660         else if (!strcmp(res->dump, "dump_socket_mem"))
9661                 dump_socket_mem(stdout);
9662         else if (!strcmp(res->dump, "dump_memzone"))
9663                 rte_memzone_dump(stdout);
9664         else if (!strcmp(res->dump, "dump_struct_sizes"))
9665                 dump_struct_sizes();
9666         else if (!strcmp(res->dump, "dump_ring"))
9667                 rte_ring_list_dump(stdout);
9668         else if (!strcmp(res->dump, "dump_mempool"))
9669                 rte_mempool_list_dump(stdout);
9670         else if (!strcmp(res->dump, "dump_devargs"))
9671                 rte_devargs_dump(stdout);
9672         else if (!strcmp(res->dump, "dump_log_types"))
9673                 rte_log_dump(stdout);
9674 }
9675
9676 cmdline_parse_token_string_t cmd_dump_dump =
9677         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9678                 "dump_physmem#"
9679                 "dump_memzone#"
9680                 "dump_socket_mem#"
9681                 "dump_struct_sizes#"
9682                 "dump_ring#"
9683                 "dump_mempool#"
9684                 "dump_devargs#"
9685                 "dump_log_types");
9686
9687 cmdline_parse_inst_t cmd_dump = {
9688         .f = cmd_dump_parsed,  /* function to call */
9689         .data = NULL,      /* 2nd arg of func */
9690         .help_str = "Dump status",
9691         .tokens = {        /* token list, NULL terminated */
9692                 (void *)&cmd_dump_dump,
9693                 NULL,
9694         },
9695 };
9696
9697 /* ******************************************************************************** */
9698
9699 struct cmd_dump_one_result {
9700         cmdline_fixed_string_t dump;
9701         cmdline_fixed_string_t name;
9702 };
9703
9704 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9705                                 __rte_unused void *data)
9706 {
9707         struct cmd_dump_one_result *res = parsed_result;
9708
9709         if (!strcmp(res->dump, "dump_ring")) {
9710                 struct rte_ring *r;
9711                 r = rte_ring_lookup(res->name);
9712                 if (r == NULL) {
9713                         cmdline_printf(cl, "Cannot find ring\n");
9714                         return;
9715                 }
9716                 rte_ring_dump(stdout, r);
9717         } else if (!strcmp(res->dump, "dump_mempool")) {
9718                 struct rte_mempool *mp;
9719                 mp = rte_mempool_lookup(res->name);
9720                 if (mp == NULL) {
9721                         cmdline_printf(cl, "Cannot find mempool\n");
9722                         return;
9723                 }
9724                 rte_mempool_dump(stdout, mp);
9725         }
9726 }
9727
9728 cmdline_parse_token_string_t cmd_dump_one_dump =
9729         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9730                                  "dump_ring#dump_mempool");
9731
9732 cmdline_parse_token_string_t cmd_dump_one_name =
9733         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9734
9735 cmdline_parse_inst_t cmd_dump_one = {
9736         .f = cmd_dump_one_parsed,  /* function to call */
9737         .data = NULL,      /* 2nd arg of func */
9738         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9739         .tokens = {        /* token list, NULL terminated */
9740                 (void *)&cmd_dump_one_dump,
9741                 (void *)&cmd_dump_one_name,
9742                 NULL,
9743         },
9744 };
9745
9746 /* *** Add/Del syn filter *** */
9747 struct cmd_syn_filter_result {
9748         cmdline_fixed_string_t filter;
9749         portid_t port_id;
9750         cmdline_fixed_string_t ops;
9751         cmdline_fixed_string_t priority;
9752         cmdline_fixed_string_t high;
9753         cmdline_fixed_string_t queue;
9754         uint16_t queue_id;
9755 };
9756
9757 static void
9758 cmd_syn_filter_parsed(void *parsed_result,
9759                         __rte_unused struct cmdline *cl,
9760                         __rte_unused void *data)
9761 {
9762         struct cmd_syn_filter_result *res = parsed_result;
9763         struct rte_eth_syn_filter syn_filter;
9764         int ret = 0;
9765
9766         ret = rte_eth_dev_filter_supported(res->port_id,
9767                                         RTE_ETH_FILTER_SYN);
9768         if (ret < 0) {
9769                 printf("syn filter is not supported on port %u.\n",
9770                                 res->port_id);
9771                 return;
9772         }
9773
9774         memset(&syn_filter, 0, sizeof(syn_filter));
9775
9776         if (!strcmp(res->ops, "add")) {
9777                 if (!strcmp(res->high, "high"))
9778                         syn_filter.hig_pri = 1;
9779                 else
9780                         syn_filter.hig_pri = 0;
9781
9782                 syn_filter.queue = res->queue_id;
9783                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9784                                                 RTE_ETH_FILTER_SYN,
9785                                                 RTE_ETH_FILTER_ADD,
9786                                                 &syn_filter);
9787         } else
9788                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9789                                                 RTE_ETH_FILTER_SYN,
9790                                                 RTE_ETH_FILTER_DELETE,
9791                                                 &syn_filter);
9792
9793         if (ret < 0)
9794                 printf("syn filter programming error: (%s)\n",
9795                                 strerror(-ret));
9796 }
9797
9798 cmdline_parse_token_string_t cmd_syn_filter_filter =
9799         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9800         filter, "syn_filter");
9801 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9802         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9803         port_id, UINT16);
9804 cmdline_parse_token_string_t cmd_syn_filter_ops =
9805         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9806         ops, "add#del");
9807 cmdline_parse_token_string_t cmd_syn_filter_priority =
9808         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9809                                 priority, "priority");
9810 cmdline_parse_token_string_t cmd_syn_filter_high =
9811         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9812                                 high, "high#low");
9813 cmdline_parse_token_string_t cmd_syn_filter_queue =
9814         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9815                                 queue, "queue");
9816 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9817         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9818                                 queue_id, UINT16);
9819
9820 cmdline_parse_inst_t cmd_syn_filter = {
9821         .f = cmd_syn_filter_parsed,
9822         .data = NULL,
9823         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9824                 "<queue_id>: Add/Delete syn filter",
9825         .tokens = {
9826                 (void *)&cmd_syn_filter_filter,
9827                 (void *)&cmd_syn_filter_port_id,
9828                 (void *)&cmd_syn_filter_ops,
9829                 (void *)&cmd_syn_filter_priority,
9830                 (void *)&cmd_syn_filter_high,
9831                 (void *)&cmd_syn_filter_queue,
9832                 (void *)&cmd_syn_filter_queue_id,
9833                 NULL,
9834         },
9835 };
9836
9837 /* *** queue region set *** */
9838 struct cmd_queue_region_result {
9839         cmdline_fixed_string_t set;
9840         cmdline_fixed_string_t port;
9841         portid_t port_id;
9842         cmdline_fixed_string_t cmd;
9843         cmdline_fixed_string_t region;
9844         uint8_t  region_id;
9845         cmdline_fixed_string_t queue_start_index;
9846         uint8_t  queue_id;
9847         cmdline_fixed_string_t queue_num;
9848         uint8_t  queue_num_value;
9849 };
9850
9851 static void
9852 cmd_queue_region_parsed(void *parsed_result,
9853                         __rte_unused struct cmdline *cl,
9854                         __rte_unused void *data)
9855 {
9856         struct cmd_queue_region_result *res = parsed_result;
9857         int ret = -ENOTSUP;
9858 #ifdef RTE_LIBRTE_I40E_PMD
9859         struct rte_pmd_i40e_queue_region_conf region_conf;
9860         enum rte_pmd_i40e_queue_region_op op_type;
9861 #endif
9862
9863         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9864                 return;
9865
9866 #ifdef RTE_LIBRTE_I40E_PMD
9867         memset(&region_conf, 0, sizeof(region_conf));
9868         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9869         region_conf.region_id = res->region_id;
9870         region_conf.queue_num = res->queue_num_value;
9871         region_conf.queue_start_index = res->queue_id;
9872
9873         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9874                                 op_type, &region_conf);
9875 #endif
9876
9877         switch (ret) {
9878         case 0:
9879                 break;
9880         case -ENOTSUP:
9881                 printf("function not implemented or supported\n");
9882                 break;
9883         default:
9884                 printf("queue region config error: (%s)\n", strerror(-ret));
9885         }
9886 }
9887
9888 cmdline_parse_token_string_t cmd_queue_region_set =
9889 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9890                 set, "set");
9891 cmdline_parse_token_string_t cmd_queue_region_port =
9892         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9893 cmdline_parse_token_num_t cmd_queue_region_port_id =
9894         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9895                                 port_id, UINT16);
9896 cmdline_parse_token_string_t cmd_queue_region_cmd =
9897         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9898                                  cmd, "queue-region");
9899 cmdline_parse_token_string_t cmd_queue_region_id =
9900         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9901                                 region, "region_id");
9902 cmdline_parse_token_num_t cmd_queue_region_index =
9903         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9904                                 region_id, UINT8);
9905 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9906         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9907                                 queue_start_index, "queue_start_index");
9908 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9909         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9910                                 queue_id, UINT8);
9911 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9912         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9913                                 queue_num, "queue_num");
9914 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9915         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9916                                 queue_num_value, UINT8);
9917
9918 cmdline_parse_inst_t cmd_queue_region = {
9919         .f = cmd_queue_region_parsed,
9920         .data = NULL,
9921         .help_str = "set port <port_id> queue-region region_id <value> "
9922                 "queue_start_index <value> queue_num <value>: Set a queue region",
9923         .tokens = {
9924                 (void *)&cmd_queue_region_set,
9925                 (void *)&cmd_queue_region_port,
9926                 (void *)&cmd_queue_region_port_id,
9927                 (void *)&cmd_queue_region_cmd,
9928                 (void *)&cmd_queue_region_id,
9929                 (void *)&cmd_queue_region_index,
9930                 (void *)&cmd_queue_region_queue_start_index,
9931                 (void *)&cmd_queue_region_queue_id,
9932                 (void *)&cmd_queue_region_queue_num,
9933                 (void *)&cmd_queue_region_queue_num_value,
9934                 NULL,
9935         },
9936 };
9937
9938 /* *** queue region and flowtype set *** */
9939 struct cmd_region_flowtype_result {
9940         cmdline_fixed_string_t set;
9941         cmdline_fixed_string_t port;
9942         portid_t port_id;
9943         cmdline_fixed_string_t cmd;
9944         cmdline_fixed_string_t region;
9945         uint8_t  region_id;
9946         cmdline_fixed_string_t flowtype;
9947         uint8_t  flowtype_id;
9948 };
9949
9950 static void
9951 cmd_region_flowtype_parsed(void *parsed_result,
9952                         __rte_unused struct cmdline *cl,
9953                         __rte_unused void *data)
9954 {
9955         struct cmd_region_flowtype_result *res = parsed_result;
9956         int ret = -ENOTSUP;
9957 #ifdef RTE_LIBRTE_I40E_PMD
9958         struct rte_pmd_i40e_queue_region_conf region_conf;
9959         enum rte_pmd_i40e_queue_region_op op_type;
9960 #endif
9961
9962         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9963                 return;
9964
9965 #ifdef RTE_LIBRTE_I40E_PMD
9966         memset(&region_conf, 0, sizeof(region_conf));
9967
9968         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9969         region_conf.region_id = res->region_id;
9970         region_conf.hw_flowtype = res->flowtype_id;
9971
9972         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9973                         op_type, &region_conf);
9974 #endif
9975
9976         switch (ret) {
9977         case 0:
9978                 break;
9979         case -ENOTSUP:
9980                 printf("function not implemented or supported\n");
9981                 break;
9982         default:
9983                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9984         }
9985 }
9986
9987 cmdline_parse_token_string_t cmd_region_flowtype_set =
9988 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9989                                 set, "set");
9990 cmdline_parse_token_string_t cmd_region_flowtype_port =
9991         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9992                                 port, "port");
9993 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9994         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9995                                 port_id, UINT16);
9996 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9997         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9998                                 cmd, "queue-region");
9999 cmdline_parse_token_string_t cmd_region_flowtype_index =
10000         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10001                                 region, "region_id");
10002 cmdline_parse_token_num_t cmd_region_flowtype_id =
10003         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10004                                 region_id, UINT8);
10005 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10006         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10007                                 flowtype, "flowtype");
10008 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10009         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10010                                 flowtype_id, UINT8);
10011 cmdline_parse_inst_t cmd_region_flowtype = {
10012         .f = cmd_region_flowtype_parsed,
10013         .data = NULL,
10014         .help_str = "set port <port_id> queue-region region_id <value> "
10015                 "flowtype <value>: Set a flowtype region index",
10016         .tokens = {
10017                 (void *)&cmd_region_flowtype_set,
10018                 (void *)&cmd_region_flowtype_port,
10019                 (void *)&cmd_region_flowtype_port_index,
10020                 (void *)&cmd_region_flowtype_cmd,
10021                 (void *)&cmd_region_flowtype_index,
10022                 (void *)&cmd_region_flowtype_id,
10023                 (void *)&cmd_region_flowtype_flow_index,
10024                 (void *)&cmd_region_flowtype_flow_id,
10025                 NULL,
10026         },
10027 };
10028
10029 /* *** User Priority (UP) to queue region (region_id) set *** */
10030 struct cmd_user_priority_region_result {
10031         cmdline_fixed_string_t set;
10032         cmdline_fixed_string_t port;
10033         portid_t port_id;
10034         cmdline_fixed_string_t cmd;
10035         cmdline_fixed_string_t user_priority;
10036         uint8_t  user_priority_id;
10037         cmdline_fixed_string_t region;
10038         uint8_t  region_id;
10039 };
10040
10041 static void
10042 cmd_user_priority_region_parsed(void *parsed_result,
10043                         __rte_unused struct cmdline *cl,
10044                         __rte_unused void *data)
10045 {
10046         struct cmd_user_priority_region_result *res = parsed_result;
10047         int ret = -ENOTSUP;
10048 #ifdef RTE_LIBRTE_I40E_PMD
10049         struct rte_pmd_i40e_queue_region_conf region_conf;
10050         enum rte_pmd_i40e_queue_region_op op_type;
10051 #endif
10052
10053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10054                 return;
10055
10056 #ifdef RTE_LIBRTE_I40E_PMD
10057         memset(&region_conf, 0, sizeof(region_conf));
10058         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10059         region_conf.user_priority = res->user_priority_id;
10060         region_conf.region_id = res->region_id;
10061
10062         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10063                                 op_type, &region_conf);
10064 #endif
10065
10066         switch (ret) {
10067         case 0:
10068                 break;
10069         case -ENOTSUP:
10070                 printf("function not implemented or supported\n");
10071                 break;
10072         default:
10073                 printf("user_priority region config error: (%s)\n",
10074                                 strerror(-ret));
10075         }
10076 }
10077
10078 cmdline_parse_token_string_t cmd_user_priority_region_set =
10079         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10080                                 set, "set");
10081 cmdline_parse_token_string_t cmd_user_priority_region_port =
10082         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10083                                 port, "port");
10084 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10085         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10086                                 port_id, UINT16);
10087 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10088         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10089                                 cmd, "queue-region");
10090 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10091         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10092                                 user_priority, "UP");
10093 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10094         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10095                                 user_priority_id, UINT8);
10096 cmdline_parse_token_string_t cmd_user_priority_region_region =
10097         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10098                                 region, "region_id");
10099 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10100         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10101                                 region_id, UINT8);
10102
10103 cmdline_parse_inst_t cmd_user_priority_region = {
10104         .f = cmd_user_priority_region_parsed,
10105         .data = NULL,
10106         .help_str = "set port <port_id> queue-region UP <value> "
10107                 "region_id <value>: Set the mapping of User Priority (UP) "
10108                 "to queue region (region_id) ",
10109         .tokens = {
10110                 (void *)&cmd_user_priority_region_set,
10111                 (void *)&cmd_user_priority_region_port,
10112                 (void *)&cmd_user_priority_region_port_index,
10113                 (void *)&cmd_user_priority_region_cmd,
10114                 (void *)&cmd_user_priority_region_UP,
10115                 (void *)&cmd_user_priority_region_UP_id,
10116                 (void *)&cmd_user_priority_region_region,
10117                 (void *)&cmd_user_priority_region_region_id,
10118                 NULL,
10119         },
10120 };
10121
10122 /* *** flush all queue region related configuration *** */
10123 struct cmd_flush_queue_region_result {
10124         cmdline_fixed_string_t set;
10125         cmdline_fixed_string_t port;
10126         portid_t port_id;
10127         cmdline_fixed_string_t cmd;
10128         cmdline_fixed_string_t flush;
10129         cmdline_fixed_string_t what;
10130 };
10131
10132 static void
10133 cmd_flush_queue_region_parsed(void *parsed_result,
10134                         __rte_unused struct cmdline *cl,
10135                         __rte_unused void *data)
10136 {
10137         struct cmd_flush_queue_region_result *res = parsed_result;
10138         int ret = -ENOTSUP;
10139 #ifdef RTE_LIBRTE_I40E_PMD
10140         struct rte_pmd_i40e_queue_region_conf region_conf;
10141         enum rte_pmd_i40e_queue_region_op op_type;
10142 #endif
10143
10144         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10145                 return;
10146
10147 #ifdef RTE_LIBRTE_I40E_PMD
10148         memset(&region_conf, 0, sizeof(region_conf));
10149
10150         if (strcmp(res->what, "on") == 0)
10151                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10152         else
10153                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10154
10155         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10156                                 op_type, &region_conf);
10157 #endif
10158
10159         switch (ret) {
10160         case 0:
10161                 break;
10162         case -ENOTSUP:
10163                 printf("function not implemented or supported\n");
10164                 break;
10165         default:
10166                 printf("queue region config flush error: (%s)\n",
10167                                 strerror(-ret));
10168         }
10169 }
10170
10171 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10172         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10173                                 set, "set");
10174 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10175         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10176                                 port, "port");
10177 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10178         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10179                                 port_id, UINT16);
10180 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10181         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10182                                 cmd, "queue-region");
10183 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10184         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10185                                 flush, "flush");
10186 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10187         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10188                                 what, "on#off");
10189
10190 cmdline_parse_inst_t cmd_flush_queue_region = {
10191         .f = cmd_flush_queue_region_parsed,
10192         .data = NULL,
10193         .help_str = "set port <port_id> queue-region flush on|off"
10194                 ": flush all queue region related configuration",
10195         .tokens = {
10196                 (void *)&cmd_flush_queue_region_set,
10197                 (void *)&cmd_flush_queue_region_port,
10198                 (void *)&cmd_flush_queue_region_port_index,
10199                 (void *)&cmd_flush_queue_region_cmd,
10200                 (void *)&cmd_flush_queue_region_flush,
10201                 (void *)&cmd_flush_queue_region_what,
10202                 NULL,
10203         },
10204 };
10205
10206 /* *** get all queue region related configuration info *** */
10207 struct cmd_show_queue_region_info {
10208         cmdline_fixed_string_t show;
10209         cmdline_fixed_string_t port;
10210         portid_t port_id;
10211         cmdline_fixed_string_t cmd;
10212 };
10213
10214 static void
10215 cmd_show_queue_region_info_parsed(void *parsed_result,
10216                         __rte_unused struct cmdline *cl,
10217                         __rte_unused void *data)
10218 {
10219         struct cmd_show_queue_region_info *res = parsed_result;
10220         int ret = -ENOTSUP;
10221 #ifdef RTE_LIBRTE_I40E_PMD
10222         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10223         enum rte_pmd_i40e_queue_region_op op_type;
10224 #endif
10225
10226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10227                 return;
10228
10229 #ifdef RTE_LIBRTE_I40E_PMD
10230         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10231
10232         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10233
10234         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10235                                         op_type, &rte_pmd_regions);
10236
10237         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10238 #endif
10239
10240         switch (ret) {
10241         case 0:
10242                 break;
10243         case -ENOTSUP:
10244                 printf("function not implemented or supported\n");
10245                 break;
10246         default:
10247                 printf("queue region config info show error: (%s)\n",
10248                                 strerror(-ret));
10249         }
10250 }
10251
10252 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10253 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10254                                 show, "show");
10255 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10256         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10257                                 port, "port");
10258 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10259         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10260                                 port_id, UINT16);
10261 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10262         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10263                                 cmd, "queue-region");
10264
10265 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10266         .f = cmd_show_queue_region_info_parsed,
10267         .data = NULL,
10268         .help_str = "show port <port_id> queue-region"
10269                 ": show all queue region related configuration info",
10270         .tokens = {
10271                 (void *)&cmd_show_queue_region_info_get,
10272                 (void *)&cmd_show_queue_region_info_port,
10273                 (void *)&cmd_show_queue_region_info_port_index,
10274                 (void *)&cmd_show_queue_region_info_cmd,
10275                 NULL,
10276         },
10277 };
10278
10279 /* *** ADD/REMOVE A 2tuple FILTER *** */
10280 struct cmd_2tuple_filter_result {
10281         cmdline_fixed_string_t filter;
10282         portid_t port_id;
10283         cmdline_fixed_string_t ops;
10284         cmdline_fixed_string_t dst_port;
10285         uint16_t dst_port_value;
10286         cmdline_fixed_string_t protocol;
10287         uint8_t protocol_value;
10288         cmdline_fixed_string_t mask;
10289         uint8_t  mask_value;
10290         cmdline_fixed_string_t tcp_flags;
10291         uint8_t tcp_flags_value;
10292         cmdline_fixed_string_t priority;
10293         uint8_t  priority_value;
10294         cmdline_fixed_string_t queue;
10295         uint16_t  queue_id;
10296 };
10297
10298 static void
10299 cmd_2tuple_filter_parsed(void *parsed_result,
10300                         __rte_unused struct cmdline *cl,
10301                         __rte_unused void *data)
10302 {
10303         struct rte_eth_ntuple_filter filter;
10304         struct cmd_2tuple_filter_result *res = parsed_result;
10305         int ret = 0;
10306
10307         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10308         if (ret < 0) {
10309                 printf("ntuple filter is not supported on port %u.\n",
10310                         res->port_id);
10311                 return;
10312         }
10313
10314         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10315
10316         filter.flags = RTE_2TUPLE_FLAGS;
10317         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10318         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10319         filter.proto = res->protocol_value;
10320         filter.priority = res->priority_value;
10321         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10322                 printf("nonzero tcp_flags is only meaningful"
10323                         " when protocol is TCP.\n");
10324                 return;
10325         }
10326         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10327                 printf("invalid TCP flags.\n");
10328                 return;
10329         }
10330
10331         if (res->tcp_flags_value != 0) {
10332                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10333                 filter.tcp_flags = res->tcp_flags_value;
10334         }
10335
10336         /* need convert to big endian. */
10337         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10338         filter.queue = res->queue_id;
10339
10340         if (!strcmp(res->ops, "add"))
10341                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10342                                 RTE_ETH_FILTER_NTUPLE,
10343                                 RTE_ETH_FILTER_ADD,
10344                                 &filter);
10345         else
10346                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10347                                 RTE_ETH_FILTER_NTUPLE,
10348                                 RTE_ETH_FILTER_DELETE,
10349                                 &filter);
10350         if (ret < 0)
10351                 printf("2tuple filter programming error: (%s)\n",
10352                         strerror(-ret));
10353
10354 }
10355
10356 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10357         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10358                                  filter, "2tuple_filter");
10359 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10360         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10361                                 port_id, UINT16);
10362 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10363         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10364                                  ops, "add#del");
10365 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10366         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10367                                 dst_port, "dst_port");
10368 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10369         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10370                                 dst_port_value, UINT16);
10371 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10372         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10373                                 protocol, "protocol");
10374 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10375         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10376                                 protocol_value, UINT8);
10377 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10378         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10379                                 mask, "mask");
10380 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10381         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10382                                 mask_value, INT8);
10383 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10384         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10385                                 tcp_flags, "tcp_flags");
10386 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10387         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10388                                 tcp_flags_value, UINT8);
10389 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10390         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10391                                 priority, "priority");
10392 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10393         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10394                                 priority_value, UINT8);
10395 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10396         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10397                                 queue, "queue");
10398 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10399         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10400                                 queue_id, UINT16);
10401
10402 cmdline_parse_inst_t cmd_2tuple_filter = {
10403         .f = cmd_2tuple_filter_parsed,
10404         .data = NULL,
10405         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10406                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10407                 "<queue_id>: Add a 2tuple filter",
10408         .tokens = {
10409                 (void *)&cmd_2tuple_filter_filter,
10410                 (void *)&cmd_2tuple_filter_port_id,
10411                 (void *)&cmd_2tuple_filter_ops,
10412                 (void *)&cmd_2tuple_filter_dst_port,
10413                 (void *)&cmd_2tuple_filter_dst_port_value,
10414                 (void *)&cmd_2tuple_filter_protocol,
10415                 (void *)&cmd_2tuple_filter_protocol_value,
10416                 (void *)&cmd_2tuple_filter_mask,
10417                 (void *)&cmd_2tuple_filter_mask_value,
10418                 (void *)&cmd_2tuple_filter_tcp_flags,
10419                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10420                 (void *)&cmd_2tuple_filter_priority,
10421                 (void *)&cmd_2tuple_filter_priority_value,
10422                 (void *)&cmd_2tuple_filter_queue,
10423                 (void *)&cmd_2tuple_filter_queue_id,
10424                 NULL,
10425         },
10426 };
10427
10428 /* *** ADD/REMOVE A 5tuple FILTER *** */
10429 struct cmd_5tuple_filter_result {
10430         cmdline_fixed_string_t filter;
10431         portid_t port_id;
10432         cmdline_fixed_string_t ops;
10433         cmdline_fixed_string_t dst_ip;
10434         cmdline_ipaddr_t dst_ip_value;
10435         cmdline_fixed_string_t src_ip;
10436         cmdline_ipaddr_t src_ip_value;
10437         cmdline_fixed_string_t dst_port;
10438         uint16_t dst_port_value;
10439         cmdline_fixed_string_t src_port;
10440         uint16_t src_port_value;
10441         cmdline_fixed_string_t protocol;
10442         uint8_t protocol_value;
10443         cmdline_fixed_string_t mask;
10444         uint8_t  mask_value;
10445         cmdline_fixed_string_t tcp_flags;
10446         uint8_t tcp_flags_value;
10447         cmdline_fixed_string_t priority;
10448         uint8_t  priority_value;
10449         cmdline_fixed_string_t queue;
10450         uint16_t  queue_id;
10451 };
10452
10453 static void
10454 cmd_5tuple_filter_parsed(void *parsed_result,
10455                         __rte_unused struct cmdline *cl,
10456                         __rte_unused void *data)
10457 {
10458         struct rte_eth_ntuple_filter filter;
10459         struct cmd_5tuple_filter_result *res = parsed_result;
10460         int ret = 0;
10461
10462         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10463         if (ret < 0) {
10464                 printf("ntuple filter is not supported on port %u.\n",
10465                         res->port_id);
10466                 return;
10467         }
10468
10469         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10470
10471         filter.flags = RTE_5TUPLE_FLAGS;
10472         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10473         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10474         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10475         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10476         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10477         filter.proto = res->protocol_value;
10478         filter.priority = res->priority_value;
10479         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10480                 printf("nonzero tcp_flags is only meaningful"
10481                         " when protocol is TCP.\n");
10482                 return;
10483         }
10484         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10485                 printf("invalid TCP flags.\n");
10486                 return;
10487         }
10488
10489         if (res->tcp_flags_value != 0) {
10490                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10491                 filter.tcp_flags = res->tcp_flags_value;
10492         }
10493
10494         if (res->dst_ip_value.family == AF_INET)
10495                 /* no need to convert, already big endian. */
10496                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10497         else {
10498                 if (filter.dst_ip_mask == 0) {
10499                         printf("can not support ipv6 involved compare.\n");
10500                         return;
10501                 }
10502                 filter.dst_ip = 0;
10503         }
10504
10505         if (res->src_ip_value.family == AF_INET)
10506                 /* no need to convert, already big endian. */
10507                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10508         else {
10509                 if (filter.src_ip_mask == 0) {
10510                         printf("can not support ipv6 involved compare.\n");
10511                         return;
10512                 }
10513                 filter.src_ip = 0;
10514         }
10515         /* need convert to big endian. */
10516         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10517         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10518         filter.queue = res->queue_id;
10519
10520         if (!strcmp(res->ops, "add"))
10521                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10522                                 RTE_ETH_FILTER_NTUPLE,
10523                                 RTE_ETH_FILTER_ADD,
10524                                 &filter);
10525         else
10526                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10527                                 RTE_ETH_FILTER_NTUPLE,
10528                                 RTE_ETH_FILTER_DELETE,
10529                                 &filter);
10530         if (ret < 0)
10531                 printf("5tuple filter programming error: (%s)\n",
10532                         strerror(-ret));
10533 }
10534
10535 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10536         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10537                                  filter, "5tuple_filter");
10538 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10539         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10540                                 port_id, UINT16);
10541 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10542         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10543                                  ops, "add#del");
10544 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10545         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10546                                 dst_ip, "dst_ip");
10547 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10548         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10549                                 dst_ip_value);
10550 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10551         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10552                                 src_ip, "src_ip");
10553 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10554         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10555                                 src_ip_value);
10556 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10557         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10558                                 dst_port, "dst_port");
10559 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10560         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10561                                 dst_port_value, UINT16);
10562 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10563         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10564                                 src_port, "src_port");
10565 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10566         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10567                                 src_port_value, UINT16);
10568 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10569         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10570                                 protocol, "protocol");
10571 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10572         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10573                                 protocol_value, UINT8);
10574 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10575         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10576                                 mask, "mask");
10577 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10578         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10579                                 mask_value, INT8);
10580 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10581         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10582                                 tcp_flags, "tcp_flags");
10583 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10584         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10585                                 tcp_flags_value, UINT8);
10586 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10587         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10588                                 priority, "priority");
10589 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10590         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10591                                 priority_value, UINT8);
10592 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10593         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10594                                 queue, "queue");
10595 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10596         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10597                                 queue_id, UINT16);
10598
10599 cmdline_parse_inst_t cmd_5tuple_filter = {
10600         .f = cmd_5tuple_filter_parsed,
10601         .data = NULL,
10602         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10603                 "src_ip <value> dst_port <value> src_port <value> "
10604                 "protocol <value>  mask <value> tcp_flags <value> "
10605                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10606         .tokens = {
10607                 (void *)&cmd_5tuple_filter_filter,
10608                 (void *)&cmd_5tuple_filter_port_id,
10609                 (void *)&cmd_5tuple_filter_ops,
10610                 (void *)&cmd_5tuple_filter_dst_ip,
10611                 (void *)&cmd_5tuple_filter_dst_ip_value,
10612                 (void *)&cmd_5tuple_filter_src_ip,
10613                 (void *)&cmd_5tuple_filter_src_ip_value,
10614                 (void *)&cmd_5tuple_filter_dst_port,
10615                 (void *)&cmd_5tuple_filter_dst_port_value,
10616                 (void *)&cmd_5tuple_filter_src_port,
10617                 (void *)&cmd_5tuple_filter_src_port_value,
10618                 (void *)&cmd_5tuple_filter_protocol,
10619                 (void *)&cmd_5tuple_filter_protocol_value,
10620                 (void *)&cmd_5tuple_filter_mask,
10621                 (void *)&cmd_5tuple_filter_mask_value,
10622                 (void *)&cmd_5tuple_filter_tcp_flags,
10623                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10624                 (void *)&cmd_5tuple_filter_priority,
10625                 (void *)&cmd_5tuple_filter_priority_value,
10626                 (void *)&cmd_5tuple_filter_queue,
10627                 (void *)&cmd_5tuple_filter_queue_id,
10628                 NULL,
10629         },
10630 };
10631
10632 /* *** ADD/REMOVE A flex FILTER *** */
10633 struct cmd_flex_filter_result {
10634         cmdline_fixed_string_t filter;
10635         cmdline_fixed_string_t ops;
10636         portid_t port_id;
10637         cmdline_fixed_string_t len;
10638         uint8_t len_value;
10639         cmdline_fixed_string_t bytes;
10640         cmdline_fixed_string_t bytes_value;
10641         cmdline_fixed_string_t mask;
10642         cmdline_fixed_string_t mask_value;
10643         cmdline_fixed_string_t priority;
10644         uint8_t priority_value;
10645         cmdline_fixed_string_t queue;
10646         uint16_t queue_id;
10647 };
10648
10649 static int xdigit2val(unsigned char c)
10650 {
10651         int val;
10652         if (isdigit(c))
10653                 val = c - '0';
10654         else if (isupper(c))
10655                 val = c - 'A' + 10;
10656         else
10657                 val = c - 'a' + 10;
10658         return val;
10659 }
10660
10661 static void
10662 cmd_flex_filter_parsed(void *parsed_result,
10663                           __rte_unused struct cmdline *cl,
10664                           __rte_unused void *data)
10665 {
10666         int ret = 0;
10667         struct rte_eth_flex_filter filter;
10668         struct cmd_flex_filter_result *res = parsed_result;
10669         char *bytes_ptr, *mask_ptr;
10670         uint16_t len, i, j = 0;
10671         char c;
10672         int val;
10673         uint8_t byte = 0;
10674
10675         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10676                 printf("the len exceed the max length 128\n");
10677                 return;
10678         }
10679         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10680         filter.len = res->len_value;
10681         filter.priority = res->priority_value;
10682         filter.queue = res->queue_id;
10683         bytes_ptr = res->bytes_value;
10684         mask_ptr = res->mask_value;
10685
10686          /* translate bytes string to array. */
10687         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10688                 (bytes_ptr[1] == 'X')))
10689                 bytes_ptr += 2;
10690         len = strnlen(bytes_ptr, res->len_value * 2);
10691         if (len == 0 || (len % 8 != 0)) {
10692                 printf("please check len and bytes input\n");
10693                 return;
10694         }
10695         for (i = 0; i < len; i++) {
10696                 c = bytes_ptr[i];
10697                 if (isxdigit(c) == 0) {
10698                         /* invalid characters. */
10699                         printf("invalid input\n");
10700                         return;
10701                 }
10702                 val = xdigit2val(c);
10703                 if (i % 2) {
10704                         byte |= val;
10705                         filter.bytes[j] = byte;
10706                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10707                         j++;
10708                         byte = 0;
10709                 } else
10710                         byte |= val << 4;
10711         }
10712         printf("\n");
10713          /* translate mask string to uint8_t array. */
10714         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10715                 (mask_ptr[1] == 'X')))
10716                 mask_ptr += 2;
10717         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10718         if (len == 0) {
10719                 printf("invalid input\n");
10720                 return;
10721         }
10722         j = 0;
10723         byte = 0;
10724         for (i = 0; i < len; i++) {
10725                 c = mask_ptr[i];
10726                 if (isxdigit(c) == 0) {
10727                         /* invalid characters. */
10728                         printf("invalid input\n");
10729                         return;
10730                 }
10731                 val = xdigit2val(c);
10732                 if (i % 2) {
10733                         byte |= val;
10734                         filter.mask[j] = byte;
10735                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10736                         j++;
10737                         byte = 0;
10738                 } else
10739                         byte |= val << 4;
10740         }
10741         printf("\n");
10742
10743         if (!strcmp(res->ops, "add"))
10744                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10745                                 RTE_ETH_FILTER_FLEXIBLE,
10746                                 RTE_ETH_FILTER_ADD,
10747                                 &filter);
10748         else
10749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10750                                 RTE_ETH_FILTER_FLEXIBLE,
10751                                 RTE_ETH_FILTER_DELETE,
10752                                 &filter);
10753
10754         if (ret < 0)
10755                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10756 }
10757
10758 cmdline_parse_token_string_t cmd_flex_filter_filter =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10760                                 filter, "flex_filter");
10761 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10762         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10763                                 port_id, UINT16);
10764 cmdline_parse_token_string_t cmd_flex_filter_ops =
10765         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10766                                 ops, "add#del");
10767 cmdline_parse_token_string_t cmd_flex_filter_len =
10768         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10769                                 len, "len");
10770 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10771         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10772                                 len_value, UINT8);
10773 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10775                                 bytes, "bytes");
10776 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10778                                 bytes_value, NULL);
10779 cmdline_parse_token_string_t cmd_flex_filter_mask =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10781                                 mask, "mask");
10782 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10783         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10784                                 mask_value, NULL);
10785 cmdline_parse_token_string_t cmd_flex_filter_priority =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10787                                 priority, "priority");
10788 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10789         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10790                                 priority_value, UINT8);
10791 cmdline_parse_token_string_t cmd_flex_filter_queue =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10793                                 queue, "queue");
10794 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10795         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10796                                 queue_id, UINT16);
10797 cmdline_parse_inst_t cmd_flex_filter = {
10798         .f = cmd_flex_filter_parsed,
10799         .data = NULL,
10800         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10801                 "<value> mask <value> priority <value> queue <queue_id>: "
10802                 "Add/Del a flex filter",
10803         .tokens = {
10804                 (void *)&cmd_flex_filter_filter,
10805                 (void *)&cmd_flex_filter_port_id,
10806                 (void *)&cmd_flex_filter_ops,
10807                 (void *)&cmd_flex_filter_len,
10808                 (void *)&cmd_flex_filter_len_value,
10809                 (void *)&cmd_flex_filter_bytes,
10810                 (void *)&cmd_flex_filter_bytes_value,
10811                 (void *)&cmd_flex_filter_mask,
10812                 (void *)&cmd_flex_filter_mask_value,
10813                 (void *)&cmd_flex_filter_priority,
10814                 (void *)&cmd_flex_filter_priority_value,
10815                 (void *)&cmd_flex_filter_queue,
10816                 (void *)&cmd_flex_filter_queue_id,
10817                 NULL,
10818         },
10819 };
10820
10821 /* *** Filters Control *** */
10822
10823 /* *** deal with ethertype filter *** */
10824 struct cmd_ethertype_filter_result {
10825         cmdline_fixed_string_t filter;
10826         portid_t port_id;
10827         cmdline_fixed_string_t ops;
10828         cmdline_fixed_string_t mac;
10829         struct rte_ether_addr mac_addr;
10830         cmdline_fixed_string_t ethertype;
10831         uint16_t ethertype_value;
10832         cmdline_fixed_string_t drop;
10833         cmdline_fixed_string_t queue;
10834         uint16_t  queue_id;
10835 };
10836
10837 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10838         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10839                                  filter, "ethertype_filter");
10840 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10841         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10842                               port_id, UINT16);
10843 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10844         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10845                                  ops, "add#del");
10846 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10847         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10848                                  mac, "mac_addr#mac_ignr");
10849 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10850         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10851                                      mac_addr);
10852 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10853         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10854                                  ethertype, "ethertype");
10855 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10856         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10857                               ethertype_value, UINT16);
10858 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10859         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10860                                  drop, "drop#fwd");
10861 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10862         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10863                                  queue, "queue");
10864 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10865         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10866                               queue_id, UINT16);
10867
10868 static void
10869 cmd_ethertype_filter_parsed(void *parsed_result,
10870                           __rte_unused struct cmdline *cl,
10871                           __rte_unused void *data)
10872 {
10873         struct cmd_ethertype_filter_result *res = parsed_result;
10874         struct rte_eth_ethertype_filter filter;
10875         int ret = 0;
10876
10877         ret = rte_eth_dev_filter_supported(res->port_id,
10878                         RTE_ETH_FILTER_ETHERTYPE);
10879         if (ret < 0) {
10880                 printf("ethertype filter is not supported on port %u.\n",
10881                         res->port_id);
10882                 return;
10883         }
10884
10885         memset(&filter, 0, sizeof(filter));
10886         if (!strcmp(res->mac, "mac_addr")) {
10887                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10888                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10889                         sizeof(struct rte_ether_addr));
10890         }
10891         if (!strcmp(res->drop, "drop"))
10892                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10893         filter.ether_type = res->ethertype_value;
10894         filter.queue = res->queue_id;
10895
10896         if (!strcmp(res->ops, "add"))
10897                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10898                                 RTE_ETH_FILTER_ETHERTYPE,
10899                                 RTE_ETH_FILTER_ADD,
10900                                 &filter);
10901         else
10902                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10903                                 RTE_ETH_FILTER_ETHERTYPE,
10904                                 RTE_ETH_FILTER_DELETE,
10905                                 &filter);
10906         if (ret < 0)
10907                 printf("ethertype filter programming error: (%s)\n",
10908                         strerror(-ret));
10909 }
10910
10911 cmdline_parse_inst_t cmd_ethertype_filter = {
10912         .f = cmd_ethertype_filter_parsed,
10913         .data = NULL,
10914         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10915                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10916                 "Add or delete an ethertype filter entry",
10917         .tokens = {
10918                 (void *)&cmd_ethertype_filter_filter,
10919                 (void *)&cmd_ethertype_filter_port_id,
10920                 (void *)&cmd_ethertype_filter_ops,
10921                 (void *)&cmd_ethertype_filter_mac,
10922                 (void *)&cmd_ethertype_filter_mac_addr,
10923                 (void *)&cmd_ethertype_filter_ethertype,
10924                 (void *)&cmd_ethertype_filter_ethertype_value,
10925                 (void *)&cmd_ethertype_filter_drop,
10926                 (void *)&cmd_ethertype_filter_queue,
10927                 (void *)&cmd_ethertype_filter_queue_id,
10928                 NULL,
10929         },
10930 };
10931
10932 /* *** deal with flow director filter *** */
10933 struct cmd_flow_director_result {
10934         cmdline_fixed_string_t flow_director_filter;
10935         portid_t port_id;
10936         cmdline_fixed_string_t mode;
10937         cmdline_fixed_string_t mode_value;
10938         cmdline_fixed_string_t ops;
10939         cmdline_fixed_string_t flow;
10940         cmdline_fixed_string_t flow_type;
10941         cmdline_fixed_string_t ether;
10942         uint16_t ether_type;
10943         cmdline_fixed_string_t src;
10944         cmdline_ipaddr_t ip_src;
10945         uint16_t port_src;
10946         cmdline_fixed_string_t dst;
10947         cmdline_ipaddr_t ip_dst;
10948         uint16_t port_dst;
10949         cmdline_fixed_string_t verify_tag;
10950         uint32_t verify_tag_value;
10951         cmdline_fixed_string_t tos;
10952         uint8_t tos_value;
10953         cmdline_fixed_string_t proto;
10954         uint8_t proto_value;
10955         cmdline_fixed_string_t ttl;
10956         uint8_t ttl_value;
10957         cmdline_fixed_string_t vlan;
10958         uint16_t vlan_value;
10959         cmdline_fixed_string_t flexbytes;
10960         cmdline_fixed_string_t flexbytes_value;
10961         cmdline_fixed_string_t pf_vf;
10962         cmdline_fixed_string_t drop;
10963         cmdline_fixed_string_t queue;
10964         uint16_t  queue_id;
10965         cmdline_fixed_string_t fd_id;
10966         uint32_t  fd_id_value;
10967         cmdline_fixed_string_t mac;
10968         struct rte_ether_addr mac_addr;
10969         cmdline_fixed_string_t tunnel;
10970         cmdline_fixed_string_t tunnel_type;
10971         cmdline_fixed_string_t tunnel_id;
10972         uint32_t tunnel_id_value;
10973         cmdline_fixed_string_t packet;
10974         char filepath[];
10975 };
10976
10977 static inline int
10978 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10979 {
10980         char s[256];
10981         const char *p, *p0 = q_arg;
10982         char *end;
10983         unsigned long int_fld;
10984         char *str_fld[max_num];
10985         int i;
10986         unsigned size;
10987         int ret = -1;
10988
10989         p = strchr(p0, '(');
10990         if (p == NULL)
10991                 return -1;
10992         ++p;
10993         p0 = strchr(p, ')');
10994         if (p0 == NULL)
10995                 return -1;
10996
10997         size = p0 - p;
10998         if (size >= sizeof(s))
10999                 return -1;
11000
11001         snprintf(s, sizeof(s), "%.*s", size, p);
11002         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11003         if (ret < 0 || ret > max_num)
11004                 return -1;
11005         for (i = 0; i < ret; i++) {
11006                 errno = 0;
11007                 int_fld = strtoul(str_fld[i], &end, 0);
11008                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11009                         return -1;
11010                 flexbytes[i] = (uint8_t)int_fld;
11011         }
11012         return ret;
11013 }
11014
11015 static uint16_t
11016 str2flowtype(char *string)
11017 {
11018         uint8_t i = 0;
11019         static const struct {
11020                 char str[32];
11021                 uint16_t type;
11022         } flowtype_str[] = {
11023                 {"raw", RTE_ETH_FLOW_RAW},
11024                 {"ipv4", RTE_ETH_FLOW_IPV4},
11025                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11026                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11027                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11028                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11029                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11030                 {"ipv6", RTE_ETH_FLOW_IPV6},
11031                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11032                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11033                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11034                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11035                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11036                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11037         };
11038
11039         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11040                 if (!strcmp(flowtype_str[i].str, string))
11041                         return flowtype_str[i].type;
11042         }
11043
11044         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11045                 return (uint16_t)atoi(string);
11046
11047         return RTE_ETH_FLOW_UNKNOWN;
11048 }
11049
11050 static enum rte_eth_fdir_tunnel_type
11051 str2fdir_tunneltype(char *string)
11052 {
11053         uint8_t i = 0;
11054
11055         static const struct {
11056                 char str[32];
11057                 enum rte_eth_fdir_tunnel_type type;
11058         } tunneltype_str[] = {
11059                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11060                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11061         };
11062
11063         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11064                 if (!strcmp(tunneltype_str[i].str, string))
11065                         return tunneltype_str[i].type;
11066         }
11067         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11068 }
11069
11070 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11071 do { \
11072         if ((ip_addr).family == AF_INET) \
11073                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11074         else { \
11075                 printf("invalid parameter.\n"); \
11076                 return; \
11077         } \
11078 } while (0)
11079
11080 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11081 do { \
11082         if ((ip_addr).family == AF_INET6) \
11083                 rte_memcpy(&(ip), \
11084                                  &((ip_addr).addr.ipv6), \
11085                                  sizeof(struct in6_addr)); \
11086         else { \
11087                 printf("invalid parameter.\n"); \
11088                 return; \
11089         } \
11090 } while (0)
11091
11092 static void
11093 cmd_flow_director_filter_parsed(void *parsed_result,
11094                           __rte_unused struct cmdline *cl,
11095                           __rte_unused void *data)
11096 {
11097         struct cmd_flow_director_result *res = parsed_result;
11098         struct rte_eth_fdir_filter entry;
11099         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11100         char *end;
11101         unsigned long vf_id;
11102         int ret = 0;
11103
11104         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11105         if (ret < 0) {
11106                 printf("flow director is not supported on port %u.\n",
11107                         res->port_id);
11108                 return;
11109         }
11110         memset(flexbytes, 0, sizeof(flexbytes));
11111         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11112
11113         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11114                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11115                         printf("Please set mode to MAC-VLAN.\n");
11116                         return;
11117                 }
11118         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11119                 if (strcmp(res->mode_value, "Tunnel")) {
11120                         printf("Please set mode to Tunnel.\n");
11121                         return;
11122                 }
11123         } else {
11124                 if (!strcmp(res->mode_value, "raw")) {
11125 #ifdef RTE_LIBRTE_I40E_PMD
11126                         struct rte_pmd_i40e_flow_type_mapping
11127                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11128                         struct rte_pmd_i40e_pkt_template_conf conf;
11129                         uint16_t flow_type = str2flowtype(res->flow_type);
11130                         uint16_t i, port = res->port_id;
11131                         uint8_t add;
11132
11133                         memset(&conf, 0, sizeof(conf));
11134
11135                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11136                                 printf("Invalid flow type specified.\n");
11137                                 return;
11138                         }
11139                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11140                                                                  mapping);
11141                         if (ret)
11142                                 return;
11143                         if (mapping[flow_type].pctype == 0ULL) {
11144                                 printf("Invalid flow type specified.\n");
11145                                 return;
11146                         }
11147                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11148                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11149                                         conf.input.pctype = i;
11150                                         break;
11151                                 }
11152                         }
11153
11154                         conf.input.packet = open_file(res->filepath,
11155                                                 &conf.input.length);
11156                         if (!conf.input.packet)
11157                                 return;
11158                         if (!strcmp(res->drop, "drop"))
11159                                 conf.action.behavior =
11160                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11161                         else
11162                                 conf.action.behavior =
11163                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11164                         conf.action.report_status =
11165                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11166                         conf.action.rx_queue = res->queue_id;
11167                         conf.soft_id = res->fd_id_value;
11168                         add  = strcmp(res->ops, "del") ? 1 : 0;
11169                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11170                                                                         &conf,
11171                                                                         add);
11172                         if (ret < 0)
11173                                 printf("flow director config error: (%s)\n",
11174                                        strerror(-ret));
11175                         close_file(conf.input.packet);
11176 #endif
11177                         return;
11178                 } else if (strcmp(res->mode_value, "IP")) {
11179                         printf("Please set mode to IP or raw.\n");
11180                         return;
11181                 }
11182                 entry.input.flow_type = str2flowtype(res->flow_type);
11183         }
11184
11185         ret = parse_flexbytes(res->flexbytes_value,
11186                                         flexbytes,
11187                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11188         if (ret < 0) {
11189                 printf("error: Cannot parse flexbytes input.\n");
11190                 return;
11191         }
11192
11193         switch (entry.input.flow_type) {
11194         case RTE_ETH_FLOW_FRAG_IPV4:
11195         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11196                 entry.input.flow.ip4_flow.proto = res->proto_value;
11197                 /* fall-through */
11198         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11199         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11200                 IPV4_ADDR_TO_UINT(res->ip_dst,
11201                         entry.input.flow.ip4_flow.dst_ip);
11202                 IPV4_ADDR_TO_UINT(res->ip_src,
11203                         entry.input.flow.ip4_flow.src_ip);
11204                 entry.input.flow.ip4_flow.tos = res->tos_value;
11205                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11206                 /* need convert to big endian. */
11207                 entry.input.flow.udp4_flow.dst_port =
11208                                 rte_cpu_to_be_16(res->port_dst);
11209                 entry.input.flow.udp4_flow.src_port =
11210                                 rte_cpu_to_be_16(res->port_src);
11211                 break;
11212         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11213                 IPV4_ADDR_TO_UINT(res->ip_dst,
11214                         entry.input.flow.sctp4_flow.ip.dst_ip);
11215                 IPV4_ADDR_TO_UINT(res->ip_src,
11216                         entry.input.flow.sctp4_flow.ip.src_ip);
11217                 entry.input.flow.ip4_flow.tos = res->tos_value;
11218                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11219                 /* need convert to big endian. */
11220                 entry.input.flow.sctp4_flow.dst_port =
11221                                 rte_cpu_to_be_16(res->port_dst);
11222                 entry.input.flow.sctp4_flow.src_port =
11223                                 rte_cpu_to_be_16(res->port_src);
11224                 entry.input.flow.sctp4_flow.verify_tag =
11225                                 rte_cpu_to_be_32(res->verify_tag_value);
11226                 break;
11227         case RTE_ETH_FLOW_FRAG_IPV6:
11228         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11229                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11230                 /* fall-through */
11231         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11232         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11233                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11234                         entry.input.flow.ipv6_flow.dst_ip);
11235                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11236                         entry.input.flow.ipv6_flow.src_ip);
11237                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11238                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11239                 /* need convert to big endian. */
11240                 entry.input.flow.udp6_flow.dst_port =
11241                                 rte_cpu_to_be_16(res->port_dst);
11242                 entry.input.flow.udp6_flow.src_port =
11243                                 rte_cpu_to_be_16(res->port_src);
11244                 break;
11245         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11246                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11247                         entry.input.flow.sctp6_flow.ip.dst_ip);
11248                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11249                         entry.input.flow.sctp6_flow.ip.src_ip);
11250                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11251                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11252                 /* need convert to big endian. */
11253                 entry.input.flow.sctp6_flow.dst_port =
11254                                 rte_cpu_to_be_16(res->port_dst);
11255                 entry.input.flow.sctp6_flow.src_port =
11256                                 rte_cpu_to_be_16(res->port_src);
11257                 entry.input.flow.sctp6_flow.verify_tag =
11258                                 rte_cpu_to_be_32(res->verify_tag_value);
11259                 break;
11260         case RTE_ETH_FLOW_L2_PAYLOAD:
11261                 entry.input.flow.l2_flow.ether_type =
11262                         rte_cpu_to_be_16(res->ether_type);
11263                 break;
11264         default:
11265                 break;
11266         }
11267
11268         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11269                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11270                                  &res->mac_addr,
11271                                  sizeof(struct rte_ether_addr));
11272
11273         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11274                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11275                                  &res->mac_addr,
11276                                  sizeof(struct rte_ether_addr));
11277                 entry.input.flow.tunnel_flow.tunnel_type =
11278                         str2fdir_tunneltype(res->tunnel_type);
11279                 entry.input.flow.tunnel_flow.tunnel_id =
11280                         rte_cpu_to_be_32(res->tunnel_id_value);
11281         }
11282
11283         rte_memcpy(entry.input.flow_ext.flexbytes,
11284                    flexbytes,
11285                    RTE_ETH_FDIR_MAX_FLEXLEN);
11286
11287         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11288
11289         entry.action.flex_off = 0;  /*use 0 by default */
11290         if (!strcmp(res->drop, "drop"))
11291                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11292         else
11293                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11294
11295         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11296             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11297                 if (!strcmp(res->pf_vf, "pf"))
11298                         entry.input.flow_ext.is_vf = 0;
11299                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11300                         struct rte_eth_dev_info dev_info;
11301
11302                         ret = eth_dev_info_get_print_err(res->port_id,
11303                                                 &dev_info);
11304                         if (ret != 0)
11305                                 return;
11306
11307                         errno = 0;
11308                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11309                         if (errno != 0 || *end != '\0' ||
11310                             vf_id >= dev_info.max_vfs) {
11311                                 printf("invalid parameter %s.\n", res->pf_vf);
11312                                 return;
11313                         }
11314                         entry.input.flow_ext.is_vf = 1;
11315                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11316                 } else {
11317                         printf("invalid parameter %s.\n", res->pf_vf);
11318                         return;
11319                 }
11320         }
11321
11322         /* set to report FD ID by default */
11323         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11324         entry.action.rx_queue = res->queue_id;
11325         entry.soft_id = res->fd_id_value;
11326         if (!strcmp(res->ops, "add"))
11327                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11328                                              RTE_ETH_FILTER_ADD, &entry);
11329         else if (!strcmp(res->ops, "del"))
11330                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11331                                              RTE_ETH_FILTER_DELETE, &entry);
11332         else
11333                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11334                                              RTE_ETH_FILTER_UPDATE, &entry);
11335         if (ret < 0)
11336                 printf("flow director programming error: (%s)\n",
11337                         strerror(-ret));
11338 }
11339
11340 cmdline_parse_token_string_t cmd_flow_director_filter =
11341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11342                                  flow_director_filter, "flow_director_filter");
11343 cmdline_parse_token_num_t cmd_flow_director_port_id =
11344         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11345                               port_id, UINT16);
11346 cmdline_parse_token_string_t cmd_flow_director_ops =
11347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348                                  ops, "add#del#update");
11349 cmdline_parse_token_string_t cmd_flow_director_flow =
11350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11351                                  flow, "flow");
11352 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354                 flow_type, NULL);
11355 cmdline_parse_token_string_t cmd_flow_director_ether =
11356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11357                                  ether, "ether");
11358 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11359         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11360                               ether_type, UINT16);
11361 cmdline_parse_token_string_t cmd_flow_director_src =
11362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11363                                  src, "src");
11364 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11365         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11366                                  ip_src);
11367 cmdline_parse_token_num_t cmd_flow_director_port_src =
11368         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11369                               port_src, UINT16);
11370 cmdline_parse_token_string_t cmd_flow_director_dst =
11371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11372                                  dst, "dst");
11373 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11374         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11375                                  ip_dst);
11376 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11377         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11378                               port_dst, UINT16);
11379 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11381                                   verify_tag, "verify_tag");
11382 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11383         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11384                               verify_tag_value, UINT32);
11385 cmdline_parse_token_string_t cmd_flow_director_tos =
11386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11387                                  tos, "tos");
11388 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11389         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11390                               tos_value, UINT8);
11391 cmdline_parse_token_string_t cmd_flow_director_proto =
11392         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11393                                  proto, "proto");
11394 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11395         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11396                               proto_value, UINT8);
11397 cmdline_parse_token_string_t cmd_flow_director_ttl =
11398         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11399                                  ttl, "ttl");
11400 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11401         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11402                               ttl_value, UINT8);
11403 cmdline_parse_token_string_t cmd_flow_director_vlan =
11404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11405                                  vlan, "vlan");
11406 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11407         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11408                               vlan_value, UINT16);
11409 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11411                                  flexbytes, "flexbytes");
11412 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11414                               flexbytes_value, NULL);
11415 cmdline_parse_token_string_t cmd_flow_director_drop =
11416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11417                                  drop, "drop#fwd");
11418 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11419         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11420                               pf_vf, NULL);
11421 cmdline_parse_token_string_t cmd_flow_director_queue =
11422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11423                                  queue, "queue");
11424 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11425         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11426                               queue_id, UINT16);
11427 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11429                                  fd_id, "fd_id");
11430 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11431         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11432                               fd_id_value, UINT32);
11433
11434 cmdline_parse_token_string_t cmd_flow_director_mode =
11435         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11436                                  mode, "mode");
11437 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11439                                  mode_value, "IP");
11440 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11441         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11442                                  mode_value, "MAC-VLAN");
11443 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11444         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11445                                  mode_value, "Tunnel");
11446 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11448                                  mode_value, "raw");
11449 cmdline_parse_token_string_t cmd_flow_director_mac =
11450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11451                                  mac, "mac");
11452 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11453         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11454                                     mac_addr);
11455 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11456         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11457                                  tunnel, "tunnel");
11458 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11460                                  tunnel_type, "NVGRE#VxLAN");
11461 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11463                                  tunnel_id, "tunnel-id");
11464 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11465         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11466                               tunnel_id_value, UINT32);
11467 cmdline_parse_token_string_t cmd_flow_director_packet =
11468         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11469                                  packet, "packet");
11470 cmdline_parse_token_string_t cmd_flow_director_filepath =
11471         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11472                                  filepath, NULL);
11473
11474 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11475         .f = cmd_flow_director_filter_parsed,
11476         .data = NULL,
11477         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11478                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11479                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11480                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11481                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11482                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11483                 "fd_id <fd_id_value>: "
11484                 "Add or delete an ip flow director entry on NIC",
11485         .tokens = {
11486                 (void *)&cmd_flow_director_filter,
11487                 (void *)&cmd_flow_director_port_id,
11488                 (void *)&cmd_flow_director_mode,
11489                 (void *)&cmd_flow_director_mode_ip,
11490                 (void *)&cmd_flow_director_ops,
11491                 (void *)&cmd_flow_director_flow,
11492                 (void *)&cmd_flow_director_flow_type,
11493                 (void *)&cmd_flow_director_src,
11494                 (void *)&cmd_flow_director_ip_src,
11495                 (void *)&cmd_flow_director_dst,
11496                 (void *)&cmd_flow_director_ip_dst,
11497                 (void *)&cmd_flow_director_tos,
11498                 (void *)&cmd_flow_director_tos_value,
11499                 (void *)&cmd_flow_director_proto,
11500                 (void *)&cmd_flow_director_proto_value,
11501                 (void *)&cmd_flow_director_ttl,
11502                 (void *)&cmd_flow_director_ttl_value,
11503                 (void *)&cmd_flow_director_vlan,
11504                 (void *)&cmd_flow_director_vlan_value,
11505                 (void *)&cmd_flow_director_flexbytes,
11506                 (void *)&cmd_flow_director_flexbytes_value,
11507                 (void *)&cmd_flow_director_drop,
11508                 (void *)&cmd_flow_director_pf_vf,
11509                 (void *)&cmd_flow_director_queue,
11510                 (void *)&cmd_flow_director_queue_id,
11511                 (void *)&cmd_flow_director_fd_id,
11512                 (void *)&cmd_flow_director_fd_id_value,
11513                 NULL,
11514         },
11515 };
11516
11517 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11518         .f = cmd_flow_director_filter_parsed,
11519         .data = NULL,
11520         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11521                 "director entry on NIC",
11522         .tokens = {
11523                 (void *)&cmd_flow_director_filter,
11524                 (void *)&cmd_flow_director_port_id,
11525                 (void *)&cmd_flow_director_mode,
11526                 (void *)&cmd_flow_director_mode_ip,
11527                 (void *)&cmd_flow_director_ops,
11528                 (void *)&cmd_flow_director_flow,
11529                 (void *)&cmd_flow_director_flow_type,
11530                 (void *)&cmd_flow_director_src,
11531                 (void *)&cmd_flow_director_ip_src,
11532                 (void *)&cmd_flow_director_port_src,
11533                 (void *)&cmd_flow_director_dst,
11534                 (void *)&cmd_flow_director_ip_dst,
11535                 (void *)&cmd_flow_director_port_dst,
11536                 (void *)&cmd_flow_director_tos,
11537                 (void *)&cmd_flow_director_tos_value,
11538                 (void *)&cmd_flow_director_ttl,
11539                 (void *)&cmd_flow_director_ttl_value,
11540                 (void *)&cmd_flow_director_vlan,
11541                 (void *)&cmd_flow_director_vlan_value,
11542                 (void *)&cmd_flow_director_flexbytes,
11543                 (void *)&cmd_flow_director_flexbytes_value,
11544                 (void *)&cmd_flow_director_drop,
11545                 (void *)&cmd_flow_director_pf_vf,
11546                 (void *)&cmd_flow_director_queue,
11547                 (void *)&cmd_flow_director_queue_id,
11548                 (void *)&cmd_flow_director_fd_id,
11549                 (void *)&cmd_flow_director_fd_id_value,
11550                 NULL,
11551         },
11552 };
11553
11554 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11555         .f = cmd_flow_director_filter_parsed,
11556         .data = NULL,
11557         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11558                 "director entry on NIC",
11559         .tokens = {
11560                 (void *)&cmd_flow_director_filter,
11561                 (void *)&cmd_flow_director_port_id,
11562                 (void *)&cmd_flow_director_mode,
11563                 (void *)&cmd_flow_director_mode_ip,
11564                 (void *)&cmd_flow_director_ops,
11565                 (void *)&cmd_flow_director_flow,
11566                 (void *)&cmd_flow_director_flow_type,
11567                 (void *)&cmd_flow_director_src,
11568                 (void *)&cmd_flow_director_ip_src,
11569                 (void *)&cmd_flow_director_port_src,
11570                 (void *)&cmd_flow_director_dst,
11571                 (void *)&cmd_flow_director_ip_dst,
11572                 (void *)&cmd_flow_director_port_dst,
11573                 (void *)&cmd_flow_director_verify_tag,
11574                 (void *)&cmd_flow_director_verify_tag_value,
11575                 (void *)&cmd_flow_director_tos,
11576                 (void *)&cmd_flow_director_tos_value,
11577                 (void *)&cmd_flow_director_ttl,
11578                 (void *)&cmd_flow_director_ttl_value,
11579                 (void *)&cmd_flow_director_vlan,
11580                 (void *)&cmd_flow_director_vlan_value,
11581                 (void *)&cmd_flow_director_flexbytes,
11582                 (void *)&cmd_flow_director_flexbytes_value,
11583                 (void *)&cmd_flow_director_drop,
11584                 (void *)&cmd_flow_director_pf_vf,
11585                 (void *)&cmd_flow_director_queue,
11586                 (void *)&cmd_flow_director_queue_id,
11587                 (void *)&cmd_flow_director_fd_id,
11588                 (void *)&cmd_flow_director_fd_id_value,
11589                 NULL,
11590         },
11591 };
11592
11593 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11594         .f = cmd_flow_director_filter_parsed,
11595         .data = NULL,
11596         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11597                 "director entry on NIC",
11598         .tokens = {
11599                 (void *)&cmd_flow_director_filter,
11600                 (void *)&cmd_flow_director_port_id,
11601                 (void *)&cmd_flow_director_mode,
11602                 (void *)&cmd_flow_director_mode_ip,
11603                 (void *)&cmd_flow_director_ops,
11604                 (void *)&cmd_flow_director_flow,
11605                 (void *)&cmd_flow_director_flow_type,
11606                 (void *)&cmd_flow_director_ether,
11607                 (void *)&cmd_flow_director_ether_type,
11608                 (void *)&cmd_flow_director_flexbytes,
11609                 (void *)&cmd_flow_director_flexbytes_value,
11610                 (void *)&cmd_flow_director_drop,
11611                 (void *)&cmd_flow_director_pf_vf,
11612                 (void *)&cmd_flow_director_queue,
11613                 (void *)&cmd_flow_director_queue_id,
11614                 (void *)&cmd_flow_director_fd_id,
11615                 (void *)&cmd_flow_director_fd_id_value,
11616                 NULL,
11617         },
11618 };
11619
11620 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11621         .f = cmd_flow_director_filter_parsed,
11622         .data = NULL,
11623         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11624                 "director entry on NIC",
11625         .tokens = {
11626                 (void *)&cmd_flow_director_filter,
11627                 (void *)&cmd_flow_director_port_id,
11628                 (void *)&cmd_flow_director_mode,
11629                 (void *)&cmd_flow_director_mode_mac_vlan,
11630                 (void *)&cmd_flow_director_ops,
11631                 (void *)&cmd_flow_director_mac,
11632                 (void *)&cmd_flow_director_mac_addr,
11633                 (void *)&cmd_flow_director_vlan,
11634                 (void *)&cmd_flow_director_vlan_value,
11635                 (void *)&cmd_flow_director_flexbytes,
11636                 (void *)&cmd_flow_director_flexbytes_value,
11637                 (void *)&cmd_flow_director_drop,
11638                 (void *)&cmd_flow_director_queue,
11639                 (void *)&cmd_flow_director_queue_id,
11640                 (void *)&cmd_flow_director_fd_id,
11641                 (void *)&cmd_flow_director_fd_id_value,
11642                 NULL,
11643         },
11644 };
11645
11646 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11647         .f = cmd_flow_director_filter_parsed,
11648         .data = NULL,
11649         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11650                 "director entry on NIC",
11651         .tokens = {
11652                 (void *)&cmd_flow_director_filter,
11653                 (void *)&cmd_flow_director_port_id,
11654                 (void *)&cmd_flow_director_mode,
11655                 (void *)&cmd_flow_director_mode_tunnel,
11656                 (void *)&cmd_flow_director_ops,
11657                 (void *)&cmd_flow_director_mac,
11658                 (void *)&cmd_flow_director_mac_addr,
11659                 (void *)&cmd_flow_director_vlan,
11660                 (void *)&cmd_flow_director_vlan_value,
11661                 (void *)&cmd_flow_director_tunnel,
11662                 (void *)&cmd_flow_director_tunnel_type,
11663                 (void *)&cmd_flow_director_tunnel_id,
11664                 (void *)&cmd_flow_director_tunnel_id_value,
11665                 (void *)&cmd_flow_director_flexbytes,
11666                 (void *)&cmd_flow_director_flexbytes_value,
11667                 (void *)&cmd_flow_director_drop,
11668                 (void *)&cmd_flow_director_queue,
11669                 (void *)&cmd_flow_director_queue_id,
11670                 (void *)&cmd_flow_director_fd_id,
11671                 (void *)&cmd_flow_director_fd_id_value,
11672                 NULL,
11673         },
11674 };
11675
11676 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11677         .f = cmd_flow_director_filter_parsed,
11678         .data = NULL,
11679         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11680                 "director entry on NIC",
11681         .tokens = {
11682                 (void *)&cmd_flow_director_filter,
11683                 (void *)&cmd_flow_director_port_id,
11684                 (void *)&cmd_flow_director_mode,
11685                 (void *)&cmd_flow_director_mode_raw,
11686                 (void *)&cmd_flow_director_ops,
11687                 (void *)&cmd_flow_director_flow,
11688                 (void *)&cmd_flow_director_flow_type,
11689                 (void *)&cmd_flow_director_drop,
11690                 (void *)&cmd_flow_director_queue,
11691                 (void *)&cmd_flow_director_queue_id,
11692                 (void *)&cmd_flow_director_fd_id,
11693                 (void *)&cmd_flow_director_fd_id_value,
11694                 (void *)&cmd_flow_director_packet,
11695                 (void *)&cmd_flow_director_filepath,
11696                 NULL,
11697         },
11698 };
11699
11700 struct cmd_flush_flow_director_result {
11701         cmdline_fixed_string_t flush_flow_director;
11702         portid_t port_id;
11703 };
11704
11705 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11706         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11707                                  flush_flow_director, "flush_flow_director");
11708 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11709         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11710                               port_id, UINT16);
11711
11712 static void
11713 cmd_flush_flow_director_parsed(void *parsed_result,
11714                           __rte_unused struct cmdline *cl,
11715                           __rte_unused void *data)
11716 {
11717         struct cmd_flow_director_result *res = parsed_result;
11718         int ret = 0;
11719
11720         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11721         if (ret < 0) {
11722                 printf("flow director is not supported on port %u.\n",
11723                         res->port_id);
11724                 return;
11725         }
11726
11727         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11728                         RTE_ETH_FILTER_FLUSH, NULL);
11729         if (ret < 0)
11730                 printf("flow director table flushing error: (%s)\n",
11731                         strerror(-ret));
11732 }
11733
11734 cmdline_parse_inst_t cmd_flush_flow_director = {
11735         .f = cmd_flush_flow_director_parsed,
11736         .data = NULL,
11737         .help_str = "flush_flow_director <port_id>: "
11738                 "Flush all flow director entries of a device on NIC",
11739         .tokens = {
11740                 (void *)&cmd_flush_flow_director_flush,
11741                 (void *)&cmd_flush_flow_director_port_id,
11742                 NULL,
11743         },
11744 };
11745
11746 /* *** deal with flow director mask *** */
11747 struct cmd_flow_director_mask_result {
11748         cmdline_fixed_string_t flow_director_mask;
11749         portid_t port_id;
11750         cmdline_fixed_string_t mode;
11751         cmdline_fixed_string_t mode_value;
11752         cmdline_fixed_string_t vlan;
11753         uint16_t vlan_mask;
11754         cmdline_fixed_string_t src_mask;
11755         cmdline_ipaddr_t ipv4_src;
11756         cmdline_ipaddr_t ipv6_src;
11757         uint16_t port_src;
11758         cmdline_fixed_string_t dst_mask;
11759         cmdline_ipaddr_t ipv4_dst;
11760         cmdline_ipaddr_t ipv6_dst;
11761         uint16_t port_dst;
11762         cmdline_fixed_string_t mac;
11763         uint8_t mac_addr_byte_mask;
11764         cmdline_fixed_string_t tunnel_id;
11765         uint32_t tunnel_id_mask;
11766         cmdline_fixed_string_t tunnel_type;
11767         uint8_t tunnel_type_mask;
11768 };
11769
11770 static void
11771 cmd_flow_director_mask_parsed(void *parsed_result,
11772                           __rte_unused struct cmdline *cl,
11773                           __rte_unused void *data)
11774 {
11775         struct cmd_flow_director_mask_result *res = parsed_result;
11776         struct rte_eth_fdir_masks *mask;
11777         struct rte_port *port;
11778
11779         port = &ports[res->port_id];
11780         /** Check if the port is not started **/
11781         if (port->port_status != RTE_PORT_STOPPED) {
11782                 printf("Please stop port %d first\n", res->port_id);
11783                 return;
11784         }
11785
11786         mask = &port->dev_conf.fdir_conf.mask;
11787
11788         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11789                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11790                         printf("Please set mode to MAC-VLAN.\n");
11791                         return;
11792                 }
11793
11794                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11795         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11796                 if (strcmp(res->mode_value, "Tunnel")) {
11797                         printf("Please set mode to Tunnel.\n");
11798                         return;
11799                 }
11800
11801                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11802                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11803                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11804                 mask->tunnel_type_mask = res->tunnel_type_mask;
11805         } else {
11806                 if (strcmp(res->mode_value, "IP")) {
11807                         printf("Please set mode to IP.\n");
11808                         return;
11809                 }
11810
11811                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11812                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11813                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11814                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11815                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11816                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11817                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11818         }
11819
11820         cmd_reconfig_device_queue(res->port_id, 1, 1);
11821 }
11822
11823 cmdline_parse_token_string_t cmd_flow_director_mask =
11824         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11825                                  flow_director_mask, "flow_director_mask");
11826 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11827         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11828                               port_id, UINT16);
11829 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11831                                  vlan, "vlan");
11832 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11833         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11834                               vlan_mask, UINT16);
11835 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11836         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11837                                  src_mask, "src_mask");
11838 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11839         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11840                                  ipv4_src);
11841 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11842         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11843                                  ipv6_src);
11844 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11845         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11846                               port_src, UINT16);
11847 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11848         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11849                                  dst_mask, "dst_mask");
11850 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11851         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11852                                  ipv4_dst);
11853 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11854         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11855                                  ipv6_dst);
11856 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11857         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11858                               port_dst, UINT16);
11859
11860 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11862                                  mode, "mode");
11863 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11865                                  mode_value, "IP");
11866 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11868                                  mode_value, "MAC-VLAN");
11869 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11871                                  mode_value, "Tunnel");
11872 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11874                                  mac, "mac");
11875 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11876         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11877                               mac_addr_byte_mask, UINT8);
11878 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11880                                  tunnel_type, "tunnel-type");
11881 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11882         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11883                               tunnel_type_mask, UINT8);
11884 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11886                                  tunnel_id, "tunnel-id");
11887 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11888         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11889                               tunnel_id_mask, UINT32);
11890
11891 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11892         .f = cmd_flow_director_mask_parsed,
11893         .data = NULL,
11894         .help_str = "flow_director_mask ... : "
11895                 "Set IP mode flow director's mask on NIC",
11896         .tokens = {
11897                 (void *)&cmd_flow_director_mask,
11898                 (void *)&cmd_flow_director_mask_port_id,
11899                 (void *)&cmd_flow_director_mask_mode,
11900                 (void *)&cmd_flow_director_mask_mode_ip,
11901                 (void *)&cmd_flow_director_mask_vlan,
11902                 (void *)&cmd_flow_director_mask_vlan_value,
11903                 (void *)&cmd_flow_director_mask_src,
11904                 (void *)&cmd_flow_director_mask_ipv4_src,
11905                 (void *)&cmd_flow_director_mask_ipv6_src,
11906                 (void *)&cmd_flow_director_mask_port_src,
11907                 (void *)&cmd_flow_director_mask_dst,
11908                 (void *)&cmd_flow_director_mask_ipv4_dst,
11909                 (void *)&cmd_flow_director_mask_ipv6_dst,
11910                 (void *)&cmd_flow_director_mask_port_dst,
11911                 NULL,
11912         },
11913 };
11914
11915 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11916         .f = cmd_flow_director_mask_parsed,
11917         .data = NULL,
11918         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11919                 "flow director's mask on NIC",
11920         .tokens = {
11921                 (void *)&cmd_flow_director_mask,
11922                 (void *)&cmd_flow_director_mask_port_id,
11923                 (void *)&cmd_flow_director_mask_mode,
11924                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11925                 (void *)&cmd_flow_director_mask_vlan,
11926                 (void *)&cmd_flow_director_mask_vlan_value,
11927                 NULL,
11928         },
11929 };
11930
11931 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11932         .f = cmd_flow_director_mask_parsed,
11933         .data = NULL,
11934         .help_str = "flow_director_mask ... : Set tunnel mode "
11935                 "flow director's mask on NIC",
11936         .tokens = {
11937                 (void *)&cmd_flow_director_mask,
11938                 (void *)&cmd_flow_director_mask_port_id,
11939                 (void *)&cmd_flow_director_mask_mode,
11940                 (void *)&cmd_flow_director_mask_mode_tunnel,
11941                 (void *)&cmd_flow_director_mask_vlan,
11942                 (void *)&cmd_flow_director_mask_vlan_value,
11943                 (void *)&cmd_flow_director_mask_mac,
11944                 (void *)&cmd_flow_director_mask_mac_value,
11945                 (void *)&cmd_flow_director_mask_tunnel_type,
11946                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11947                 (void *)&cmd_flow_director_mask_tunnel_id,
11948                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11949                 NULL,
11950         },
11951 };
11952
11953 /* *** deal with flow director mask on flexible payload *** */
11954 struct cmd_flow_director_flex_mask_result {
11955         cmdline_fixed_string_t flow_director_flexmask;
11956         portid_t port_id;
11957         cmdline_fixed_string_t flow;
11958         cmdline_fixed_string_t flow_type;
11959         cmdline_fixed_string_t mask;
11960 };
11961
11962 static void
11963 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11964                           __rte_unused struct cmdline *cl,
11965                           __rte_unused void *data)
11966 {
11967         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11968         struct rte_eth_fdir_info fdir_info;
11969         struct rte_eth_fdir_flex_mask flex_mask;
11970         struct rte_port *port;
11971         uint64_t flow_type_mask;
11972         uint16_t i;
11973         int ret;
11974
11975         port = &ports[res->port_id];
11976         /** Check if the port is not started **/
11977         if (port->port_status != RTE_PORT_STOPPED) {
11978                 printf("Please stop port %d first\n", res->port_id);
11979                 return;
11980         }
11981
11982         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11983         ret = parse_flexbytes(res->mask,
11984                         flex_mask.mask,
11985                         RTE_ETH_FDIR_MAX_FLEXLEN);
11986         if (ret < 0) {
11987                 printf("error: Cannot parse mask input.\n");
11988                 return;
11989         }
11990
11991         memset(&fdir_info, 0, sizeof(fdir_info));
11992         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11993                                 RTE_ETH_FILTER_INFO, &fdir_info);
11994         if (ret < 0) {
11995                 printf("Cannot get FDir filter info\n");
11996                 return;
11997         }
11998
11999         if (!strcmp(res->flow_type, "none")) {
12000                 /* means don't specify the flow type */
12001                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12002                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12003                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12004                                0, sizeof(struct rte_eth_fdir_flex_mask));
12005                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12006                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12007                                  &flex_mask,
12008                                  sizeof(struct rte_eth_fdir_flex_mask));
12009                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12010                 return;
12011         }
12012         flow_type_mask = fdir_info.flow_types_mask[0];
12013         if (!strcmp(res->flow_type, "all")) {
12014                 if (!flow_type_mask) {
12015                         printf("No flow type supported\n");
12016                         return;
12017                 }
12018                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12019                         if (flow_type_mask & (1ULL << i)) {
12020                                 flex_mask.flow_type = i;
12021                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12022                         }
12023                 }
12024                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12025                 return;
12026         }
12027         flex_mask.flow_type = str2flowtype(res->flow_type);
12028         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12029                 printf("Flow type %s not supported on port %d\n",
12030                                 res->flow_type, res->port_id);
12031                 return;
12032         }
12033         fdir_set_flex_mask(res->port_id, &flex_mask);
12034         cmd_reconfig_device_queue(res->port_id, 1, 1);
12035 }
12036
12037 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12038         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12039                                  flow_director_flexmask,
12040                                  "flow_director_flex_mask");
12041 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12042         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12043                               port_id, UINT16);
12044 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12046                                  flow, "flow");
12047 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12048         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12049                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12050                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12051 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12052         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12053                                  mask, NULL);
12054
12055 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12056         .f = cmd_flow_director_flex_mask_parsed,
12057         .data = NULL,
12058         .help_str = "flow_director_flex_mask ... : "
12059                 "Set flow director's flex mask on NIC",
12060         .tokens = {
12061                 (void *)&cmd_flow_director_flexmask,
12062                 (void *)&cmd_flow_director_flexmask_port_id,
12063                 (void *)&cmd_flow_director_flexmask_flow,
12064                 (void *)&cmd_flow_director_flexmask_flow_type,
12065                 (void *)&cmd_flow_director_flexmask_mask,
12066                 NULL,
12067         },
12068 };
12069
12070 /* *** deal with flow director flexible payload configuration *** */
12071 struct cmd_flow_director_flexpayload_result {
12072         cmdline_fixed_string_t flow_director_flexpayload;
12073         portid_t port_id;
12074         cmdline_fixed_string_t payload_layer;
12075         cmdline_fixed_string_t payload_cfg;
12076 };
12077
12078 static inline int
12079 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12080 {
12081         char s[256];
12082         const char *p, *p0 = q_arg;
12083         char *end;
12084         unsigned long int_fld;
12085         char *str_fld[max_num];
12086         int i;
12087         unsigned size;
12088         int ret = -1;
12089
12090         p = strchr(p0, '(');
12091         if (p == NULL)
12092                 return -1;
12093         ++p;
12094         p0 = strchr(p, ')');
12095         if (p0 == NULL)
12096                 return -1;
12097
12098         size = p0 - p;
12099         if (size >= sizeof(s))
12100                 return -1;
12101
12102         snprintf(s, sizeof(s), "%.*s", size, p);
12103         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12104         if (ret < 0 || ret > max_num)
12105                 return -1;
12106         for (i = 0; i < ret; i++) {
12107                 errno = 0;
12108                 int_fld = strtoul(str_fld[i], &end, 0);
12109                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12110                         return -1;
12111                 offsets[i] = (uint16_t)int_fld;
12112         }
12113         return ret;
12114 }
12115
12116 static void
12117 cmd_flow_director_flxpld_parsed(void *parsed_result,
12118                           __rte_unused struct cmdline *cl,
12119                           __rte_unused void *data)
12120 {
12121         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12122         struct rte_eth_flex_payload_cfg flex_cfg;
12123         struct rte_port *port;
12124         int ret = 0;
12125
12126         port = &ports[res->port_id];
12127         /** Check if the port is not started **/
12128         if (port->port_status != RTE_PORT_STOPPED) {
12129                 printf("Please stop port %d first\n", res->port_id);
12130                 return;
12131         }
12132
12133         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12134
12135         if (!strcmp(res->payload_layer, "raw"))
12136                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12137         else if (!strcmp(res->payload_layer, "l2"))
12138                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12139         else if (!strcmp(res->payload_layer, "l3"))
12140                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12141         else if (!strcmp(res->payload_layer, "l4"))
12142                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12143
12144         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12145                             RTE_ETH_FDIR_MAX_FLEXLEN);
12146         if (ret < 0) {
12147                 printf("error: Cannot parse flex payload input.\n");
12148                 return;
12149         }
12150
12151         fdir_set_flex_payload(res->port_id, &flex_cfg);
12152         cmd_reconfig_device_queue(res->port_id, 1, 1);
12153 }
12154
12155 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12156         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12157                                  flow_director_flexpayload,
12158                                  "flow_director_flex_payload");
12159 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12160         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12161                               port_id, UINT16);
12162 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12164                                  payload_layer, "raw#l2#l3#l4");
12165 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12166         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12167                                  payload_cfg, NULL);
12168
12169 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12170         .f = cmd_flow_director_flxpld_parsed,
12171         .data = NULL,
12172         .help_str = "flow_director_flexpayload ... : "
12173                 "Set flow director's flex payload on NIC",
12174         .tokens = {
12175                 (void *)&cmd_flow_director_flexpayload,
12176                 (void *)&cmd_flow_director_flexpayload_port_id,
12177                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12178                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12179                 NULL,
12180         },
12181 };
12182
12183 /* Generic flow interface command. */
12184 extern cmdline_parse_inst_t cmd_flow;
12185
12186 /* *** Classification Filters Control *** */
12187 /* *** Get symmetric hash enable per port *** */
12188 struct cmd_get_sym_hash_ena_per_port_result {
12189         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12190         portid_t port_id;
12191 };
12192
12193 static void
12194 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12195                                  __rte_unused struct cmdline *cl,
12196                                  __rte_unused void *data)
12197 {
12198         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12199         struct rte_eth_hash_filter_info info;
12200         int ret;
12201
12202         if (rte_eth_dev_filter_supported(res->port_id,
12203                                 RTE_ETH_FILTER_HASH) < 0) {
12204                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12205                                                         res->port_id);
12206                 return;
12207         }
12208
12209         memset(&info, 0, sizeof(info));
12210         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12211         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12212                                                 RTE_ETH_FILTER_GET, &info);
12213
12214         if (ret < 0) {
12215                 printf("Cannot get symmetric hash enable per port "
12216                                         "on port %u\n", res->port_id);
12217                 return;
12218         }
12219
12220         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12221                                 "enabled" : "disabled", res->port_id);
12222 }
12223
12224 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12225         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12226                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12227 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12228         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12229                 port_id, UINT16);
12230
12231 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12232         .f = cmd_get_sym_hash_per_port_parsed,
12233         .data = NULL,
12234         .help_str = "get_sym_hash_ena_per_port <port_id>",
12235         .tokens = {
12236                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12237                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12238                 NULL,
12239         },
12240 };
12241
12242 /* *** Set symmetric hash enable per port *** */
12243 struct cmd_set_sym_hash_ena_per_port_result {
12244         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12245         cmdline_fixed_string_t enable;
12246         portid_t port_id;
12247 };
12248
12249 static void
12250 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12251                                  __rte_unused struct cmdline *cl,
12252                                  __rte_unused void *data)
12253 {
12254         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12255         struct rte_eth_hash_filter_info info;
12256         int ret;
12257
12258         if (rte_eth_dev_filter_supported(res->port_id,
12259                                 RTE_ETH_FILTER_HASH) < 0) {
12260                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12261                                                         res->port_id);
12262                 return;
12263         }
12264
12265         memset(&info, 0, sizeof(info));
12266         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12267         if (!strcmp(res->enable, "enable"))
12268                 info.info.enable = 1;
12269         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12270                                         RTE_ETH_FILTER_SET, &info);
12271         if (ret < 0) {
12272                 printf("Cannot set symmetric hash enable per port on "
12273                                         "port %u\n", res->port_id);
12274                 return;
12275         }
12276         printf("Symmetric hash has been set to %s on port %u\n",
12277                                         res->enable, res->port_id);
12278 }
12279
12280 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12281         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12282                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12283 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12284         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12285                 port_id, UINT16);
12286 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12287         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12288                 enable, "enable#disable");
12289
12290 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12291         .f = cmd_set_sym_hash_per_port_parsed,
12292         .data = NULL,
12293         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12294         .tokens = {
12295                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12296                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12297                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12298                 NULL,
12299         },
12300 };
12301
12302 /* Get global config of hash function */
12303 struct cmd_get_hash_global_config_result {
12304         cmdline_fixed_string_t get_hash_global_config;
12305         portid_t port_id;
12306 };
12307
12308 static char *
12309 flowtype_to_str(uint16_t ftype)
12310 {
12311         uint16_t i;
12312         static struct {
12313                 char str[16];
12314                 uint16_t ftype;
12315         } ftype_table[] = {
12316                 {"ipv4", RTE_ETH_FLOW_IPV4},
12317                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12318                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12319                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12320                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12321                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12322                 {"ipv6", RTE_ETH_FLOW_IPV6},
12323                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12324                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12325                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12326                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12327                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12328                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12329                 {"port", RTE_ETH_FLOW_PORT},
12330                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12331                 {"geneve", RTE_ETH_FLOW_GENEVE},
12332                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12333                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12334         };
12335
12336         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12337                 if (ftype_table[i].ftype == ftype)
12338                         return ftype_table[i].str;
12339         }
12340
12341         return NULL;
12342 }
12343
12344 static void
12345 cmd_get_hash_global_config_parsed(void *parsed_result,
12346                                   __rte_unused struct cmdline *cl,
12347                                   __rte_unused void *data)
12348 {
12349         struct cmd_get_hash_global_config_result *res = parsed_result;
12350         struct rte_eth_hash_filter_info info;
12351         uint32_t idx, offset;
12352         uint16_t i;
12353         char *str;
12354         int ret;
12355
12356         if (rte_eth_dev_filter_supported(res->port_id,
12357                         RTE_ETH_FILTER_HASH) < 0) {
12358                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12359                                                         res->port_id);
12360                 return;
12361         }
12362
12363         memset(&info, 0, sizeof(info));
12364         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12365         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12366                                         RTE_ETH_FILTER_GET, &info);
12367         if (ret < 0) {
12368                 printf("Cannot get hash global configurations by port %d\n",
12369                                                         res->port_id);
12370                 return;
12371         }
12372
12373         switch (info.info.global_conf.hash_func) {
12374         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12375                 printf("Hash function is Toeplitz\n");
12376                 break;
12377         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12378                 printf("Hash function is Simple XOR\n");
12379                 break;
12380         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12381                 printf("Hash function is Symmetric Toeplitz\n");
12382                 break;
12383         default:
12384                 printf("Unknown hash function\n");
12385                 break;
12386         }
12387
12388         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12389                 idx = i / UINT64_BIT;
12390                 offset = i % UINT64_BIT;
12391                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12392                                                 (1ULL << offset)))
12393                         continue;
12394                 str = flowtype_to_str(i);
12395                 if (!str)
12396                         continue;
12397                 printf("Symmetric hash is %s globally for flow type %s "
12398                                                         "by port %d\n",
12399                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12400                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12401                                                         res->port_id);
12402         }
12403 }
12404
12405 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12406         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12407                 get_hash_global_config, "get_hash_global_config");
12408 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12409         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12410                 port_id, UINT16);
12411
12412 cmdline_parse_inst_t cmd_get_hash_global_config = {
12413         .f = cmd_get_hash_global_config_parsed,
12414         .data = NULL,
12415         .help_str = "get_hash_global_config <port_id>",
12416         .tokens = {
12417                 (void *)&cmd_get_hash_global_config_all,
12418                 (void *)&cmd_get_hash_global_config_port_id,
12419                 NULL,
12420         },
12421 };
12422
12423 /* Set global config of hash function */
12424 struct cmd_set_hash_global_config_result {
12425         cmdline_fixed_string_t set_hash_global_config;
12426         portid_t port_id;
12427         cmdline_fixed_string_t hash_func;
12428         cmdline_fixed_string_t flow_type;
12429         cmdline_fixed_string_t enable;
12430 };
12431
12432 static void
12433 cmd_set_hash_global_config_parsed(void *parsed_result,
12434                                   __rte_unused struct cmdline *cl,
12435                                   __rte_unused void *data)
12436 {
12437         struct cmd_set_hash_global_config_result *res = parsed_result;
12438         struct rte_eth_hash_filter_info info;
12439         uint32_t ftype, idx, offset;
12440         int ret;
12441
12442         if (rte_eth_dev_filter_supported(res->port_id,
12443                                 RTE_ETH_FILTER_HASH) < 0) {
12444                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12445                                                         res->port_id);
12446                 return;
12447         }
12448         memset(&info, 0, sizeof(info));
12449         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12450         if (!strcmp(res->hash_func, "toeplitz"))
12451                 info.info.global_conf.hash_func =
12452                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12453         else if (!strcmp(res->hash_func, "simple_xor"))
12454                 info.info.global_conf.hash_func =
12455                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12456         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12457                 info.info.global_conf.hash_func =
12458                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12459         else if (!strcmp(res->hash_func, "default"))
12460                 info.info.global_conf.hash_func =
12461                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12462
12463         ftype = str2flowtype(res->flow_type);
12464         idx = ftype / UINT64_BIT;
12465         offset = ftype % UINT64_BIT;
12466         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12467         if (!strcmp(res->enable, "enable"))
12468                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12469                                                 (1ULL << offset);
12470         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12471                                         RTE_ETH_FILTER_SET, &info);
12472         if (ret < 0)
12473                 printf("Cannot set global hash configurations by port %d\n",
12474                                                         res->port_id);
12475         else
12476                 printf("Global hash configurations have been set "
12477                         "successfully by port %d\n", res->port_id);
12478 }
12479
12480 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12481         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12482                 set_hash_global_config, "set_hash_global_config");
12483 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12484         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12485                 port_id, UINT16);
12486 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12487         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12488                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12489 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12490         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12491                 flow_type,
12492                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12493                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12494 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12495         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12496                 enable, "enable#disable");
12497
12498 cmdline_parse_inst_t cmd_set_hash_global_config = {
12499         .f = cmd_set_hash_global_config_parsed,
12500         .data = NULL,
12501         .help_str = "set_hash_global_config <port_id> "
12502                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12503                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12504                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12505                 "l2_payload enable|disable",
12506         .tokens = {
12507                 (void *)&cmd_set_hash_global_config_all,
12508                 (void *)&cmd_set_hash_global_config_port_id,
12509                 (void *)&cmd_set_hash_global_config_hash_func,
12510                 (void *)&cmd_set_hash_global_config_flow_type,
12511                 (void *)&cmd_set_hash_global_config_enable,
12512                 NULL,
12513         },
12514 };
12515
12516 /* Set hash input set */
12517 struct cmd_set_hash_input_set_result {
12518         cmdline_fixed_string_t set_hash_input_set;
12519         portid_t port_id;
12520         cmdline_fixed_string_t flow_type;
12521         cmdline_fixed_string_t inset_field;
12522         cmdline_fixed_string_t select;
12523 };
12524
12525 static enum rte_eth_input_set_field
12526 str2inset(char *string)
12527 {
12528         uint16_t i;
12529
12530         static const struct {
12531                 char str[32];
12532                 enum rte_eth_input_set_field inset;
12533         } inset_table[] = {
12534                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12535                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12536                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12537                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12538                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12539                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12540                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12541                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12542                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12543                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12544                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12545                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12546                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12547                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12548                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12549                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12550                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12551                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12552                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12553                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12554                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12555                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12556                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12557                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12558                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12559                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12560                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12561                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12562                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12563                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12564                 {"none", RTE_ETH_INPUT_SET_NONE},
12565         };
12566
12567         for (i = 0; i < RTE_DIM(inset_table); i++) {
12568                 if (!strcmp(string, inset_table[i].str))
12569                         return inset_table[i].inset;
12570         }
12571
12572         return RTE_ETH_INPUT_SET_UNKNOWN;
12573 }
12574
12575 static void
12576 cmd_set_hash_input_set_parsed(void *parsed_result,
12577                               __rte_unused struct cmdline *cl,
12578                               __rte_unused void *data)
12579 {
12580         struct cmd_set_hash_input_set_result *res = parsed_result;
12581         struct rte_eth_hash_filter_info info;
12582
12583         memset(&info, 0, sizeof(info));
12584         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12585         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12586         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12587         info.info.input_set_conf.inset_size = 1;
12588         if (!strcmp(res->select, "select"))
12589                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12590         else if (!strcmp(res->select, "add"))
12591                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12592         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12593                                 RTE_ETH_FILTER_SET, &info);
12594 }
12595
12596 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12597         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12598                 set_hash_input_set, "set_hash_input_set");
12599 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12600         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12601                 port_id, UINT16);
12602 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12603         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12604                 flow_type, NULL);
12605 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12606         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12607                 inset_field,
12608                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12609                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12610                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12611                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12612                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12613                 "fld-8th#none");
12614 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12615         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12616                 select, "select#add");
12617
12618 cmdline_parse_inst_t cmd_set_hash_input_set = {
12619         .f = cmd_set_hash_input_set_parsed,
12620         .data = NULL,
12621         .help_str = "set_hash_input_set <port_id> "
12622         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12623         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12624         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12625         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12626         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12627         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12628         "fld-7th|fld-8th|none select|add",
12629         .tokens = {
12630                 (void *)&cmd_set_hash_input_set_cmd,
12631                 (void *)&cmd_set_hash_input_set_port_id,
12632                 (void *)&cmd_set_hash_input_set_flow_type,
12633                 (void *)&cmd_set_hash_input_set_field,
12634                 (void *)&cmd_set_hash_input_set_select,
12635                 NULL,
12636         },
12637 };
12638
12639 /* Set flow director input set */
12640 struct cmd_set_fdir_input_set_result {
12641         cmdline_fixed_string_t set_fdir_input_set;
12642         portid_t port_id;
12643         cmdline_fixed_string_t flow_type;
12644         cmdline_fixed_string_t inset_field;
12645         cmdline_fixed_string_t select;
12646 };
12647
12648 static void
12649 cmd_set_fdir_input_set_parsed(void *parsed_result,
12650         __rte_unused struct cmdline *cl,
12651         __rte_unused void *data)
12652 {
12653         struct cmd_set_fdir_input_set_result *res = parsed_result;
12654         struct rte_eth_fdir_filter_info info;
12655
12656         memset(&info, 0, sizeof(info));
12657         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12658         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12659         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12660         info.info.input_set_conf.inset_size = 1;
12661         if (!strcmp(res->select, "select"))
12662                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12663         else if (!strcmp(res->select, "add"))
12664                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12665         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12666                 RTE_ETH_FILTER_SET, &info);
12667 }
12668
12669 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12670         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12671         set_fdir_input_set, "set_fdir_input_set");
12672 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12673         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12674         port_id, UINT16);
12675 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12676         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12677         flow_type,
12678         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12679         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12680 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12681         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12682         inset_field,
12683         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12684         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12685         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12686         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12687         "sctp-veri-tag#none");
12688 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12689         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12690         select, "select#add");
12691
12692 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12693         .f = cmd_set_fdir_input_set_parsed,
12694         .data = NULL,
12695         .help_str = "set_fdir_input_set <port_id> "
12696         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12697         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12698         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12699         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12700         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12701         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12702         "sctp-veri-tag|none select|add",
12703         .tokens = {
12704                 (void *)&cmd_set_fdir_input_set_cmd,
12705                 (void *)&cmd_set_fdir_input_set_port_id,
12706                 (void *)&cmd_set_fdir_input_set_flow_type,
12707                 (void *)&cmd_set_fdir_input_set_field,
12708                 (void *)&cmd_set_fdir_input_set_select,
12709                 NULL,
12710         },
12711 };
12712
12713 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12714 struct cmd_mcast_addr_result {
12715         cmdline_fixed_string_t mcast_addr_cmd;
12716         cmdline_fixed_string_t what;
12717         uint16_t port_num;
12718         struct rte_ether_addr mc_addr;
12719 };
12720
12721 static void cmd_mcast_addr_parsed(void *parsed_result,
12722                 __rte_unused struct cmdline *cl,
12723                 __rte_unused void *data)
12724 {
12725         struct cmd_mcast_addr_result *res = parsed_result;
12726
12727         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12728                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12729                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12730                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12731                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12732                 return;
12733         }
12734         if (strcmp(res->what, "add") == 0)
12735                 mcast_addr_add(res->port_num, &res->mc_addr);
12736         else
12737                 mcast_addr_remove(res->port_num, &res->mc_addr);
12738 }
12739
12740 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12741         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12742                                  mcast_addr_cmd, "mcast_addr");
12743 cmdline_parse_token_string_t cmd_mcast_addr_what =
12744         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12745                                  "add#remove");
12746 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12747         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12748 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12749         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12750
12751 cmdline_parse_inst_t cmd_mcast_addr = {
12752         .f = cmd_mcast_addr_parsed,
12753         .data = (void *)0,
12754         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12755                 "Add/Remove multicast MAC address on port_id",
12756         .tokens = {
12757                 (void *)&cmd_mcast_addr_cmd,
12758                 (void *)&cmd_mcast_addr_what,
12759                 (void *)&cmd_mcast_addr_portnum,
12760                 (void *)&cmd_mcast_addr_addr,
12761                 NULL,
12762         },
12763 };
12764
12765 /* l2 tunnel config
12766  * only support E-tag now.
12767  */
12768
12769 /* Ether type config */
12770 struct cmd_config_l2_tunnel_eth_type_result {
12771         cmdline_fixed_string_t port;
12772         cmdline_fixed_string_t config;
12773         cmdline_fixed_string_t all;
12774         portid_t id;
12775         cmdline_fixed_string_t l2_tunnel;
12776         cmdline_fixed_string_t l2_tunnel_type;
12777         cmdline_fixed_string_t eth_type;
12778         uint16_t eth_type_val;
12779 };
12780
12781 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12782         TOKEN_STRING_INITIALIZER
12783                 (struct cmd_config_l2_tunnel_eth_type_result,
12784                  port, "port");
12785 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12786         TOKEN_STRING_INITIALIZER
12787                 (struct cmd_config_l2_tunnel_eth_type_result,
12788                  config, "config");
12789 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12790         TOKEN_STRING_INITIALIZER
12791                 (struct cmd_config_l2_tunnel_eth_type_result,
12792                  all, "all");
12793 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12794         TOKEN_NUM_INITIALIZER
12795                 (struct cmd_config_l2_tunnel_eth_type_result,
12796                  id, UINT16);
12797 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_config_l2_tunnel_eth_type_result,
12800                  l2_tunnel, "l2-tunnel");
12801 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12802         TOKEN_STRING_INITIALIZER
12803                 (struct cmd_config_l2_tunnel_eth_type_result,
12804                  l2_tunnel_type, "E-tag");
12805 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12806         TOKEN_STRING_INITIALIZER
12807                 (struct cmd_config_l2_tunnel_eth_type_result,
12808                  eth_type, "ether-type");
12809 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12810         TOKEN_NUM_INITIALIZER
12811                 (struct cmd_config_l2_tunnel_eth_type_result,
12812                  eth_type_val, UINT16);
12813
12814 static enum rte_eth_tunnel_type
12815 str2fdir_l2_tunnel_type(char *string)
12816 {
12817         uint32_t i = 0;
12818
12819         static const struct {
12820                 char str[32];
12821                 enum rte_eth_tunnel_type type;
12822         } l2_tunnel_type_str[] = {
12823                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12824         };
12825
12826         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12827                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12828                         return l2_tunnel_type_str[i].type;
12829         }
12830         return RTE_TUNNEL_TYPE_NONE;
12831 }
12832
12833 /* ether type config for all ports */
12834 static void
12835 cmd_config_l2_tunnel_eth_type_all_parsed
12836         (void *parsed_result,
12837          __rte_unused struct cmdline *cl,
12838          __rte_unused void *data)
12839 {
12840         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12841         struct rte_eth_l2_tunnel_conf entry;
12842         portid_t pid;
12843
12844         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12845         entry.ether_type = res->eth_type_val;
12846
12847         RTE_ETH_FOREACH_DEV(pid) {
12848                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12849         }
12850 }
12851
12852 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12853         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12854         .data = NULL,
12855         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12856         .tokens = {
12857                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12858                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12859                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12860                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12861                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12862                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12863                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12864                 NULL,
12865         },
12866 };
12867
12868 /* ether type config for a specific port */
12869 static void
12870 cmd_config_l2_tunnel_eth_type_specific_parsed(
12871         void *parsed_result,
12872         __rte_unused struct cmdline *cl,
12873         __rte_unused void *data)
12874 {
12875         struct cmd_config_l2_tunnel_eth_type_result *res =
12876                  parsed_result;
12877         struct rte_eth_l2_tunnel_conf entry;
12878
12879         if (port_id_is_invalid(res->id, ENABLED_WARN))
12880                 return;
12881
12882         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12883         entry.ether_type = res->eth_type_val;
12884
12885         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12886 }
12887
12888 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12889         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12890         .data = NULL,
12891         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12892         .tokens = {
12893                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12894                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12895                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12896                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12897                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12898                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12899                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12900                 NULL,
12901         },
12902 };
12903
12904 /* Enable/disable l2 tunnel */
12905 struct cmd_config_l2_tunnel_en_dis_result {
12906         cmdline_fixed_string_t port;
12907         cmdline_fixed_string_t config;
12908         cmdline_fixed_string_t all;
12909         portid_t id;
12910         cmdline_fixed_string_t l2_tunnel;
12911         cmdline_fixed_string_t l2_tunnel_type;
12912         cmdline_fixed_string_t en_dis;
12913 };
12914
12915 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_config_l2_tunnel_en_dis_result,
12918                  port, "port");
12919 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12920         TOKEN_STRING_INITIALIZER
12921                 (struct cmd_config_l2_tunnel_en_dis_result,
12922                  config, "config");
12923 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12924         TOKEN_STRING_INITIALIZER
12925                 (struct cmd_config_l2_tunnel_en_dis_result,
12926                  all, "all");
12927 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12928         TOKEN_NUM_INITIALIZER
12929                 (struct cmd_config_l2_tunnel_en_dis_result,
12930                  id, UINT16);
12931 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_config_l2_tunnel_en_dis_result,
12934                  l2_tunnel, "l2-tunnel");
12935 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12936         TOKEN_STRING_INITIALIZER
12937                 (struct cmd_config_l2_tunnel_en_dis_result,
12938                  l2_tunnel_type, "E-tag");
12939 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12940         TOKEN_STRING_INITIALIZER
12941                 (struct cmd_config_l2_tunnel_en_dis_result,
12942                  en_dis, "enable#disable");
12943
12944 /* enable/disable l2 tunnel for all ports */
12945 static void
12946 cmd_config_l2_tunnel_en_dis_all_parsed(
12947         void *parsed_result,
12948         __rte_unused struct cmdline *cl,
12949         __rte_unused void *data)
12950 {
12951         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12952         struct rte_eth_l2_tunnel_conf entry;
12953         portid_t pid;
12954         uint8_t en;
12955
12956         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12957
12958         if (!strcmp("enable", res->en_dis))
12959                 en = 1;
12960         else
12961                 en = 0;
12962
12963         RTE_ETH_FOREACH_DEV(pid) {
12964                 rte_eth_dev_l2_tunnel_offload_set(pid,
12965                                                   &entry,
12966                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12967                                                   en);
12968         }
12969 }
12970
12971 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12972         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12973         .data = NULL,
12974         .help_str = "port config all l2-tunnel E-tag enable|disable",
12975         .tokens = {
12976                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12977                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12978                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12979                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12980                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12981                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12982                 NULL,
12983         },
12984 };
12985
12986 /* enable/disable l2 tunnel for a port */
12987 static void
12988 cmd_config_l2_tunnel_en_dis_specific_parsed(
12989         void *parsed_result,
12990         __rte_unused struct cmdline *cl,
12991         __rte_unused void *data)
12992 {
12993         struct cmd_config_l2_tunnel_en_dis_result *res =
12994                 parsed_result;
12995         struct rte_eth_l2_tunnel_conf entry;
12996
12997         if (port_id_is_invalid(res->id, ENABLED_WARN))
12998                 return;
12999
13000         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13001
13002         if (!strcmp("enable", res->en_dis))
13003                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13004                                                   &entry,
13005                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13006                                                   1);
13007         else
13008                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13009                                                   &entry,
13010                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13011                                                   0);
13012 }
13013
13014 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13015         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13016         .data = NULL,
13017         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13018         .tokens = {
13019                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13020                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13021                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13022                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13023                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13024                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13025                 NULL,
13026         },
13027 };
13028
13029 /* E-tag configuration */
13030
13031 /* Common result structure for all E-tag configuration */
13032 struct cmd_config_e_tag_result {
13033         cmdline_fixed_string_t e_tag;
13034         cmdline_fixed_string_t set;
13035         cmdline_fixed_string_t insertion;
13036         cmdline_fixed_string_t stripping;
13037         cmdline_fixed_string_t forwarding;
13038         cmdline_fixed_string_t filter;
13039         cmdline_fixed_string_t add;
13040         cmdline_fixed_string_t del;
13041         cmdline_fixed_string_t on;
13042         cmdline_fixed_string_t off;
13043         cmdline_fixed_string_t on_off;
13044         cmdline_fixed_string_t port_tag_id;
13045         uint32_t port_tag_id_val;
13046         cmdline_fixed_string_t e_tag_id;
13047         uint16_t e_tag_id_val;
13048         cmdline_fixed_string_t dst_pool;
13049         uint8_t dst_pool_val;
13050         cmdline_fixed_string_t port;
13051         portid_t port_id;
13052         cmdline_fixed_string_t vf;
13053         uint8_t vf_id;
13054 };
13055
13056 /* Common CLI fields for all E-tag configuration */
13057 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13058         TOKEN_STRING_INITIALIZER
13059                 (struct cmd_config_e_tag_result,
13060                  e_tag, "E-tag");
13061 cmdline_parse_token_string_t cmd_config_e_tag_set =
13062         TOKEN_STRING_INITIALIZER
13063                 (struct cmd_config_e_tag_result,
13064                  set, "set");
13065 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13066         TOKEN_STRING_INITIALIZER
13067                 (struct cmd_config_e_tag_result,
13068                  insertion, "insertion");
13069 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_config_e_tag_result,
13072                  stripping, "stripping");
13073 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_config_e_tag_result,
13076                  forwarding, "forwarding");
13077 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_config_e_tag_result,
13080                  filter, "filter");
13081 cmdline_parse_token_string_t cmd_config_e_tag_add =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_config_e_tag_result,
13084                  add, "add");
13085 cmdline_parse_token_string_t cmd_config_e_tag_del =
13086         TOKEN_STRING_INITIALIZER
13087                 (struct cmd_config_e_tag_result,
13088                  del, "del");
13089 cmdline_parse_token_string_t cmd_config_e_tag_on =
13090         TOKEN_STRING_INITIALIZER
13091                 (struct cmd_config_e_tag_result,
13092                  on, "on");
13093 cmdline_parse_token_string_t cmd_config_e_tag_off =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_config_e_tag_result,
13096                  off, "off");
13097 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13098         TOKEN_STRING_INITIALIZER
13099                 (struct cmd_config_e_tag_result,
13100                  on_off, "on#off");
13101 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13102         TOKEN_STRING_INITIALIZER
13103                 (struct cmd_config_e_tag_result,
13104                  port_tag_id, "port-tag-id");
13105 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13106         TOKEN_NUM_INITIALIZER
13107                 (struct cmd_config_e_tag_result,
13108                  port_tag_id_val, UINT32);
13109 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13110         TOKEN_STRING_INITIALIZER
13111                 (struct cmd_config_e_tag_result,
13112                  e_tag_id, "e-tag-id");
13113 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13114         TOKEN_NUM_INITIALIZER
13115                 (struct cmd_config_e_tag_result,
13116                  e_tag_id_val, UINT16);
13117 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13118         TOKEN_STRING_INITIALIZER
13119                 (struct cmd_config_e_tag_result,
13120                  dst_pool, "dst-pool");
13121 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13122         TOKEN_NUM_INITIALIZER
13123                 (struct cmd_config_e_tag_result,
13124                  dst_pool_val, UINT8);
13125 cmdline_parse_token_string_t cmd_config_e_tag_port =
13126         TOKEN_STRING_INITIALIZER
13127                 (struct cmd_config_e_tag_result,
13128                  port, "port");
13129 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13130         TOKEN_NUM_INITIALIZER
13131                 (struct cmd_config_e_tag_result,
13132                  port_id, UINT16);
13133 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13134         TOKEN_STRING_INITIALIZER
13135                 (struct cmd_config_e_tag_result,
13136                  vf, "vf");
13137 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13138         TOKEN_NUM_INITIALIZER
13139                 (struct cmd_config_e_tag_result,
13140                  vf_id, UINT8);
13141
13142 /* E-tag insertion configuration */
13143 static void
13144 cmd_config_e_tag_insertion_en_parsed(
13145         void *parsed_result,
13146         __rte_unused struct cmdline *cl,
13147         __rte_unused void *data)
13148 {
13149         struct cmd_config_e_tag_result *res =
13150                 parsed_result;
13151         struct rte_eth_l2_tunnel_conf entry;
13152
13153         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13154                 return;
13155
13156         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13157         entry.tunnel_id = res->port_tag_id_val;
13158         entry.vf_id = res->vf_id;
13159         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13160                                           &entry,
13161                                           ETH_L2_TUNNEL_INSERTION_MASK,
13162                                           1);
13163 }
13164
13165 static void
13166 cmd_config_e_tag_insertion_dis_parsed(
13167         void *parsed_result,
13168         __rte_unused struct cmdline *cl,
13169         __rte_unused void *data)
13170 {
13171         struct cmd_config_e_tag_result *res =
13172                 parsed_result;
13173         struct rte_eth_l2_tunnel_conf entry;
13174
13175         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13176                 return;
13177
13178         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13179         entry.vf_id = res->vf_id;
13180
13181         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13182                                           &entry,
13183                                           ETH_L2_TUNNEL_INSERTION_MASK,
13184                                           0);
13185 }
13186
13187 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13188         .f = cmd_config_e_tag_insertion_en_parsed,
13189         .data = NULL,
13190         .help_str = "E-tag ... : E-tag insertion enable",
13191         .tokens = {
13192                 (void *)&cmd_config_e_tag_e_tag,
13193                 (void *)&cmd_config_e_tag_set,
13194                 (void *)&cmd_config_e_tag_insertion,
13195                 (void *)&cmd_config_e_tag_on,
13196                 (void *)&cmd_config_e_tag_port_tag_id,
13197                 (void *)&cmd_config_e_tag_port_tag_id_val,
13198                 (void *)&cmd_config_e_tag_port,
13199                 (void *)&cmd_config_e_tag_port_id,
13200                 (void *)&cmd_config_e_tag_vf,
13201                 (void *)&cmd_config_e_tag_vf_id,
13202                 NULL,
13203         },
13204 };
13205
13206 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13207         .f = cmd_config_e_tag_insertion_dis_parsed,
13208         .data = NULL,
13209         .help_str = "E-tag ... : E-tag insertion disable",
13210         .tokens = {
13211                 (void *)&cmd_config_e_tag_e_tag,
13212                 (void *)&cmd_config_e_tag_set,
13213                 (void *)&cmd_config_e_tag_insertion,
13214                 (void *)&cmd_config_e_tag_off,
13215                 (void *)&cmd_config_e_tag_port,
13216                 (void *)&cmd_config_e_tag_port_id,
13217                 (void *)&cmd_config_e_tag_vf,
13218                 (void *)&cmd_config_e_tag_vf_id,
13219                 NULL,
13220         },
13221 };
13222
13223 /* E-tag stripping configuration */
13224 static void
13225 cmd_config_e_tag_stripping_parsed(
13226         void *parsed_result,
13227         __rte_unused struct cmdline *cl,
13228         __rte_unused void *data)
13229 {
13230         struct cmd_config_e_tag_result *res =
13231                 parsed_result;
13232         struct rte_eth_l2_tunnel_conf entry;
13233
13234         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13235                 return;
13236
13237         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13238
13239         if (!strcmp(res->on_off, "on"))
13240                 rte_eth_dev_l2_tunnel_offload_set
13241                         (res->port_id,
13242                          &entry,
13243                          ETH_L2_TUNNEL_STRIPPING_MASK,
13244                          1);
13245         else
13246                 rte_eth_dev_l2_tunnel_offload_set
13247                         (res->port_id,
13248                          &entry,
13249                          ETH_L2_TUNNEL_STRIPPING_MASK,
13250                          0);
13251 }
13252
13253 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13254         .f = cmd_config_e_tag_stripping_parsed,
13255         .data = NULL,
13256         .help_str = "E-tag ... : E-tag stripping enable/disable",
13257         .tokens = {
13258                 (void *)&cmd_config_e_tag_e_tag,
13259                 (void *)&cmd_config_e_tag_set,
13260                 (void *)&cmd_config_e_tag_stripping,
13261                 (void *)&cmd_config_e_tag_on_off,
13262                 (void *)&cmd_config_e_tag_port,
13263                 (void *)&cmd_config_e_tag_port_id,
13264                 NULL,
13265         },
13266 };
13267
13268 /* E-tag forwarding configuration */
13269 static void
13270 cmd_config_e_tag_forwarding_parsed(
13271         void *parsed_result,
13272         __rte_unused struct cmdline *cl,
13273         __rte_unused void *data)
13274 {
13275         struct cmd_config_e_tag_result *res = parsed_result;
13276         struct rte_eth_l2_tunnel_conf entry;
13277
13278         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13279                 return;
13280
13281         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13282
13283         if (!strcmp(res->on_off, "on"))
13284                 rte_eth_dev_l2_tunnel_offload_set
13285                         (res->port_id,
13286                          &entry,
13287                          ETH_L2_TUNNEL_FORWARDING_MASK,
13288                          1);
13289         else
13290                 rte_eth_dev_l2_tunnel_offload_set
13291                         (res->port_id,
13292                          &entry,
13293                          ETH_L2_TUNNEL_FORWARDING_MASK,
13294                          0);
13295 }
13296
13297 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13298         .f = cmd_config_e_tag_forwarding_parsed,
13299         .data = NULL,
13300         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13301         .tokens = {
13302                 (void *)&cmd_config_e_tag_e_tag,
13303                 (void *)&cmd_config_e_tag_set,
13304                 (void *)&cmd_config_e_tag_forwarding,
13305                 (void *)&cmd_config_e_tag_on_off,
13306                 (void *)&cmd_config_e_tag_port,
13307                 (void *)&cmd_config_e_tag_port_id,
13308                 NULL,
13309         },
13310 };
13311
13312 /* E-tag filter configuration */
13313 static void
13314 cmd_config_e_tag_filter_add_parsed(
13315         void *parsed_result,
13316         __rte_unused struct cmdline *cl,
13317         __rte_unused void *data)
13318 {
13319         struct cmd_config_e_tag_result *res = parsed_result;
13320         struct rte_eth_l2_tunnel_conf entry;
13321         int ret = 0;
13322
13323         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13324                 return;
13325
13326         if (res->e_tag_id_val > 0x3fff) {
13327                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13328                 return;
13329         }
13330
13331         ret = rte_eth_dev_filter_supported(res->port_id,
13332                                            RTE_ETH_FILTER_L2_TUNNEL);
13333         if (ret < 0) {
13334                 printf("E-tag filter is not supported on port %u.\n",
13335                        res->port_id);
13336                 return;
13337         }
13338
13339         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13340         entry.tunnel_id = res->e_tag_id_val;
13341         entry.pool = res->dst_pool_val;
13342
13343         ret = rte_eth_dev_filter_ctrl(res->port_id,
13344                                       RTE_ETH_FILTER_L2_TUNNEL,
13345                                       RTE_ETH_FILTER_ADD,
13346                                       &entry);
13347         if (ret < 0)
13348                 printf("E-tag filter programming error: (%s)\n",
13349                        strerror(-ret));
13350 }
13351
13352 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13353         .f = cmd_config_e_tag_filter_add_parsed,
13354         .data = NULL,
13355         .help_str = "E-tag ... : E-tag filter add",
13356         .tokens = {
13357                 (void *)&cmd_config_e_tag_e_tag,
13358                 (void *)&cmd_config_e_tag_set,
13359                 (void *)&cmd_config_e_tag_filter,
13360                 (void *)&cmd_config_e_tag_add,
13361                 (void *)&cmd_config_e_tag_e_tag_id,
13362                 (void *)&cmd_config_e_tag_e_tag_id_val,
13363                 (void *)&cmd_config_e_tag_dst_pool,
13364                 (void *)&cmd_config_e_tag_dst_pool_val,
13365                 (void *)&cmd_config_e_tag_port,
13366                 (void *)&cmd_config_e_tag_port_id,
13367                 NULL,
13368         },
13369 };
13370
13371 static void
13372 cmd_config_e_tag_filter_del_parsed(
13373         void *parsed_result,
13374         __rte_unused struct cmdline *cl,
13375         __rte_unused void *data)
13376 {
13377         struct cmd_config_e_tag_result *res = parsed_result;
13378         struct rte_eth_l2_tunnel_conf entry;
13379         int ret = 0;
13380
13381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13382                 return;
13383
13384         if (res->e_tag_id_val > 0x3fff) {
13385                 printf("e-tag-id must be less than 0x3fff.\n");
13386                 return;
13387         }
13388
13389         ret = rte_eth_dev_filter_supported(res->port_id,
13390                                            RTE_ETH_FILTER_L2_TUNNEL);
13391         if (ret < 0) {
13392                 printf("E-tag filter is not supported on port %u.\n",
13393                        res->port_id);
13394                 return;
13395         }
13396
13397         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13398         entry.tunnel_id = res->e_tag_id_val;
13399
13400         ret = rte_eth_dev_filter_ctrl(res->port_id,
13401                                       RTE_ETH_FILTER_L2_TUNNEL,
13402                                       RTE_ETH_FILTER_DELETE,
13403                                       &entry);
13404         if (ret < 0)
13405                 printf("E-tag filter programming error: (%s)\n",
13406                        strerror(-ret));
13407 }
13408
13409 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13410         .f = cmd_config_e_tag_filter_del_parsed,
13411         .data = NULL,
13412         .help_str = "E-tag ... : E-tag filter delete",
13413         .tokens = {
13414                 (void *)&cmd_config_e_tag_e_tag,
13415                 (void *)&cmd_config_e_tag_set,
13416                 (void *)&cmd_config_e_tag_filter,
13417                 (void *)&cmd_config_e_tag_del,
13418                 (void *)&cmd_config_e_tag_e_tag_id,
13419                 (void *)&cmd_config_e_tag_e_tag_id_val,
13420                 (void *)&cmd_config_e_tag_port,
13421                 (void *)&cmd_config_e_tag_port_id,
13422                 NULL,
13423         },
13424 };
13425
13426 /* vf vlan anti spoof configuration */
13427
13428 /* Common result structure for vf vlan anti spoof */
13429 struct cmd_vf_vlan_anti_spoof_result {
13430         cmdline_fixed_string_t set;
13431         cmdline_fixed_string_t vf;
13432         cmdline_fixed_string_t vlan;
13433         cmdline_fixed_string_t antispoof;
13434         portid_t port_id;
13435         uint32_t vf_id;
13436         cmdline_fixed_string_t on_off;
13437 };
13438
13439 /* Common CLI fields for vf vlan anti spoof enable disable */
13440 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13441         TOKEN_STRING_INITIALIZER
13442                 (struct cmd_vf_vlan_anti_spoof_result,
13443                  set, "set");
13444 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13445         TOKEN_STRING_INITIALIZER
13446                 (struct cmd_vf_vlan_anti_spoof_result,
13447                  vf, "vf");
13448 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13449         TOKEN_STRING_INITIALIZER
13450                 (struct cmd_vf_vlan_anti_spoof_result,
13451                  vlan, "vlan");
13452 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13453         TOKEN_STRING_INITIALIZER
13454                 (struct cmd_vf_vlan_anti_spoof_result,
13455                  antispoof, "antispoof");
13456 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13457         TOKEN_NUM_INITIALIZER
13458                 (struct cmd_vf_vlan_anti_spoof_result,
13459                  port_id, UINT16);
13460 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13461         TOKEN_NUM_INITIALIZER
13462                 (struct cmd_vf_vlan_anti_spoof_result,
13463                  vf_id, UINT32);
13464 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_vf_vlan_anti_spoof_result,
13467                  on_off, "on#off");
13468
13469 static void
13470 cmd_set_vf_vlan_anti_spoof_parsed(
13471         void *parsed_result,
13472         __rte_unused struct cmdline *cl,
13473         __rte_unused void *data)
13474 {
13475         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13476         int ret = -ENOTSUP;
13477
13478         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13479
13480         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13481                 return;
13482
13483 #ifdef RTE_LIBRTE_IXGBE_PMD
13484         if (ret == -ENOTSUP)
13485                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13486                                 res->vf_id, is_on);
13487 #endif
13488 #ifdef RTE_LIBRTE_I40E_PMD
13489         if (ret == -ENOTSUP)
13490                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13491                                 res->vf_id, is_on);
13492 #endif
13493 #ifdef RTE_LIBRTE_BNXT_PMD
13494         if (ret == -ENOTSUP)
13495                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13496                                 res->vf_id, is_on);
13497 #endif
13498
13499         switch (ret) {
13500         case 0:
13501                 break;
13502         case -EINVAL:
13503                 printf("invalid vf_id %d\n", res->vf_id);
13504                 break;
13505         case -ENODEV:
13506                 printf("invalid port_id %d\n", res->port_id);
13507                 break;
13508         case -ENOTSUP:
13509                 printf("function not implemented\n");
13510                 break;
13511         default:
13512                 printf("programming error: (%s)\n", strerror(-ret));
13513         }
13514 }
13515
13516 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13517         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13518         .data = NULL,
13519         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13520         .tokens = {
13521                 (void *)&cmd_vf_vlan_anti_spoof_set,
13522                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13523                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13524                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13525                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13526                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13527                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13528                 NULL,
13529         },
13530 };
13531
13532 /* vf mac anti spoof configuration */
13533
13534 /* Common result structure for vf mac anti spoof */
13535 struct cmd_vf_mac_anti_spoof_result {
13536         cmdline_fixed_string_t set;
13537         cmdline_fixed_string_t vf;
13538         cmdline_fixed_string_t mac;
13539         cmdline_fixed_string_t antispoof;
13540         portid_t port_id;
13541         uint32_t vf_id;
13542         cmdline_fixed_string_t on_off;
13543 };
13544
13545 /* Common CLI fields for vf mac anti spoof enable disable */
13546 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13547         TOKEN_STRING_INITIALIZER
13548                 (struct cmd_vf_mac_anti_spoof_result,
13549                  set, "set");
13550 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13551         TOKEN_STRING_INITIALIZER
13552                 (struct cmd_vf_mac_anti_spoof_result,
13553                  vf, "vf");
13554 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13555         TOKEN_STRING_INITIALIZER
13556                 (struct cmd_vf_mac_anti_spoof_result,
13557                  mac, "mac");
13558 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_vf_mac_anti_spoof_result,
13561                  antispoof, "antispoof");
13562 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13563         TOKEN_NUM_INITIALIZER
13564                 (struct cmd_vf_mac_anti_spoof_result,
13565                  port_id, UINT16);
13566 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13567         TOKEN_NUM_INITIALIZER
13568                 (struct cmd_vf_mac_anti_spoof_result,
13569                  vf_id, UINT32);
13570 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_vf_mac_anti_spoof_result,
13573                  on_off, "on#off");
13574
13575 static void
13576 cmd_set_vf_mac_anti_spoof_parsed(
13577         void *parsed_result,
13578         __rte_unused struct cmdline *cl,
13579         __rte_unused void *data)
13580 {
13581         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13582         int ret = -ENOTSUP;
13583
13584         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13585
13586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13587                 return;
13588
13589 #ifdef RTE_LIBRTE_IXGBE_PMD
13590         if (ret == -ENOTSUP)
13591                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13592                         res->vf_id, is_on);
13593 #endif
13594 #ifdef RTE_LIBRTE_I40E_PMD
13595         if (ret == -ENOTSUP)
13596                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13597                         res->vf_id, is_on);
13598 #endif
13599 #ifdef RTE_LIBRTE_BNXT_PMD
13600         if (ret == -ENOTSUP)
13601                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13602                         res->vf_id, is_on);
13603 #endif
13604
13605         switch (ret) {
13606         case 0:
13607                 break;
13608         case -EINVAL:
13609                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13610                 break;
13611         case -ENODEV:
13612                 printf("invalid port_id %d\n", res->port_id);
13613                 break;
13614         case -ENOTSUP:
13615                 printf("function not implemented\n");
13616                 break;
13617         default:
13618                 printf("programming error: (%s)\n", strerror(-ret));
13619         }
13620 }
13621
13622 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13623         .f = cmd_set_vf_mac_anti_spoof_parsed,
13624         .data = NULL,
13625         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13626         .tokens = {
13627                 (void *)&cmd_vf_mac_anti_spoof_set,
13628                 (void *)&cmd_vf_mac_anti_spoof_vf,
13629                 (void *)&cmd_vf_mac_anti_spoof_mac,
13630                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13631                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13632                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13633                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13634                 NULL,
13635         },
13636 };
13637
13638 /* vf vlan strip queue configuration */
13639
13640 /* Common result structure for vf mac anti spoof */
13641 struct cmd_vf_vlan_stripq_result {
13642         cmdline_fixed_string_t set;
13643         cmdline_fixed_string_t vf;
13644         cmdline_fixed_string_t vlan;
13645         cmdline_fixed_string_t stripq;
13646         portid_t port_id;
13647         uint16_t vf_id;
13648         cmdline_fixed_string_t on_off;
13649 };
13650
13651 /* Common CLI fields for vf vlan strip enable disable */
13652 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13653         TOKEN_STRING_INITIALIZER
13654                 (struct cmd_vf_vlan_stripq_result,
13655                  set, "set");
13656 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_vf_vlan_stripq_result,
13659                  vf, "vf");
13660 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13661         TOKEN_STRING_INITIALIZER
13662                 (struct cmd_vf_vlan_stripq_result,
13663                  vlan, "vlan");
13664 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_vf_vlan_stripq_result,
13667                  stripq, "stripq");
13668 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13669         TOKEN_NUM_INITIALIZER
13670                 (struct cmd_vf_vlan_stripq_result,
13671                  port_id, UINT16);
13672 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13673         TOKEN_NUM_INITIALIZER
13674                 (struct cmd_vf_vlan_stripq_result,
13675                  vf_id, UINT16);
13676 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_vf_vlan_stripq_result,
13679                  on_off, "on#off");
13680
13681 static void
13682 cmd_set_vf_vlan_stripq_parsed(
13683         void *parsed_result,
13684         __rte_unused struct cmdline *cl,
13685         __rte_unused void *data)
13686 {
13687         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13688         int ret = -ENOTSUP;
13689
13690         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13691
13692         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13693                 return;
13694
13695 #ifdef RTE_LIBRTE_IXGBE_PMD
13696         if (ret == -ENOTSUP)
13697                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13698                         res->vf_id, is_on);
13699 #endif
13700 #ifdef RTE_LIBRTE_I40E_PMD
13701         if (ret == -ENOTSUP)
13702                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13703                         res->vf_id, is_on);
13704 #endif
13705 #ifdef RTE_LIBRTE_BNXT_PMD
13706         if (ret == -ENOTSUP)
13707                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13708                         res->vf_id, is_on);
13709 #endif
13710
13711         switch (ret) {
13712         case 0:
13713                 break;
13714         case -EINVAL:
13715                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13716                 break;
13717         case -ENODEV:
13718                 printf("invalid port_id %d\n", res->port_id);
13719                 break;
13720         case -ENOTSUP:
13721                 printf("function not implemented\n");
13722                 break;
13723         default:
13724                 printf("programming error: (%s)\n", strerror(-ret));
13725         }
13726 }
13727
13728 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13729         .f = cmd_set_vf_vlan_stripq_parsed,
13730         .data = NULL,
13731         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13732         .tokens = {
13733                 (void *)&cmd_vf_vlan_stripq_set,
13734                 (void *)&cmd_vf_vlan_stripq_vf,
13735                 (void *)&cmd_vf_vlan_stripq_vlan,
13736                 (void *)&cmd_vf_vlan_stripq_stripq,
13737                 (void *)&cmd_vf_vlan_stripq_port_id,
13738                 (void *)&cmd_vf_vlan_stripq_vf_id,
13739                 (void *)&cmd_vf_vlan_stripq_on_off,
13740                 NULL,
13741         },
13742 };
13743
13744 /* vf vlan insert configuration */
13745
13746 /* Common result structure for vf vlan insert */
13747 struct cmd_vf_vlan_insert_result {
13748         cmdline_fixed_string_t set;
13749         cmdline_fixed_string_t vf;
13750         cmdline_fixed_string_t vlan;
13751         cmdline_fixed_string_t insert;
13752         portid_t port_id;
13753         uint16_t vf_id;
13754         uint16_t vlan_id;
13755 };
13756
13757 /* Common CLI fields for vf vlan insert enable disable */
13758 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_vf_vlan_insert_result,
13761                  set, "set");
13762 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_vf_vlan_insert_result,
13765                  vf, "vf");
13766 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13767         TOKEN_STRING_INITIALIZER
13768                 (struct cmd_vf_vlan_insert_result,
13769                  vlan, "vlan");
13770 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_vf_vlan_insert_result,
13773                  insert, "insert");
13774 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13775         TOKEN_NUM_INITIALIZER
13776                 (struct cmd_vf_vlan_insert_result,
13777                  port_id, UINT16);
13778 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13779         TOKEN_NUM_INITIALIZER
13780                 (struct cmd_vf_vlan_insert_result,
13781                  vf_id, UINT16);
13782 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13783         TOKEN_NUM_INITIALIZER
13784                 (struct cmd_vf_vlan_insert_result,
13785                  vlan_id, UINT16);
13786
13787 static void
13788 cmd_set_vf_vlan_insert_parsed(
13789         void *parsed_result,
13790         __rte_unused struct cmdline *cl,
13791         __rte_unused void *data)
13792 {
13793         struct cmd_vf_vlan_insert_result *res = parsed_result;
13794         int ret = -ENOTSUP;
13795
13796         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13797                 return;
13798
13799 #ifdef RTE_LIBRTE_IXGBE_PMD
13800         if (ret == -ENOTSUP)
13801                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13802                         res->vlan_id);
13803 #endif
13804 #ifdef RTE_LIBRTE_I40E_PMD
13805         if (ret == -ENOTSUP)
13806                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13807                         res->vlan_id);
13808 #endif
13809 #ifdef RTE_LIBRTE_BNXT_PMD
13810         if (ret == -ENOTSUP)
13811                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13812                         res->vlan_id);
13813 #endif
13814
13815         switch (ret) {
13816         case 0:
13817                 break;
13818         case -EINVAL:
13819                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13820                 break;
13821         case -ENODEV:
13822                 printf("invalid port_id %d\n", res->port_id);
13823                 break;
13824         case -ENOTSUP:
13825                 printf("function not implemented\n");
13826                 break;
13827         default:
13828                 printf("programming error: (%s)\n", strerror(-ret));
13829         }
13830 }
13831
13832 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13833         .f = cmd_set_vf_vlan_insert_parsed,
13834         .data = NULL,
13835         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13836         .tokens = {
13837                 (void *)&cmd_vf_vlan_insert_set,
13838                 (void *)&cmd_vf_vlan_insert_vf,
13839                 (void *)&cmd_vf_vlan_insert_vlan,
13840                 (void *)&cmd_vf_vlan_insert_insert,
13841                 (void *)&cmd_vf_vlan_insert_port_id,
13842                 (void *)&cmd_vf_vlan_insert_vf_id,
13843                 (void *)&cmd_vf_vlan_insert_vlan_id,
13844                 NULL,
13845         },
13846 };
13847
13848 /* tx loopback configuration */
13849
13850 /* Common result structure for tx loopback */
13851 struct cmd_tx_loopback_result {
13852         cmdline_fixed_string_t set;
13853         cmdline_fixed_string_t tx;
13854         cmdline_fixed_string_t loopback;
13855         portid_t port_id;
13856         cmdline_fixed_string_t on_off;
13857 };
13858
13859 /* Common CLI fields for tx loopback enable disable */
13860 cmdline_parse_token_string_t cmd_tx_loopback_set =
13861         TOKEN_STRING_INITIALIZER
13862                 (struct cmd_tx_loopback_result,
13863                  set, "set");
13864 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13865         TOKEN_STRING_INITIALIZER
13866                 (struct cmd_tx_loopback_result,
13867                  tx, "tx");
13868 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_tx_loopback_result,
13871                  loopback, "loopback");
13872 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13873         TOKEN_NUM_INITIALIZER
13874                 (struct cmd_tx_loopback_result,
13875                  port_id, UINT16);
13876 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_tx_loopback_result,
13879                  on_off, "on#off");
13880
13881 static void
13882 cmd_set_tx_loopback_parsed(
13883         void *parsed_result,
13884         __rte_unused struct cmdline *cl,
13885         __rte_unused void *data)
13886 {
13887         struct cmd_tx_loopback_result *res = parsed_result;
13888         int ret = -ENOTSUP;
13889
13890         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13891
13892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13893                 return;
13894
13895 #ifdef RTE_LIBRTE_IXGBE_PMD
13896         if (ret == -ENOTSUP)
13897                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13898 #endif
13899 #ifdef RTE_LIBRTE_I40E_PMD
13900         if (ret == -ENOTSUP)
13901                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13902 #endif
13903 #ifdef RTE_LIBRTE_BNXT_PMD
13904         if (ret == -ENOTSUP)
13905                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13906 #endif
13907 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13908         if (ret == -ENOTSUP)
13909                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13910 #endif
13911
13912         switch (ret) {
13913         case 0:
13914                 break;
13915         case -EINVAL:
13916                 printf("invalid is_on %d\n", is_on);
13917                 break;
13918         case -ENODEV:
13919                 printf("invalid port_id %d\n", res->port_id);
13920                 break;
13921         case -ENOTSUP:
13922                 printf("function not implemented\n");
13923                 break;
13924         default:
13925                 printf("programming error: (%s)\n", strerror(-ret));
13926         }
13927 }
13928
13929 cmdline_parse_inst_t cmd_set_tx_loopback = {
13930         .f = cmd_set_tx_loopback_parsed,
13931         .data = NULL,
13932         .help_str = "set tx loopback <port_id> on|off",
13933         .tokens = {
13934                 (void *)&cmd_tx_loopback_set,
13935                 (void *)&cmd_tx_loopback_tx,
13936                 (void *)&cmd_tx_loopback_loopback,
13937                 (void *)&cmd_tx_loopback_port_id,
13938                 (void *)&cmd_tx_loopback_on_off,
13939                 NULL,
13940         },
13941 };
13942
13943 /* all queues drop enable configuration */
13944
13945 /* Common result structure for all queues drop enable */
13946 struct cmd_all_queues_drop_en_result {
13947         cmdline_fixed_string_t set;
13948         cmdline_fixed_string_t all;
13949         cmdline_fixed_string_t queues;
13950         cmdline_fixed_string_t drop;
13951         portid_t port_id;
13952         cmdline_fixed_string_t on_off;
13953 };
13954
13955 /* Common CLI fields for tx loopback enable disable */
13956 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_all_queues_drop_en_result,
13959                  set, "set");
13960 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_all_queues_drop_en_result,
13963                  all, "all");
13964 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_all_queues_drop_en_result,
13967                  queues, "queues");
13968 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_all_queues_drop_en_result,
13971                  drop, "drop");
13972 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13973         TOKEN_NUM_INITIALIZER
13974                 (struct cmd_all_queues_drop_en_result,
13975                  port_id, UINT16);
13976 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13977         TOKEN_STRING_INITIALIZER
13978                 (struct cmd_all_queues_drop_en_result,
13979                  on_off, "on#off");
13980
13981 static void
13982 cmd_set_all_queues_drop_en_parsed(
13983         void *parsed_result,
13984         __rte_unused struct cmdline *cl,
13985         __rte_unused void *data)
13986 {
13987         struct cmd_all_queues_drop_en_result *res = parsed_result;
13988         int ret = -ENOTSUP;
13989         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13990
13991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13992                 return;
13993
13994 #ifdef RTE_LIBRTE_IXGBE_PMD
13995         if (ret == -ENOTSUP)
13996                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13997 #endif
13998 #ifdef RTE_LIBRTE_BNXT_PMD
13999         if (ret == -ENOTSUP)
14000                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14001 #endif
14002         switch (ret) {
14003         case 0:
14004                 break;
14005         case -EINVAL:
14006                 printf("invalid is_on %d\n", is_on);
14007                 break;
14008         case -ENODEV:
14009                 printf("invalid port_id %d\n", res->port_id);
14010                 break;
14011         case -ENOTSUP:
14012                 printf("function not implemented\n");
14013                 break;
14014         default:
14015                 printf("programming error: (%s)\n", strerror(-ret));
14016         }
14017 }
14018
14019 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14020         .f = cmd_set_all_queues_drop_en_parsed,
14021         .data = NULL,
14022         .help_str = "set all queues drop <port_id> on|off",
14023         .tokens = {
14024                 (void *)&cmd_all_queues_drop_en_set,
14025                 (void *)&cmd_all_queues_drop_en_all,
14026                 (void *)&cmd_all_queues_drop_en_queues,
14027                 (void *)&cmd_all_queues_drop_en_drop,
14028                 (void *)&cmd_all_queues_drop_en_port_id,
14029                 (void *)&cmd_all_queues_drop_en_on_off,
14030                 NULL,
14031         },
14032 };
14033
14034 /* vf split drop enable configuration */
14035
14036 /* Common result structure for vf split drop enable */
14037 struct cmd_vf_split_drop_en_result {
14038         cmdline_fixed_string_t set;
14039         cmdline_fixed_string_t vf;
14040         cmdline_fixed_string_t split;
14041         cmdline_fixed_string_t drop;
14042         portid_t port_id;
14043         uint16_t vf_id;
14044         cmdline_fixed_string_t on_off;
14045 };
14046
14047 /* Common CLI fields for vf split drop enable disable */
14048 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14049         TOKEN_STRING_INITIALIZER
14050                 (struct cmd_vf_split_drop_en_result,
14051                  set, "set");
14052 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14053         TOKEN_STRING_INITIALIZER
14054                 (struct cmd_vf_split_drop_en_result,
14055                  vf, "vf");
14056 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14057         TOKEN_STRING_INITIALIZER
14058                 (struct cmd_vf_split_drop_en_result,
14059                  split, "split");
14060 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_vf_split_drop_en_result,
14063                  drop, "drop");
14064 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14065         TOKEN_NUM_INITIALIZER
14066                 (struct cmd_vf_split_drop_en_result,
14067                  port_id, UINT16);
14068 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14069         TOKEN_NUM_INITIALIZER
14070                 (struct cmd_vf_split_drop_en_result,
14071                  vf_id, UINT16);
14072 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14073         TOKEN_STRING_INITIALIZER
14074                 (struct cmd_vf_split_drop_en_result,
14075                  on_off, "on#off");
14076
14077 static void
14078 cmd_set_vf_split_drop_en_parsed(
14079         void *parsed_result,
14080         __rte_unused struct cmdline *cl,
14081         __rte_unused void *data)
14082 {
14083         struct cmd_vf_split_drop_en_result *res = parsed_result;
14084         int ret = -ENOTSUP;
14085         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14086
14087         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14088                 return;
14089
14090 #ifdef RTE_LIBRTE_IXGBE_PMD
14091         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14092                         is_on);
14093 #endif
14094         switch (ret) {
14095         case 0:
14096                 break;
14097         case -EINVAL:
14098                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14099                 break;
14100         case -ENODEV:
14101                 printf("invalid port_id %d\n", res->port_id);
14102                 break;
14103         case -ENOTSUP:
14104                 printf("not supported on port %d\n", res->port_id);
14105                 break;
14106         default:
14107                 printf("programming error: (%s)\n", strerror(-ret));
14108         }
14109 }
14110
14111 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14112         .f = cmd_set_vf_split_drop_en_parsed,
14113         .data = NULL,
14114         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14115         .tokens = {
14116                 (void *)&cmd_vf_split_drop_en_set,
14117                 (void *)&cmd_vf_split_drop_en_vf,
14118                 (void *)&cmd_vf_split_drop_en_split,
14119                 (void *)&cmd_vf_split_drop_en_drop,
14120                 (void *)&cmd_vf_split_drop_en_port_id,
14121                 (void *)&cmd_vf_split_drop_en_vf_id,
14122                 (void *)&cmd_vf_split_drop_en_on_off,
14123                 NULL,
14124         },
14125 };
14126
14127 /* vf mac address configuration */
14128
14129 /* Common result structure for vf mac address */
14130 struct cmd_set_vf_mac_addr_result {
14131         cmdline_fixed_string_t set;
14132         cmdline_fixed_string_t vf;
14133         cmdline_fixed_string_t mac;
14134         cmdline_fixed_string_t addr;
14135         portid_t port_id;
14136         uint16_t vf_id;
14137         struct rte_ether_addr mac_addr;
14138
14139 };
14140
14141 /* Common CLI fields for vf split drop enable disable */
14142 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14143         TOKEN_STRING_INITIALIZER
14144                 (struct cmd_set_vf_mac_addr_result,
14145                  set, "set");
14146 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14147         TOKEN_STRING_INITIALIZER
14148                 (struct cmd_set_vf_mac_addr_result,
14149                  vf, "vf");
14150 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14151         TOKEN_STRING_INITIALIZER
14152                 (struct cmd_set_vf_mac_addr_result,
14153                  mac, "mac");
14154 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14155         TOKEN_STRING_INITIALIZER
14156                 (struct cmd_set_vf_mac_addr_result,
14157                  addr, "addr");
14158 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14159         TOKEN_NUM_INITIALIZER
14160                 (struct cmd_set_vf_mac_addr_result,
14161                  port_id, UINT16);
14162 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14163         TOKEN_NUM_INITIALIZER
14164                 (struct cmd_set_vf_mac_addr_result,
14165                  vf_id, UINT16);
14166 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14167         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14168                  mac_addr);
14169
14170 static void
14171 cmd_set_vf_mac_addr_parsed(
14172         void *parsed_result,
14173         __rte_unused struct cmdline *cl,
14174         __rte_unused void *data)
14175 {
14176         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14177         int ret = -ENOTSUP;
14178
14179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14180                 return;
14181
14182 #ifdef RTE_LIBRTE_IXGBE_PMD
14183         if (ret == -ENOTSUP)
14184                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14185                                 &res->mac_addr);
14186 #endif
14187 #ifdef RTE_LIBRTE_I40E_PMD
14188         if (ret == -ENOTSUP)
14189                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14190                                 &res->mac_addr);
14191 #endif
14192 #ifdef RTE_LIBRTE_BNXT_PMD
14193         if (ret == -ENOTSUP)
14194                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14195                                 &res->mac_addr);
14196 #endif
14197
14198         switch (ret) {
14199         case 0:
14200                 break;
14201         case -EINVAL:
14202                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14203                 break;
14204         case -ENODEV:
14205                 printf("invalid port_id %d\n", res->port_id);
14206                 break;
14207         case -ENOTSUP:
14208                 printf("function not implemented\n");
14209                 break;
14210         default:
14211                 printf("programming error: (%s)\n", strerror(-ret));
14212         }
14213 }
14214
14215 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14216         .f = cmd_set_vf_mac_addr_parsed,
14217         .data = NULL,
14218         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14219         .tokens = {
14220                 (void *)&cmd_set_vf_mac_addr_set,
14221                 (void *)&cmd_set_vf_mac_addr_vf,
14222                 (void *)&cmd_set_vf_mac_addr_mac,
14223                 (void *)&cmd_set_vf_mac_addr_addr,
14224                 (void *)&cmd_set_vf_mac_addr_port_id,
14225                 (void *)&cmd_set_vf_mac_addr_vf_id,
14226                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14227                 NULL,
14228         },
14229 };
14230
14231 /* MACsec configuration */
14232
14233 /* Common result structure for MACsec offload enable */
14234 struct cmd_macsec_offload_on_result {
14235         cmdline_fixed_string_t set;
14236         cmdline_fixed_string_t macsec;
14237         cmdline_fixed_string_t offload;
14238         portid_t port_id;
14239         cmdline_fixed_string_t on;
14240         cmdline_fixed_string_t encrypt;
14241         cmdline_fixed_string_t en_on_off;
14242         cmdline_fixed_string_t replay_protect;
14243         cmdline_fixed_string_t rp_on_off;
14244 };
14245
14246 /* Common CLI fields for MACsec offload disable */
14247 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14248         TOKEN_STRING_INITIALIZER
14249                 (struct cmd_macsec_offload_on_result,
14250                  set, "set");
14251 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14252         TOKEN_STRING_INITIALIZER
14253                 (struct cmd_macsec_offload_on_result,
14254                  macsec, "macsec");
14255 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14256         TOKEN_STRING_INITIALIZER
14257                 (struct cmd_macsec_offload_on_result,
14258                  offload, "offload");
14259 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14260         TOKEN_NUM_INITIALIZER
14261                 (struct cmd_macsec_offload_on_result,
14262                  port_id, UINT16);
14263 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14264         TOKEN_STRING_INITIALIZER
14265                 (struct cmd_macsec_offload_on_result,
14266                  on, "on");
14267 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_macsec_offload_on_result,
14270                  encrypt, "encrypt");
14271 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14272         TOKEN_STRING_INITIALIZER
14273                 (struct cmd_macsec_offload_on_result,
14274                  en_on_off, "on#off");
14275 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_macsec_offload_on_result,
14278                  replay_protect, "replay-protect");
14279 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_macsec_offload_on_result,
14282                  rp_on_off, "on#off");
14283
14284 static void
14285 cmd_set_macsec_offload_on_parsed(
14286         void *parsed_result,
14287         __rte_unused struct cmdline *cl,
14288         __rte_unused void *data)
14289 {
14290         struct cmd_macsec_offload_on_result *res = parsed_result;
14291         int ret = -ENOTSUP;
14292         portid_t port_id = res->port_id;
14293         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14294         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14295         struct rte_eth_dev_info dev_info;
14296
14297         if (port_id_is_invalid(port_id, ENABLED_WARN))
14298                 return;
14299         if (!port_is_stopped(port_id)) {
14300                 printf("Please stop port %d first\n", port_id);
14301                 return;
14302         }
14303
14304         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14305         if (ret != 0)
14306                 return;
14307
14308         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14309 #ifdef RTE_LIBRTE_IXGBE_PMD
14310                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14311 #endif
14312         }
14313         RTE_SET_USED(en);
14314         RTE_SET_USED(rp);
14315
14316         switch (ret) {
14317         case 0:
14318                 ports[port_id].dev_conf.txmode.offloads |=
14319                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14320                 cmd_reconfig_device_queue(port_id, 1, 1);
14321                 break;
14322         case -ENODEV:
14323                 printf("invalid port_id %d\n", port_id);
14324                 break;
14325         case -ENOTSUP:
14326                 printf("not supported on port %d\n", port_id);
14327                 break;
14328         default:
14329                 printf("programming error: (%s)\n", strerror(-ret));
14330         }
14331 }
14332
14333 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14334         .f = cmd_set_macsec_offload_on_parsed,
14335         .data = NULL,
14336         .help_str = "set macsec offload <port_id> on "
14337                 "encrypt on|off replay-protect on|off",
14338         .tokens = {
14339                 (void *)&cmd_macsec_offload_on_set,
14340                 (void *)&cmd_macsec_offload_on_macsec,
14341                 (void *)&cmd_macsec_offload_on_offload,
14342                 (void *)&cmd_macsec_offload_on_port_id,
14343                 (void *)&cmd_macsec_offload_on_on,
14344                 (void *)&cmd_macsec_offload_on_encrypt,
14345                 (void *)&cmd_macsec_offload_on_en_on_off,
14346                 (void *)&cmd_macsec_offload_on_replay_protect,
14347                 (void *)&cmd_macsec_offload_on_rp_on_off,
14348                 NULL,
14349         },
14350 };
14351
14352 /* Common result structure for MACsec offload disable */
14353 struct cmd_macsec_offload_off_result {
14354         cmdline_fixed_string_t set;
14355         cmdline_fixed_string_t macsec;
14356         cmdline_fixed_string_t offload;
14357         portid_t port_id;
14358         cmdline_fixed_string_t off;
14359 };
14360
14361 /* Common CLI fields for MACsec offload disable */
14362 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_macsec_offload_off_result,
14365                  set, "set");
14366 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14367         TOKEN_STRING_INITIALIZER
14368                 (struct cmd_macsec_offload_off_result,
14369                  macsec, "macsec");
14370 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14371         TOKEN_STRING_INITIALIZER
14372                 (struct cmd_macsec_offload_off_result,
14373                  offload, "offload");
14374 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14375         TOKEN_NUM_INITIALIZER
14376                 (struct cmd_macsec_offload_off_result,
14377                  port_id, UINT16);
14378 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_macsec_offload_off_result,
14381                  off, "off");
14382
14383 static void
14384 cmd_set_macsec_offload_off_parsed(
14385         void *parsed_result,
14386         __rte_unused struct cmdline *cl,
14387         __rte_unused void *data)
14388 {
14389         struct cmd_macsec_offload_off_result *res = parsed_result;
14390         int ret = -ENOTSUP;
14391         struct rte_eth_dev_info dev_info;
14392         portid_t port_id = res->port_id;
14393
14394         if (port_id_is_invalid(port_id, ENABLED_WARN))
14395                 return;
14396         if (!port_is_stopped(port_id)) {
14397                 printf("Please stop port %d first\n", port_id);
14398                 return;
14399         }
14400
14401         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14402         if (ret != 0)
14403                 return;
14404
14405         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14406 #ifdef RTE_LIBRTE_IXGBE_PMD
14407                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14408 #endif
14409         }
14410         switch (ret) {
14411         case 0:
14412                 ports[port_id].dev_conf.txmode.offloads &=
14413                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14414                 cmd_reconfig_device_queue(port_id, 1, 1);
14415                 break;
14416         case -ENODEV:
14417                 printf("invalid port_id %d\n", port_id);
14418                 break;
14419         case -ENOTSUP:
14420                 printf("not supported on port %d\n", port_id);
14421                 break;
14422         default:
14423                 printf("programming error: (%s)\n", strerror(-ret));
14424         }
14425 }
14426
14427 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14428         .f = cmd_set_macsec_offload_off_parsed,
14429         .data = NULL,
14430         .help_str = "set macsec offload <port_id> off",
14431         .tokens = {
14432                 (void *)&cmd_macsec_offload_off_set,
14433                 (void *)&cmd_macsec_offload_off_macsec,
14434                 (void *)&cmd_macsec_offload_off_offload,
14435                 (void *)&cmd_macsec_offload_off_port_id,
14436                 (void *)&cmd_macsec_offload_off_off,
14437                 NULL,
14438         },
14439 };
14440
14441 /* Common result structure for MACsec secure connection configure */
14442 struct cmd_macsec_sc_result {
14443         cmdline_fixed_string_t set;
14444         cmdline_fixed_string_t macsec;
14445         cmdline_fixed_string_t sc;
14446         cmdline_fixed_string_t tx_rx;
14447         portid_t port_id;
14448         struct rte_ether_addr mac;
14449         uint16_t pi;
14450 };
14451
14452 /* Common CLI fields for MACsec secure connection configure */
14453 cmdline_parse_token_string_t cmd_macsec_sc_set =
14454         TOKEN_STRING_INITIALIZER
14455                 (struct cmd_macsec_sc_result,
14456                  set, "set");
14457 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14458         TOKEN_STRING_INITIALIZER
14459                 (struct cmd_macsec_sc_result,
14460                  macsec, "macsec");
14461 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14462         TOKEN_STRING_INITIALIZER
14463                 (struct cmd_macsec_sc_result,
14464                  sc, "sc");
14465 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14466         TOKEN_STRING_INITIALIZER
14467                 (struct cmd_macsec_sc_result,
14468                  tx_rx, "tx#rx");
14469 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14470         TOKEN_NUM_INITIALIZER
14471                 (struct cmd_macsec_sc_result,
14472                  port_id, UINT16);
14473 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14474         TOKEN_ETHERADDR_INITIALIZER
14475                 (struct cmd_macsec_sc_result,
14476                  mac);
14477 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14478         TOKEN_NUM_INITIALIZER
14479                 (struct cmd_macsec_sc_result,
14480                  pi, UINT16);
14481
14482 static void
14483 cmd_set_macsec_sc_parsed(
14484         void *parsed_result,
14485         __rte_unused struct cmdline *cl,
14486         __rte_unused void *data)
14487 {
14488         struct cmd_macsec_sc_result *res = parsed_result;
14489         int ret = -ENOTSUP;
14490         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14491
14492 #ifdef RTE_LIBRTE_IXGBE_PMD
14493         ret = is_tx ?
14494                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14495                                 res->mac.addr_bytes) :
14496                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14497                                 res->mac.addr_bytes, res->pi);
14498 #endif
14499         RTE_SET_USED(is_tx);
14500
14501         switch (ret) {
14502         case 0:
14503                 break;
14504         case -ENODEV:
14505                 printf("invalid port_id %d\n", res->port_id);
14506                 break;
14507         case -ENOTSUP:
14508                 printf("not supported on port %d\n", res->port_id);
14509                 break;
14510         default:
14511                 printf("programming error: (%s)\n", strerror(-ret));
14512         }
14513 }
14514
14515 cmdline_parse_inst_t cmd_set_macsec_sc = {
14516         .f = cmd_set_macsec_sc_parsed,
14517         .data = NULL,
14518         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14519         .tokens = {
14520                 (void *)&cmd_macsec_sc_set,
14521                 (void *)&cmd_macsec_sc_macsec,
14522                 (void *)&cmd_macsec_sc_sc,
14523                 (void *)&cmd_macsec_sc_tx_rx,
14524                 (void *)&cmd_macsec_sc_port_id,
14525                 (void *)&cmd_macsec_sc_mac,
14526                 (void *)&cmd_macsec_sc_pi,
14527                 NULL,
14528         },
14529 };
14530
14531 /* Common result structure for MACsec secure connection configure */
14532 struct cmd_macsec_sa_result {
14533         cmdline_fixed_string_t set;
14534         cmdline_fixed_string_t macsec;
14535         cmdline_fixed_string_t sa;
14536         cmdline_fixed_string_t tx_rx;
14537         portid_t port_id;
14538         uint8_t idx;
14539         uint8_t an;
14540         uint32_t pn;
14541         cmdline_fixed_string_t key;
14542 };
14543
14544 /* Common CLI fields for MACsec secure connection configure */
14545 cmdline_parse_token_string_t cmd_macsec_sa_set =
14546         TOKEN_STRING_INITIALIZER
14547                 (struct cmd_macsec_sa_result,
14548                  set, "set");
14549 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14550         TOKEN_STRING_INITIALIZER
14551                 (struct cmd_macsec_sa_result,
14552                  macsec, "macsec");
14553 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14554         TOKEN_STRING_INITIALIZER
14555                 (struct cmd_macsec_sa_result,
14556                  sa, "sa");
14557 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14558         TOKEN_STRING_INITIALIZER
14559                 (struct cmd_macsec_sa_result,
14560                  tx_rx, "tx#rx");
14561 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14562         TOKEN_NUM_INITIALIZER
14563                 (struct cmd_macsec_sa_result,
14564                  port_id, UINT16);
14565 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14566         TOKEN_NUM_INITIALIZER
14567                 (struct cmd_macsec_sa_result,
14568                  idx, UINT8);
14569 cmdline_parse_token_num_t cmd_macsec_sa_an =
14570         TOKEN_NUM_INITIALIZER
14571                 (struct cmd_macsec_sa_result,
14572                  an, UINT8);
14573 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14574         TOKEN_NUM_INITIALIZER
14575                 (struct cmd_macsec_sa_result,
14576                  pn, UINT32);
14577 cmdline_parse_token_string_t cmd_macsec_sa_key =
14578         TOKEN_STRING_INITIALIZER
14579                 (struct cmd_macsec_sa_result,
14580                  key, NULL);
14581
14582 static void
14583 cmd_set_macsec_sa_parsed(
14584         void *parsed_result,
14585         __rte_unused struct cmdline *cl,
14586         __rte_unused void *data)
14587 {
14588         struct cmd_macsec_sa_result *res = parsed_result;
14589         int ret = -ENOTSUP;
14590         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14591         uint8_t key[16] = { 0 };
14592         uint8_t xdgt0;
14593         uint8_t xdgt1;
14594         int key_len;
14595         int i;
14596
14597         key_len = strlen(res->key) / 2;
14598         if (key_len > 16)
14599                 key_len = 16;
14600
14601         for (i = 0; i < key_len; i++) {
14602                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14603                 if (xdgt0 == 0xFF)
14604                         return;
14605                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14606                 if (xdgt1 == 0xFF)
14607                         return;
14608                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14609         }
14610
14611 #ifdef RTE_LIBRTE_IXGBE_PMD
14612         ret = is_tx ?
14613                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14614                         res->idx, res->an, res->pn, key) :
14615                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14616                         res->idx, res->an, res->pn, key);
14617 #endif
14618         RTE_SET_USED(is_tx);
14619         RTE_SET_USED(key);
14620
14621         switch (ret) {
14622         case 0:
14623                 break;
14624         case -EINVAL:
14625                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14626                 break;
14627         case -ENODEV:
14628                 printf("invalid port_id %d\n", res->port_id);
14629                 break;
14630         case -ENOTSUP:
14631                 printf("not supported on port %d\n", res->port_id);
14632                 break;
14633         default:
14634                 printf("programming error: (%s)\n", strerror(-ret));
14635         }
14636 }
14637
14638 cmdline_parse_inst_t cmd_set_macsec_sa = {
14639         .f = cmd_set_macsec_sa_parsed,
14640         .data = NULL,
14641         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14642         .tokens = {
14643                 (void *)&cmd_macsec_sa_set,
14644                 (void *)&cmd_macsec_sa_macsec,
14645                 (void *)&cmd_macsec_sa_sa,
14646                 (void *)&cmd_macsec_sa_tx_rx,
14647                 (void *)&cmd_macsec_sa_port_id,
14648                 (void *)&cmd_macsec_sa_idx,
14649                 (void *)&cmd_macsec_sa_an,
14650                 (void *)&cmd_macsec_sa_pn,
14651                 (void *)&cmd_macsec_sa_key,
14652                 NULL,
14653         },
14654 };
14655
14656 /* VF unicast promiscuous mode configuration */
14657
14658 /* Common result structure for VF unicast promiscuous mode */
14659 struct cmd_vf_promisc_result {
14660         cmdline_fixed_string_t set;
14661         cmdline_fixed_string_t vf;
14662         cmdline_fixed_string_t promisc;
14663         portid_t port_id;
14664         uint32_t vf_id;
14665         cmdline_fixed_string_t on_off;
14666 };
14667
14668 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14669 cmdline_parse_token_string_t cmd_vf_promisc_set =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_vf_promisc_result,
14672                  set, "set");
14673 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_vf_promisc_result,
14676                  vf, "vf");
14677 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14678         TOKEN_STRING_INITIALIZER
14679                 (struct cmd_vf_promisc_result,
14680                  promisc, "promisc");
14681 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14682         TOKEN_NUM_INITIALIZER
14683                 (struct cmd_vf_promisc_result,
14684                  port_id, UINT16);
14685 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14686         TOKEN_NUM_INITIALIZER
14687                 (struct cmd_vf_promisc_result,
14688                  vf_id, UINT32);
14689 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14690         TOKEN_STRING_INITIALIZER
14691                 (struct cmd_vf_promisc_result,
14692                  on_off, "on#off");
14693
14694 static void
14695 cmd_set_vf_promisc_parsed(
14696         void *parsed_result,
14697         __rte_unused struct cmdline *cl,
14698         __rte_unused void *data)
14699 {
14700         struct cmd_vf_promisc_result *res = parsed_result;
14701         int ret = -ENOTSUP;
14702
14703         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14704
14705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14706                 return;
14707
14708 #ifdef RTE_LIBRTE_I40E_PMD
14709         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14710                                                   res->vf_id, is_on);
14711 #endif
14712
14713         switch (ret) {
14714         case 0:
14715                 break;
14716         case -EINVAL:
14717                 printf("invalid vf_id %d\n", res->vf_id);
14718                 break;
14719         case -ENODEV:
14720                 printf("invalid port_id %d\n", res->port_id);
14721                 break;
14722         case -ENOTSUP:
14723                 printf("function not implemented\n");
14724                 break;
14725         default:
14726                 printf("programming error: (%s)\n", strerror(-ret));
14727         }
14728 }
14729
14730 cmdline_parse_inst_t cmd_set_vf_promisc = {
14731         .f = cmd_set_vf_promisc_parsed,
14732         .data = NULL,
14733         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14734                 "Set unicast promiscuous mode for a VF from the PF",
14735         .tokens = {
14736                 (void *)&cmd_vf_promisc_set,
14737                 (void *)&cmd_vf_promisc_vf,
14738                 (void *)&cmd_vf_promisc_promisc,
14739                 (void *)&cmd_vf_promisc_port_id,
14740                 (void *)&cmd_vf_promisc_vf_id,
14741                 (void *)&cmd_vf_promisc_on_off,
14742                 NULL,
14743         },
14744 };
14745
14746 /* VF multicast promiscuous mode configuration */
14747
14748 /* Common result structure for VF multicast promiscuous mode */
14749 struct cmd_vf_allmulti_result {
14750         cmdline_fixed_string_t set;
14751         cmdline_fixed_string_t vf;
14752         cmdline_fixed_string_t allmulti;
14753         portid_t port_id;
14754         uint32_t vf_id;
14755         cmdline_fixed_string_t on_off;
14756 };
14757
14758 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14759 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14760         TOKEN_STRING_INITIALIZER
14761                 (struct cmd_vf_allmulti_result,
14762                  set, "set");
14763 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14764         TOKEN_STRING_INITIALIZER
14765                 (struct cmd_vf_allmulti_result,
14766                  vf, "vf");
14767 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_vf_allmulti_result,
14770                  allmulti, "allmulti");
14771 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14772         TOKEN_NUM_INITIALIZER
14773                 (struct cmd_vf_allmulti_result,
14774                  port_id, UINT16);
14775 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14776         TOKEN_NUM_INITIALIZER
14777                 (struct cmd_vf_allmulti_result,
14778                  vf_id, UINT32);
14779 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14780         TOKEN_STRING_INITIALIZER
14781                 (struct cmd_vf_allmulti_result,
14782                  on_off, "on#off");
14783
14784 static void
14785 cmd_set_vf_allmulti_parsed(
14786         void *parsed_result,
14787         __rte_unused struct cmdline *cl,
14788         __rte_unused void *data)
14789 {
14790         struct cmd_vf_allmulti_result *res = parsed_result;
14791         int ret = -ENOTSUP;
14792
14793         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14794
14795         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14796                 return;
14797
14798 #ifdef RTE_LIBRTE_I40E_PMD
14799         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14800                                                     res->vf_id, is_on);
14801 #endif
14802
14803         switch (ret) {
14804         case 0:
14805                 break;
14806         case -EINVAL:
14807                 printf("invalid vf_id %d\n", res->vf_id);
14808                 break;
14809         case -ENODEV:
14810                 printf("invalid port_id %d\n", res->port_id);
14811                 break;
14812         case -ENOTSUP:
14813                 printf("function not implemented\n");
14814                 break;
14815         default:
14816                 printf("programming error: (%s)\n", strerror(-ret));
14817         }
14818 }
14819
14820 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14821         .f = cmd_set_vf_allmulti_parsed,
14822         .data = NULL,
14823         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14824                 "Set multicast promiscuous mode for a VF from the PF",
14825         .tokens = {
14826                 (void *)&cmd_vf_allmulti_set,
14827                 (void *)&cmd_vf_allmulti_vf,
14828                 (void *)&cmd_vf_allmulti_allmulti,
14829                 (void *)&cmd_vf_allmulti_port_id,
14830                 (void *)&cmd_vf_allmulti_vf_id,
14831                 (void *)&cmd_vf_allmulti_on_off,
14832                 NULL,
14833         },
14834 };
14835
14836 /* vf broadcast mode configuration */
14837
14838 /* Common result structure for vf broadcast */
14839 struct cmd_set_vf_broadcast_result {
14840         cmdline_fixed_string_t set;
14841         cmdline_fixed_string_t vf;
14842         cmdline_fixed_string_t broadcast;
14843         portid_t port_id;
14844         uint16_t vf_id;
14845         cmdline_fixed_string_t on_off;
14846 };
14847
14848 /* Common CLI fields for vf broadcast enable disable */
14849 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14850         TOKEN_STRING_INITIALIZER
14851                 (struct cmd_set_vf_broadcast_result,
14852                  set, "set");
14853 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14854         TOKEN_STRING_INITIALIZER
14855                 (struct cmd_set_vf_broadcast_result,
14856                  vf, "vf");
14857 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_set_vf_broadcast_result,
14860                  broadcast, "broadcast");
14861 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14862         TOKEN_NUM_INITIALIZER
14863                 (struct cmd_set_vf_broadcast_result,
14864                  port_id, UINT16);
14865 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14866         TOKEN_NUM_INITIALIZER
14867                 (struct cmd_set_vf_broadcast_result,
14868                  vf_id, UINT16);
14869 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_set_vf_broadcast_result,
14872                  on_off, "on#off");
14873
14874 static void
14875 cmd_set_vf_broadcast_parsed(
14876         void *parsed_result,
14877         __rte_unused struct cmdline *cl,
14878         __rte_unused void *data)
14879 {
14880         struct cmd_set_vf_broadcast_result *res = parsed_result;
14881         int ret = -ENOTSUP;
14882
14883         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14884
14885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14886                 return;
14887
14888 #ifdef RTE_LIBRTE_I40E_PMD
14889         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14890                                             res->vf_id, is_on);
14891 #endif
14892
14893         switch (ret) {
14894         case 0:
14895                 break;
14896         case -EINVAL:
14897                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14898                 break;
14899         case -ENODEV:
14900                 printf("invalid port_id %d\n", res->port_id);
14901                 break;
14902         case -ENOTSUP:
14903                 printf("function not implemented\n");
14904                 break;
14905         default:
14906                 printf("programming error: (%s)\n", strerror(-ret));
14907         }
14908 }
14909
14910 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14911         .f = cmd_set_vf_broadcast_parsed,
14912         .data = NULL,
14913         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14914         .tokens = {
14915                 (void *)&cmd_set_vf_broadcast_set,
14916                 (void *)&cmd_set_vf_broadcast_vf,
14917                 (void *)&cmd_set_vf_broadcast_broadcast,
14918                 (void *)&cmd_set_vf_broadcast_port_id,
14919                 (void *)&cmd_set_vf_broadcast_vf_id,
14920                 (void *)&cmd_set_vf_broadcast_on_off,
14921                 NULL,
14922         },
14923 };
14924
14925 /* vf vlan tag configuration */
14926
14927 /* Common result structure for vf vlan tag */
14928 struct cmd_set_vf_vlan_tag_result {
14929         cmdline_fixed_string_t set;
14930         cmdline_fixed_string_t vf;
14931         cmdline_fixed_string_t vlan;
14932         cmdline_fixed_string_t tag;
14933         portid_t port_id;
14934         uint16_t vf_id;
14935         cmdline_fixed_string_t on_off;
14936 };
14937
14938 /* Common CLI fields for vf vlan tag enable disable */
14939 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14940         TOKEN_STRING_INITIALIZER
14941                 (struct cmd_set_vf_vlan_tag_result,
14942                  set, "set");
14943 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14944         TOKEN_STRING_INITIALIZER
14945                 (struct cmd_set_vf_vlan_tag_result,
14946                  vf, "vf");
14947 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14948         TOKEN_STRING_INITIALIZER
14949                 (struct cmd_set_vf_vlan_tag_result,
14950                  vlan, "vlan");
14951 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14952         TOKEN_STRING_INITIALIZER
14953                 (struct cmd_set_vf_vlan_tag_result,
14954                  tag, "tag");
14955 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14956         TOKEN_NUM_INITIALIZER
14957                 (struct cmd_set_vf_vlan_tag_result,
14958                  port_id, UINT16);
14959 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14960         TOKEN_NUM_INITIALIZER
14961                 (struct cmd_set_vf_vlan_tag_result,
14962                  vf_id, UINT16);
14963 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_set_vf_vlan_tag_result,
14966                  on_off, "on#off");
14967
14968 static void
14969 cmd_set_vf_vlan_tag_parsed(
14970         void *parsed_result,
14971         __rte_unused struct cmdline *cl,
14972         __rte_unused void *data)
14973 {
14974         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14975         int ret = -ENOTSUP;
14976
14977         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14978
14979         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14980                 return;
14981
14982 #ifdef RTE_LIBRTE_I40E_PMD
14983         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14984                                            res->vf_id, is_on);
14985 #endif
14986
14987         switch (ret) {
14988         case 0:
14989                 break;
14990         case -EINVAL:
14991                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14992                 break;
14993         case -ENODEV:
14994                 printf("invalid port_id %d\n", res->port_id);
14995                 break;
14996         case -ENOTSUP:
14997                 printf("function not implemented\n");
14998                 break;
14999         default:
15000                 printf("programming error: (%s)\n", strerror(-ret));
15001         }
15002 }
15003
15004 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15005         .f = cmd_set_vf_vlan_tag_parsed,
15006         .data = NULL,
15007         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15008         .tokens = {
15009                 (void *)&cmd_set_vf_vlan_tag_set,
15010                 (void *)&cmd_set_vf_vlan_tag_vf,
15011                 (void *)&cmd_set_vf_vlan_tag_vlan,
15012                 (void *)&cmd_set_vf_vlan_tag_tag,
15013                 (void *)&cmd_set_vf_vlan_tag_port_id,
15014                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15015                 (void *)&cmd_set_vf_vlan_tag_on_off,
15016                 NULL,
15017         },
15018 };
15019
15020 /* Common definition of VF and TC TX bandwidth configuration */
15021 struct cmd_vf_tc_bw_result {
15022         cmdline_fixed_string_t set;
15023         cmdline_fixed_string_t vf;
15024         cmdline_fixed_string_t tc;
15025         cmdline_fixed_string_t tx;
15026         cmdline_fixed_string_t min_bw;
15027         cmdline_fixed_string_t max_bw;
15028         cmdline_fixed_string_t strict_link_prio;
15029         portid_t port_id;
15030         uint16_t vf_id;
15031         uint8_t tc_no;
15032         uint32_t bw;
15033         cmdline_fixed_string_t bw_list;
15034         uint8_t tc_map;
15035 };
15036
15037 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15038         TOKEN_STRING_INITIALIZER
15039                 (struct cmd_vf_tc_bw_result,
15040                  set, "set");
15041 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15042         TOKEN_STRING_INITIALIZER
15043                 (struct cmd_vf_tc_bw_result,
15044                  vf, "vf");
15045 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15046         TOKEN_STRING_INITIALIZER
15047                 (struct cmd_vf_tc_bw_result,
15048                  tc, "tc");
15049 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15050         TOKEN_STRING_INITIALIZER
15051                 (struct cmd_vf_tc_bw_result,
15052                  tx, "tx");
15053 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15054         TOKEN_STRING_INITIALIZER
15055                 (struct cmd_vf_tc_bw_result,
15056                  strict_link_prio, "strict-link-priority");
15057 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15058         TOKEN_STRING_INITIALIZER
15059                 (struct cmd_vf_tc_bw_result,
15060                  min_bw, "min-bandwidth");
15061 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15062         TOKEN_STRING_INITIALIZER
15063                 (struct cmd_vf_tc_bw_result,
15064                  max_bw, "max-bandwidth");
15065 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15066         TOKEN_NUM_INITIALIZER
15067                 (struct cmd_vf_tc_bw_result,
15068                  port_id, UINT16);
15069 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15070         TOKEN_NUM_INITIALIZER
15071                 (struct cmd_vf_tc_bw_result,
15072                  vf_id, UINT16);
15073 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15074         TOKEN_NUM_INITIALIZER
15075                 (struct cmd_vf_tc_bw_result,
15076                  tc_no, UINT8);
15077 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15078         TOKEN_NUM_INITIALIZER
15079                 (struct cmd_vf_tc_bw_result,
15080                  bw, UINT32);
15081 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15082         TOKEN_STRING_INITIALIZER
15083                 (struct cmd_vf_tc_bw_result,
15084                  bw_list, NULL);
15085 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15086         TOKEN_NUM_INITIALIZER
15087                 (struct cmd_vf_tc_bw_result,
15088                  tc_map, UINT8);
15089
15090 /* VF max bandwidth setting */
15091 static void
15092 cmd_vf_max_bw_parsed(
15093         void *parsed_result,
15094         __rte_unused struct cmdline *cl,
15095         __rte_unused void *data)
15096 {
15097         struct cmd_vf_tc_bw_result *res = parsed_result;
15098         int ret = -ENOTSUP;
15099
15100         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15101                 return;
15102
15103 #ifdef RTE_LIBRTE_I40E_PMD
15104         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15105                                          res->vf_id, res->bw);
15106 #endif
15107
15108         switch (ret) {
15109         case 0:
15110                 break;
15111         case -EINVAL:
15112                 printf("invalid vf_id %d or bandwidth %d\n",
15113                        res->vf_id, res->bw);
15114                 break;
15115         case -ENODEV:
15116                 printf("invalid port_id %d\n", res->port_id);
15117                 break;
15118         case -ENOTSUP:
15119                 printf("function not implemented\n");
15120                 break;
15121         default:
15122                 printf("programming error: (%s)\n", strerror(-ret));
15123         }
15124 }
15125
15126 cmdline_parse_inst_t cmd_vf_max_bw = {
15127         .f = cmd_vf_max_bw_parsed,
15128         .data = NULL,
15129         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15130         .tokens = {
15131                 (void *)&cmd_vf_tc_bw_set,
15132                 (void *)&cmd_vf_tc_bw_vf,
15133                 (void *)&cmd_vf_tc_bw_tx,
15134                 (void *)&cmd_vf_tc_bw_max_bw,
15135                 (void *)&cmd_vf_tc_bw_port_id,
15136                 (void *)&cmd_vf_tc_bw_vf_id,
15137                 (void *)&cmd_vf_tc_bw_bw,
15138                 NULL,
15139         },
15140 };
15141
15142 static int
15143 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15144                            uint8_t *tc_num,
15145                            char *str)
15146 {
15147         uint32_t size;
15148         const char *p, *p0 = str;
15149         char s[256];
15150         char *end;
15151         char *str_fld[16];
15152         uint16_t i;
15153         int ret;
15154
15155         p = strchr(p0, '(');
15156         if (p == NULL) {
15157                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15158                 return -1;
15159         }
15160         p++;
15161         p0 = strchr(p, ')');
15162         if (p0 == NULL) {
15163                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15164                 return -1;
15165         }
15166         size = p0 - p;
15167         if (size >= sizeof(s)) {
15168                 printf("The string size exceeds the internal buffer size\n");
15169                 return -1;
15170         }
15171         snprintf(s, sizeof(s), "%.*s", size, p);
15172         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15173         if (ret <= 0) {
15174                 printf("Failed to get the bandwidth list. ");
15175                 return -1;
15176         }
15177         *tc_num = ret;
15178         for (i = 0; i < ret; i++)
15179                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15180
15181         return 0;
15182 }
15183
15184 /* TC min bandwidth setting */
15185 static void
15186 cmd_vf_tc_min_bw_parsed(
15187         void *parsed_result,
15188         __rte_unused struct cmdline *cl,
15189         __rte_unused void *data)
15190 {
15191         struct cmd_vf_tc_bw_result *res = parsed_result;
15192         uint8_t tc_num;
15193         uint8_t bw[16];
15194         int ret = -ENOTSUP;
15195
15196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15197                 return;
15198
15199         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15200         if (ret)
15201                 return;
15202
15203 #ifdef RTE_LIBRTE_I40E_PMD
15204         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15205                                               tc_num, bw);
15206 #endif
15207
15208         switch (ret) {
15209         case 0:
15210                 break;
15211         case -EINVAL:
15212                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15213                 break;
15214         case -ENODEV:
15215                 printf("invalid port_id %d\n", res->port_id);
15216                 break;
15217         case -ENOTSUP:
15218                 printf("function not implemented\n");
15219                 break;
15220         default:
15221                 printf("programming error: (%s)\n", strerror(-ret));
15222         }
15223 }
15224
15225 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15226         .f = cmd_vf_tc_min_bw_parsed,
15227         .data = NULL,
15228         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15229                     " <bw1, bw2, ...>",
15230         .tokens = {
15231                 (void *)&cmd_vf_tc_bw_set,
15232                 (void *)&cmd_vf_tc_bw_vf,
15233                 (void *)&cmd_vf_tc_bw_tc,
15234                 (void *)&cmd_vf_tc_bw_tx,
15235                 (void *)&cmd_vf_tc_bw_min_bw,
15236                 (void *)&cmd_vf_tc_bw_port_id,
15237                 (void *)&cmd_vf_tc_bw_vf_id,
15238                 (void *)&cmd_vf_tc_bw_bw_list,
15239                 NULL,
15240         },
15241 };
15242
15243 static void
15244 cmd_tc_min_bw_parsed(
15245         void *parsed_result,
15246         __rte_unused struct cmdline *cl,
15247         __rte_unused void *data)
15248 {
15249         struct cmd_vf_tc_bw_result *res = parsed_result;
15250         struct rte_port *port;
15251         uint8_t tc_num;
15252         uint8_t bw[16];
15253         int ret = -ENOTSUP;
15254
15255         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15256                 return;
15257
15258         port = &ports[res->port_id];
15259         /** Check if the port is not started **/
15260         if (port->port_status != RTE_PORT_STOPPED) {
15261                 printf("Please stop port %d first\n", res->port_id);
15262                 return;
15263         }
15264
15265         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15266         if (ret)
15267                 return;
15268
15269 #ifdef RTE_LIBRTE_IXGBE_PMD
15270         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15271 #endif
15272
15273         switch (ret) {
15274         case 0:
15275                 break;
15276         case -EINVAL:
15277                 printf("invalid bandwidth\n");
15278                 break;
15279         case -ENODEV:
15280                 printf("invalid port_id %d\n", res->port_id);
15281                 break;
15282         case -ENOTSUP:
15283                 printf("function not implemented\n");
15284                 break;
15285         default:
15286                 printf("programming error: (%s)\n", strerror(-ret));
15287         }
15288 }
15289
15290 cmdline_parse_inst_t cmd_tc_min_bw = {
15291         .f = cmd_tc_min_bw_parsed,
15292         .data = NULL,
15293         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15294         .tokens = {
15295                 (void *)&cmd_vf_tc_bw_set,
15296                 (void *)&cmd_vf_tc_bw_tc,
15297                 (void *)&cmd_vf_tc_bw_tx,
15298                 (void *)&cmd_vf_tc_bw_min_bw,
15299                 (void *)&cmd_vf_tc_bw_port_id,
15300                 (void *)&cmd_vf_tc_bw_bw_list,
15301                 NULL,
15302         },
15303 };
15304
15305 /* TC max bandwidth setting */
15306 static void
15307 cmd_vf_tc_max_bw_parsed(
15308         void *parsed_result,
15309         __rte_unused struct cmdline *cl,
15310         __rte_unused void *data)
15311 {
15312         struct cmd_vf_tc_bw_result *res = parsed_result;
15313         int ret = -ENOTSUP;
15314
15315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15316                 return;
15317
15318 #ifdef RTE_LIBRTE_I40E_PMD
15319         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15320                                             res->tc_no, res->bw);
15321 #endif
15322
15323         switch (ret) {
15324         case 0:
15325                 break;
15326         case -EINVAL:
15327                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15328                        res->vf_id, res->tc_no, res->bw);
15329                 break;
15330         case -ENODEV:
15331                 printf("invalid port_id %d\n", res->port_id);
15332                 break;
15333         case -ENOTSUP:
15334                 printf("function not implemented\n");
15335                 break;
15336         default:
15337                 printf("programming error: (%s)\n", strerror(-ret));
15338         }
15339 }
15340
15341 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15342         .f = cmd_vf_tc_max_bw_parsed,
15343         .data = NULL,
15344         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15345                     " <bandwidth>",
15346         .tokens = {
15347                 (void *)&cmd_vf_tc_bw_set,
15348                 (void *)&cmd_vf_tc_bw_vf,
15349                 (void *)&cmd_vf_tc_bw_tc,
15350                 (void *)&cmd_vf_tc_bw_tx,
15351                 (void *)&cmd_vf_tc_bw_max_bw,
15352                 (void *)&cmd_vf_tc_bw_port_id,
15353                 (void *)&cmd_vf_tc_bw_vf_id,
15354                 (void *)&cmd_vf_tc_bw_tc_no,
15355                 (void *)&cmd_vf_tc_bw_bw,
15356                 NULL,
15357         },
15358 };
15359
15360
15361 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15362
15363 /* *** Set Port default Traffic Management Hierarchy *** */
15364 struct cmd_set_port_tm_hierarchy_default_result {
15365         cmdline_fixed_string_t set;
15366         cmdline_fixed_string_t port;
15367         cmdline_fixed_string_t tm;
15368         cmdline_fixed_string_t hierarchy;
15369         cmdline_fixed_string_t def;
15370         portid_t port_id;
15371 };
15372
15373 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15374         TOKEN_STRING_INITIALIZER(
15375                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15376 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15377         TOKEN_STRING_INITIALIZER(
15378                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15379 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15380         TOKEN_STRING_INITIALIZER(
15381                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15382 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15383         TOKEN_STRING_INITIALIZER(
15384                 struct cmd_set_port_tm_hierarchy_default_result,
15385                         hierarchy, "hierarchy");
15386 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15387         TOKEN_STRING_INITIALIZER(
15388                 struct cmd_set_port_tm_hierarchy_default_result,
15389                         def, "default");
15390 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15391         TOKEN_NUM_INITIALIZER(
15392                 struct cmd_set_port_tm_hierarchy_default_result,
15393                         port_id, UINT16);
15394
15395 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15396         __rte_unused struct cmdline *cl,
15397         __rte_unused void *data)
15398 {
15399         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15400         struct rte_port *p;
15401         portid_t port_id = res->port_id;
15402
15403         if (port_id_is_invalid(port_id, ENABLED_WARN))
15404                 return;
15405
15406         p = &ports[port_id];
15407
15408         /* Forward mode: tm */
15409         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15410                 printf("  softnicfwd mode not enabled(error)\n");
15411                 return;
15412         }
15413
15414         /* Set the default tm hierarchy */
15415         p->softport.default_tm_hierarchy_enable = 1;
15416 }
15417
15418 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15419         .f = cmd_set_port_tm_hierarchy_default_parsed,
15420         .data = NULL,
15421         .help_str = "set port tm hierarchy default <port_id>",
15422         .tokens = {
15423                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15424                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15425                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15426                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15427                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15428                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15429                 NULL,
15430         },
15431 };
15432 #endif
15433
15434 /** Set VXLAN encapsulation details */
15435 struct cmd_set_vxlan_result {
15436         cmdline_fixed_string_t set;
15437         cmdline_fixed_string_t vxlan;
15438         cmdline_fixed_string_t pos_token;
15439         cmdline_fixed_string_t ip_version;
15440         uint32_t vlan_present:1;
15441         uint32_t vni;
15442         uint16_t udp_src;
15443         uint16_t udp_dst;
15444         cmdline_ipaddr_t ip_src;
15445         cmdline_ipaddr_t ip_dst;
15446         uint16_t tci;
15447         uint8_t tos;
15448         uint8_t ttl;
15449         struct rte_ether_addr eth_src;
15450         struct rte_ether_addr eth_dst;
15451 };
15452
15453 cmdline_parse_token_string_t cmd_set_vxlan_set =
15454         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15455 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15457 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15459                                  "vxlan-tos-ttl");
15460 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15462                                  "vxlan-with-vlan");
15463 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15464         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15465                                  "ip-version");
15466 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15467         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15468                                  "ipv4#ipv6");
15469 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15470         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15471                                  "vni");
15472 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15473         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15474 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15475         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15476                                  "udp-src");
15477 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15478         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15479 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15480         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15481                                  "udp-dst");
15482 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15483         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15484 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15485         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15486                                  "ip-tos");
15487 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15488         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15489 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15490         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15491                                  "ip-ttl");
15492 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15493         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15494 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15495         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15496                                  "ip-src");
15497 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15498         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15499 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15500         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15501                                  "ip-dst");
15502 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15503         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15504 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15505         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15506                                  "vlan-tci");
15507 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15508         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15509 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15510         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15511                                  "eth-src");
15512 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15513         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15514 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15515         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15516                                  "eth-dst");
15517 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15518         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15519
15520 static void cmd_set_vxlan_parsed(void *parsed_result,
15521         __rte_unused struct cmdline *cl,
15522         __rte_unused void *data)
15523 {
15524         struct cmd_set_vxlan_result *res = parsed_result;
15525         union {
15526                 uint32_t vxlan_id;
15527                 uint8_t vni[4];
15528         } id = {
15529                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15530         };
15531
15532         vxlan_encap_conf.select_tos_ttl = 0;
15533         if (strcmp(res->vxlan, "vxlan") == 0)
15534                 vxlan_encap_conf.select_vlan = 0;
15535         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15536                 vxlan_encap_conf.select_vlan = 1;
15537         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15538                 vxlan_encap_conf.select_vlan = 0;
15539                 vxlan_encap_conf.select_tos_ttl = 1;
15540         }
15541         if (strcmp(res->ip_version, "ipv4") == 0)
15542                 vxlan_encap_conf.select_ipv4 = 1;
15543         else if (strcmp(res->ip_version, "ipv6") == 0)
15544                 vxlan_encap_conf.select_ipv4 = 0;
15545         else
15546                 return;
15547         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15548         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15549         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15550         vxlan_encap_conf.ip_tos = res->tos;
15551         vxlan_encap_conf.ip_ttl = res->ttl;
15552         if (vxlan_encap_conf.select_ipv4) {
15553                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15554                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15555         } else {
15556                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15557                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15558         }
15559         if (vxlan_encap_conf.select_vlan)
15560                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15561         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15562                    RTE_ETHER_ADDR_LEN);
15563         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15564                    RTE_ETHER_ADDR_LEN);
15565 }
15566
15567 cmdline_parse_inst_t cmd_set_vxlan = {
15568         .f = cmd_set_vxlan_parsed,
15569         .data = NULL,
15570         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15571                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15572                 " eth-src <eth-src> eth-dst <eth-dst>",
15573         .tokens = {
15574                 (void *)&cmd_set_vxlan_set,
15575                 (void *)&cmd_set_vxlan_vxlan,
15576                 (void *)&cmd_set_vxlan_ip_version,
15577                 (void *)&cmd_set_vxlan_ip_version_value,
15578                 (void *)&cmd_set_vxlan_vni,
15579                 (void *)&cmd_set_vxlan_vni_value,
15580                 (void *)&cmd_set_vxlan_udp_src,
15581                 (void *)&cmd_set_vxlan_udp_src_value,
15582                 (void *)&cmd_set_vxlan_udp_dst,
15583                 (void *)&cmd_set_vxlan_udp_dst_value,
15584                 (void *)&cmd_set_vxlan_ip_src,
15585                 (void *)&cmd_set_vxlan_ip_src_value,
15586                 (void *)&cmd_set_vxlan_ip_dst,
15587                 (void *)&cmd_set_vxlan_ip_dst_value,
15588                 (void *)&cmd_set_vxlan_eth_src,
15589                 (void *)&cmd_set_vxlan_eth_src_value,
15590                 (void *)&cmd_set_vxlan_eth_dst,
15591                 (void *)&cmd_set_vxlan_eth_dst_value,
15592                 NULL,
15593         },
15594 };
15595
15596 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15597         .f = cmd_set_vxlan_parsed,
15598         .data = NULL,
15599         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15600                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15601                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15602                 " eth-dst <eth-dst>",
15603         .tokens = {
15604                 (void *)&cmd_set_vxlan_set,
15605                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15606                 (void *)&cmd_set_vxlan_ip_version,
15607                 (void *)&cmd_set_vxlan_ip_version_value,
15608                 (void *)&cmd_set_vxlan_vni,
15609                 (void *)&cmd_set_vxlan_vni_value,
15610                 (void *)&cmd_set_vxlan_udp_src,
15611                 (void *)&cmd_set_vxlan_udp_src_value,
15612                 (void *)&cmd_set_vxlan_udp_dst,
15613                 (void *)&cmd_set_vxlan_udp_dst_value,
15614                 (void *)&cmd_set_vxlan_ip_tos,
15615                 (void *)&cmd_set_vxlan_ip_tos_value,
15616                 (void *)&cmd_set_vxlan_ip_ttl,
15617                 (void *)&cmd_set_vxlan_ip_ttl_value,
15618                 (void *)&cmd_set_vxlan_ip_src,
15619                 (void *)&cmd_set_vxlan_ip_src_value,
15620                 (void *)&cmd_set_vxlan_ip_dst,
15621                 (void *)&cmd_set_vxlan_ip_dst_value,
15622                 (void *)&cmd_set_vxlan_eth_src,
15623                 (void *)&cmd_set_vxlan_eth_src_value,
15624                 (void *)&cmd_set_vxlan_eth_dst,
15625                 (void *)&cmd_set_vxlan_eth_dst_value,
15626                 NULL,
15627         },
15628 };
15629
15630 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15631         .f = cmd_set_vxlan_parsed,
15632         .data = NULL,
15633         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15634                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15635                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15636                 " <eth-dst>",
15637         .tokens = {
15638                 (void *)&cmd_set_vxlan_set,
15639                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15640                 (void *)&cmd_set_vxlan_ip_version,
15641                 (void *)&cmd_set_vxlan_ip_version_value,
15642                 (void *)&cmd_set_vxlan_vni,
15643                 (void *)&cmd_set_vxlan_vni_value,
15644                 (void *)&cmd_set_vxlan_udp_src,
15645                 (void *)&cmd_set_vxlan_udp_src_value,
15646                 (void *)&cmd_set_vxlan_udp_dst,
15647                 (void *)&cmd_set_vxlan_udp_dst_value,
15648                 (void *)&cmd_set_vxlan_ip_src,
15649                 (void *)&cmd_set_vxlan_ip_src_value,
15650                 (void *)&cmd_set_vxlan_ip_dst,
15651                 (void *)&cmd_set_vxlan_ip_dst_value,
15652                 (void *)&cmd_set_vxlan_vlan,
15653                 (void *)&cmd_set_vxlan_vlan_value,
15654                 (void *)&cmd_set_vxlan_eth_src,
15655                 (void *)&cmd_set_vxlan_eth_src_value,
15656                 (void *)&cmd_set_vxlan_eth_dst,
15657                 (void *)&cmd_set_vxlan_eth_dst_value,
15658                 NULL,
15659         },
15660 };
15661
15662 /** Set NVGRE encapsulation details */
15663 struct cmd_set_nvgre_result {
15664         cmdline_fixed_string_t set;
15665         cmdline_fixed_string_t nvgre;
15666         cmdline_fixed_string_t pos_token;
15667         cmdline_fixed_string_t ip_version;
15668         uint32_t tni;
15669         cmdline_ipaddr_t ip_src;
15670         cmdline_ipaddr_t ip_dst;
15671         uint16_t tci;
15672         struct rte_ether_addr eth_src;
15673         struct rte_ether_addr eth_dst;
15674 };
15675
15676 cmdline_parse_token_string_t cmd_set_nvgre_set =
15677         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15678 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15679         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15680 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15681         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15682                                  "nvgre-with-vlan");
15683 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15684         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15685                                  "ip-version");
15686 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15687         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15688                                  "ipv4#ipv6");
15689 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15690         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15691                                  "tni");
15692 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15693         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15694 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15695         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15696                                  "ip-src");
15697 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15698         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15699 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15700         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15701                                  "ip-dst");
15702 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15703         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15704 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15705         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15706                                  "vlan-tci");
15707 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15708         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15709 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15710         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15711                                  "eth-src");
15712 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15713         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15714 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15715         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15716                                  "eth-dst");
15717 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15718         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15719
15720 static void cmd_set_nvgre_parsed(void *parsed_result,
15721         __rte_unused struct cmdline *cl,
15722         __rte_unused void *data)
15723 {
15724         struct cmd_set_nvgre_result *res = parsed_result;
15725         union {
15726                 uint32_t nvgre_tni;
15727                 uint8_t tni[4];
15728         } id = {
15729                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15730         };
15731
15732         if (strcmp(res->nvgre, "nvgre") == 0)
15733                 nvgre_encap_conf.select_vlan = 0;
15734         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15735                 nvgre_encap_conf.select_vlan = 1;
15736         if (strcmp(res->ip_version, "ipv4") == 0)
15737                 nvgre_encap_conf.select_ipv4 = 1;
15738         else if (strcmp(res->ip_version, "ipv6") == 0)
15739                 nvgre_encap_conf.select_ipv4 = 0;
15740         else
15741                 return;
15742         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15743         if (nvgre_encap_conf.select_ipv4) {
15744                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15745                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15746         } else {
15747                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15748                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15749         }
15750         if (nvgre_encap_conf.select_vlan)
15751                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15752         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15753                    RTE_ETHER_ADDR_LEN);
15754         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15755                    RTE_ETHER_ADDR_LEN);
15756 }
15757
15758 cmdline_parse_inst_t cmd_set_nvgre = {
15759         .f = cmd_set_nvgre_parsed,
15760         .data = NULL,
15761         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15762                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15763                 " eth-dst <eth-dst>",
15764         .tokens = {
15765                 (void *)&cmd_set_nvgre_set,
15766                 (void *)&cmd_set_nvgre_nvgre,
15767                 (void *)&cmd_set_nvgre_ip_version,
15768                 (void *)&cmd_set_nvgre_ip_version_value,
15769                 (void *)&cmd_set_nvgre_tni,
15770                 (void *)&cmd_set_nvgre_tni_value,
15771                 (void *)&cmd_set_nvgre_ip_src,
15772                 (void *)&cmd_set_nvgre_ip_src_value,
15773                 (void *)&cmd_set_nvgre_ip_dst,
15774                 (void *)&cmd_set_nvgre_ip_dst_value,
15775                 (void *)&cmd_set_nvgre_eth_src,
15776                 (void *)&cmd_set_nvgre_eth_src_value,
15777                 (void *)&cmd_set_nvgre_eth_dst,
15778                 (void *)&cmd_set_nvgre_eth_dst_value,
15779                 NULL,
15780         },
15781 };
15782
15783 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15784         .f = cmd_set_nvgre_parsed,
15785         .data = NULL,
15786         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15787                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15788                 " eth-src <eth-src> eth-dst <eth-dst>",
15789         .tokens = {
15790                 (void *)&cmd_set_nvgre_set,
15791                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15792                 (void *)&cmd_set_nvgre_ip_version,
15793                 (void *)&cmd_set_nvgre_ip_version_value,
15794                 (void *)&cmd_set_nvgre_tni,
15795                 (void *)&cmd_set_nvgre_tni_value,
15796                 (void *)&cmd_set_nvgre_ip_src,
15797                 (void *)&cmd_set_nvgre_ip_src_value,
15798                 (void *)&cmd_set_nvgre_ip_dst,
15799                 (void *)&cmd_set_nvgre_ip_dst_value,
15800                 (void *)&cmd_set_nvgre_vlan,
15801                 (void *)&cmd_set_nvgre_vlan_value,
15802                 (void *)&cmd_set_nvgre_eth_src,
15803                 (void *)&cmd_set_nvgre_eth_src_value,
15804                 (void *)&cmd_set_nvgre_eth_dst,
15805                 (void *)&cmd_set_nvgre_eth_dst_value,
15806                 NULL,
15807         },
15808 };
15809
15810 /** Set L2 encapsulation details */
15811 struct cmd_set_l2_encap_result {
15812         cmdline_fixed_string_t set;
15813         cmdline_fixed_string_t l2_encap;
15814         cmdline_fixed_string_t pos_token;
15815         cmdline_fixed_string_t ip_version;
15816         uint32_t vlan_present:1;
15817         uint16_t tci;
15818         struct rte_ether_addr eth_src;
15819         struct rte_ether_addr eth_dst;
15820 };
15821
15822 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15823         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15824 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15825         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15826 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15828                                  "l2_encap-with-vlan");
15829 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15831                                  "ip-version");
15832 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15834                                  "ipv4#ipv6");
15835 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15836         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15837                                  "vlan-tci");
15838 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15839         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15840 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15841         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15842                                  "eth-src");
15843 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15844         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15845 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15846         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15847                                  "eth-dst");
15848 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15849         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15850
15851 static void cmd_set_l2_encap_parsed(void *parsed_result,
15852         __rte_unused struct cmdline *cl,
15853         __rte_unused void *data)
15854 {
15855         struct cmd_set_l2_encap_result *res = parsed_result;
15856
15857         if (strcmp(res->l2_encap, "l2_encap") == 0)
15858                 l2_encap_conf.select_vlan = 0;
15859         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15860                 l2_encap_conf.select_vlan = 1;
15861         if (strcmp(res->ip_version, "ipv4") == 0)
15862                 l2_encap_conf.select_ipv4 = 1;
15863         else if (strcmp(res->ip_version, "ipv6") == 0)
15864                 l2_encap_conf.select_ipv4 = 0;
15865         else
15866                 return;
15867         if (l2_encap_conf.select_vlan)
15868                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15869         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15870                    RTE_ETHER_ADDR_LEN);
15871         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15872                    RTE_ETHER_ADDR_LEN);
15873 }
15874
15875 cmdline_parse_inst_t cmd_set_l2_encap = {
15876         .f = cmd_set_l2_encap_parsed,
15877         .data = NULL,
15878         .help_str = "set l2_encap ip-version ipv4|ipv6"
15879                 " eth-src <eth-src> eth-dst <eth-dst>",
15880         .tokens = {
15881                 (void *)&cmd_set_l2_encap_set,
15882                 (void *)&cmd_set_l2_encap_l2_encap,
15883                 (void *)&cmd_set_l2_encap_ip_version,
15884                 (void *)&cmd_set_l2_encap_ip_version_value,
15885                 (void *)&cmd_set_l2_encap_eth_src,
15886                 (void *)&cmd_set_l2_encap_eth_src_value,
15887                 (void *)&cmd_set_l2_encap_eth_dst,
15888                 (void *)&cmd_set_l2_encap_eth_dst_value,
15889                 NULL,
15890         },
15891 };
15892
15893 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15894         .f = cmd_set_l2_encap_parsed,
15895         .data = NULL,
15896         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15897                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15898         .tokens = {
15899                 (void *)&cmd_set_l2_encap_set,
15900                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15901                 (void *)&cmd_set_l2_encap_ip_version,
15902                 (void *)&cmd_set_l2_encap_ip_version_value,
15903                 (void *)&cmd_set_l2_encap_vlan,
15904                 (void *)&cmd_set_l2_encap_vlan_value,
15905                 (void *)&cmd_set_l2_encap_eth_src,
15906                 (void *)&cmd_set_l2_encap_eth_src_value,
15907                 (void *)&cmd_set_l2_encap_eth_dst,
15908                 (void *)&cmd_set_l2_encap_eth_dst_value,
15909                 NULL,
15910         },
15911 };
15912
15913 /** Set L2 decapsulation details */
15914 struct cmd_set_l2_decap_result {
15915         cmdline_fixed_string_t set;
15916         cmdline_fixed_string_t l2_decap;
15917         cmdline_fixed_string_t pos_token;
15918         uint32_t vlan_present:1;
15919 };
15920
15921 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15922         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15923 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15924         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15925                                  "l2_decap");
15926 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15927         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15928                                  "l2_decap-with-vlan");
15929
15930 static void cmd_set_l2_decap_parsed(void *parsed_result,
15931         __rte_unused struct cmdline *cl,
15932         __rte_unused void *data)
15933 {
15934         struct cmd_set_l2_decap_result *res = parsed_result;
15935
15936         if (strcmp(res->l2_decap, "l2_decap") == 0)
15937                 l2_decap_conf.select_vlan = 0;
15938         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15939                 l2_decap_conf.select_vlan = 1;
15940 }
15941
15942 cmdline_parse_inst_t cmd_set_l2_decap = {
15943         .f = cmd_set_l2_decap_parsed,
15944         .data = NULL,
15945         .help_str = "set l2_decap",
15946         .tokens = {
15947                 (void *)&cmd_set_l2_decap_set,
15948                 (void *)&cmd_set_l2_decap_l2_decap,
15949                 NULL,
15950         },
15951 };
15952
15953 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15954         .f = cmd_set_l2_decap_parsed,
15955         .data = NULL,
15956         .help_str = "set l2_decap-with-vlan",
15957         .tokens = {
15958                 (void *)&cmd_set_l2_decap_set,
15959                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15960                 NULL,
15961         },
15962 };
15963
15964 /** Set MPLSoGRE encapsulation details */
15965 struct cmd_set_mplsogre_encap_result {
15966         cmdline_fixed_string_t set;
15967         cmdline_fixed_string_t mplsogre;
15968         cmdline_fixed_string_t pos_token;
15969         cmdline_fixed_string_t ip_version;
15970         uint32_t vlan_present:1;
15971         uint32_t label;
15972         cmdline_ipaddr_t ip_src;
15973         cmdline_ipaddr_t ip_dst;
15974         uint16_t tci;
15975         struct rte_ether_addr eth_src;
15976         struct rte_ether_addr eth_dst;
15977 };
15978
15979 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15981                                  "set");
15982 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15984                                  "mplsogre_encap");
15985 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15987                                  mplsogre, "mplsogre_encap-with-vlan");
15988 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15990                                  pos_token, "ip-version");
15991 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15993                                  ip_version, "ipv4#ipv6");
15994 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15995         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15996                                  pos_token, "label");
15997 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15998         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15999                               UINT32);
16000 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16001         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16002                                  pos_token, "ip-src");
16003 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16004         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16005 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16006         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16007                                  pos_token, "ip-dst");
16008 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16009         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16010 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16011         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16012                                  pos_token, "vlan-tci");
16013 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16014         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16015                               UINT16);
16016 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16017         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16018                                  pos_token, "eth-src");
16019 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16020         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16021                                     eth_src);
16022 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16024                                  pos_token, "eth-dst");
16025 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16026         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16027                                     eth_dst);
16028
16029 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16030         __rte_unused struct cmdline *cl,
16031         __rte_unused void *data)
16032 {
16033         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16034         union {
16035                 uint32_t mplsogre_label;
16036                 uint8_t label[4];
16037         } id = {
16038                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16039         };
16040
16041         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16042                 mplsogre_encap_conf.select_vlan = 0;
16043         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16044                 mplsogre_encap_conf.select_vlan = 1;
16045         if (strcmp(res->ip_version, "ipv4") == 0)
16046                 mplsogre_encap_conf.select_ipv4 = 1;
16047         else if (strcmp(res->ip_version, "ipv6") == 0)
16048                 mplsogre_encap_conf.select_ipv4 = 0;
16049         else
16050                 return;
16051         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16052         if (mplsogre_encap_conf.select_ipv4) {
16053                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16054                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16055         } else {
16056                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16057                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16058         }
16059         if (mplsogre_encap_conf.select_vlan)
16060                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16061         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16062                    RTE_ETHER_ADDR_LEN);
16063         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16064                    RTE_ETHER_ADDR_LEN);
16065 }
16066
16067 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16068         .f = cmd_set_mplsogre_encap_parsed,
16069         .data = NULL,
16070         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16071                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16072                 " eth-dst <eth-dst>",
16073         .tokens = {
16074                 (void *)&cmd_set_mplsogre_encap_set,
16075                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16076                 (void *)&cmd_set_mplsogre_encap_ip_version,
16077                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16078                 (void *)&cmd_set_mplsogre_encap_label,
16079                 (void *)&cmd_set_mplsogre_encap_label_value,
16080                 (void *)&cmd_set_mplsogre_encap_ip_src,
16081                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16082                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16083                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16084                 (void *)&cmd_set_mplsogre_encap_eth_src,
16085                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16086                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16087                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16088                 NULL,
16089         },
16090 };
16091
16092 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16093         .f = cmd_set_mplsogre_encap_parsed,
16094         .data = NULL,
16095         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16096                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16097                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16098         .tokens = {
16099                 (void *)&cmd_set_mplsogre_encap_set,
16100                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16101                 (void *)&cmd_set_mplsogre_encap_ip_version,
16102                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16103                 (void *)&cmd_set_mplsogre_encap_label,
16104                 (void *)&cmd_set_mplsogre_encap_label_value,
16105                 (void *)&cmd_set_mplsogre_encap_ip_src,
16106                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16107                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16108                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16109                 (void *)&cmd_set_mplsogre_encap_vlan,
16110                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16111                 (void *)&cmd_set_mplsogre_encap_eth_src,
16112                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16113                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16114                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16115                 NULL,
16116         },
16117 };
16118
16119 /** Set MPLSoGRE decapsulation details */
16120 struct cmd_set_mplsogre_decap_result {
16121         cmdline_fixed_string_t set;
16122         cmdline_fixed_string_t mplsogre;
16123         cmdline_fixed_string_t pos_token;
16124         cmdline_fixed_string_t ip_version;
16125         uint32_t vlan_present:1;
16126 };
16127
16128 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16129         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16130                                  "set");
16131 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16132         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16133                                  "mplsogre_decap");
16134 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16135         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16136                                  mplsogre, "mplsogre_decap-with-vlan");
16137 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16138         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16139                                  pos_token, "ip-version");
16140 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16141         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16142                                  ip_version, "ipv4#ipv6");
16143
16144 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16145         __rte_unused struct cmdline *cl,
16146         __rte_unused void *data)
16147 {
16148         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16149
16150         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16151                 mplsogre_decap_conf.select_vlan = 0;
16152         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16153                 mplsogre_decap_conf.select_vlan = 1;
16154         if (strcmp(res->ip_version, "ipv4") == 0)
16155                 mplsogre_decap_conf.select_ipv4 = 1;
16156         else if (strcmp(res->ip_version, "ipv6") == 0)
16157                 mplsogre_decap_conf.select_ipv4 = 0;
16158 }
16159
16160 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16161         .f = cmd_set_mplsogre_decap_parsed,
16162         .data = NULL,
16163         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16164         .tokens = {
16165                 (void *)&cmd_set_mplsogre_decap_set,
16166                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16167                 (void *)&cmd_set_mplsogre_decap_ip_version,
16168                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16169                 NULL,
16170         },
16171 };
16172
16173 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16174         .f = cmd_set_mplsogre_decap_parsed,
16175         .data = NULL,
16176         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16177         .tokens = {
16178                 (void *)&cmd_set_mplsogre_decap_set,
16179                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16180                 (void *)&cmd_set_mplsogre_decap_ip_version,
16181                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16182                 NULL,
16183         },
16184 };
16185
16186 /** Set MPLSoUDP encapsulation details */
16187 struct cmd_set_mplsoudp_encap_result {
16188         cmdline_fixed_string_t set;
16189         cmdline_fixed_string_t mplsoudp;
16190         cmdline_fixed_string_t pos_token;
16191         cmdline_fixed_string_t ip_version;
16192         uint32_t vlan_present:1;
16193         uint32_t label;
16194         uint16_t udp_src;
16195         uint16_t udp_dst;
16196         cmdline_ipaddr_t ip_src;
16197         cmdline_ipaddr_t ip_dst;
16198         uint16_t tci;
16199         struct rte_ether_addr eth_src;
16200         struct rte_ether_addr eth_dst;
16201 };
16202
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16205                                  "set");
16206 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16207         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16208                                  "mplsoudp_encap");
16209 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16211                                  mplsoudp, "mplsoudp_encap-with-vlan");
16212 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16213         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16214                                  pos_token, "ip-version");
16215 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16217                                  ip_version, "ipv4#ipv6");
16218 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16219         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16220                                  pos_token, "label");
16221 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16222         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16223                               UINT32);
16224 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16225         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16226                                  pos_token, "udp-src");
16227 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16228         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16229                               UINT16);
16230 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16231         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16232                                  pos_token, "udp-dst");
16233 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16234         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16235                               UINT16);
16236 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16237         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16238                                  pos_token, "ip-src");
16239 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16240         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16241 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16242         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16243                                  pos_token, "ip-dst");
16244 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16245         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16246 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16247         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16248                                  pos_token, "vlan-tci");
16249 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16250         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16251                               UINT16);
16252 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16253         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16254                                  pos_token, "eth-src");
16255 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16256         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16257                                     eth_src);
16258 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16259         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16260                                  pos_token, "eth-dst");
16261 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16262         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16263                                     eth_dst);
16264
16265 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16266         __rte_unused struct cmdline *cl,
16267         __rte_unused void *data)
16268 {
16269         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16270         union {
16271                 uint32_t mplsoudp_label;
16272                 uint8_t label[4];
16273         } id = {
16274                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16275         };
16276
16277         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16278                 mplsoudp_encap_conf.select_vlan = 0;
16279         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16280                 mplsoudp_encap_conf.select_vlan = 1;
16281         if (strcmp(res->ip_version, "ipv4") == 0)
16282                 mplsoudp_encap_conf.select_ipv4 = 1;
16283         else if (strcmp(res->ip_version, "ipv6") == 0)
16284                 mplsoudp_encap_conf.select_ipv4 = 0;
16285         else
16286                 return;
16287         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16288         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16289         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16290         if (mplsoudp_encap_conf.select_ipv4) {
16291                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16292                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16293         } else {
16294                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16295                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16296         }
16297         if (mplsoudp_encap_conf.select_vlan)
16298                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16299         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16300                    RTE_ETHER_ADDR_LEN);
16301         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16302                    RTE_ETHER_ADDR_LEN);
16303 }
16304
16305 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16306         .f = cmd_set_mplsoudp_encap_parsed,
16307         .data = NULL,
16308         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16309                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16310                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16311         .tokens = {
16312                 (void *)&cmd_set_mplsoudp_encap_set,
16313                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16314                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16315                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16316                 (void *)&cmd_set_mplsoudp_encap_label,
16317                 (void *)&cmd_set_mplsoudp_encap_label_value,
16318                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16319                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16320                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16321                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16322                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16323                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16324                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16325                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16326                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16327                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16328                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16329                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16330                 NULL,
16331         },
16332 };
16333
16334 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16335         .f = cmd_set_mplsoudp_encap_parsed,
16336         .data = NULL,
16337         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16338                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16339                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16340                 " eth-src <eth-src> eth-dst <eth-dst>",
16341         .tokens = {
16342                 (void *)&cmd_set_mplsoudp_encap_set,
16343                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16344                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16345                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16346                 (void *)&cmd_set_mplsoudp_encap_label,
16347                 (void *)&cmd_set_mplsoudp_encap_label_value,
16348                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16349                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16350                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16351                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16352                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16353                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16354                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16355                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16356                 (void *)&cmd_set_mplsoudp_encap_vlan,
16357                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16358                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16359                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16360                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16361                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16362                 NULL,
16363         },
16364 };
16365
16366 /** Set MPLSoUDP decapsulation details */
16367 struct cmd_set_mplsoudp_decap_result {
16368         cmdline_fixed_string_t set;
16369         cmdline_fixed_string_t mplsoudp;
16370         cmdline_fixed_string_t pos_token;
16371         cmdline_fixed_string_t ip_version;
16372         uint32_t vlan_present:1;
16373 };
16374
16375 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16376         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16377                                  "set");
16378 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16379         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16380                                  "mplsoudp_decap");
16381 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16382         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16383                                  mplsoudp, "mplsoudp_decap-with-vlan");
16384 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16385         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16386                                  pos_token, "ip-version");
16387 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16388         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16389                                  ip_version, "ipv4#ipv6");
16390
16391 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16392         __rte_unused struct cmdline *cl,
16393         __rte_unused void *data)
16394 {
16395         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16396
16397         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16398                 mplsoudp_decap_conf.select_vlan = 0;
16399         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16400                 mplsoudp_decap_conf.select_vlan = 1;
16401         if (strcmp(res->ip_version, "ipv4") == 0)
16402                 mplsoudp_decap_conf.select_ipv4 = 1;
16403         else if (strcmp(res->ip_version, "ipv6") == 0)
16404                 mplsoudp_decap_conf.select_ipv4 = 0;
16405 }
16406
16407 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16408         .f = cmd_set_mplsoudp_decap_parsed,
16409         .data = NULL,
16410         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16411         .tokens = {
16412                 (void *)&cmd_set_mplsoudp_decap_set,
16413                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16414                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16415                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16416                 NULL,
16417         },
16418 };
16419
16420 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16421         .f = cmd_set_mplsoudp_decap_parsed,
16422         .data = NULL,
16423         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16424         .tokens = {
16425                 (void *)&cmd_set_mplsoudp_decap_set,
16426                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16427                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16428                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16429                 NULL,
16430         },
16431 };
16432
16433 /* Strict link priority scheduling mode setting */
16434 static void
16435 cmd_strict_link_prio_parsed(
16436         void *parsed_result,
16437         __rte_unused struct cmdline *cl,
16438         __rte_unused void *data)
16439 {
16440         struct cmd_vf_tc_bw_result *res = parsed_result;
16441         int ret = -ENOTSUP;
16442
16443         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16444                 return;
16445
16446 #ifdef RTE_LIBRTE_I40E_PMD
16447         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16448 #endif
16449
16450         switch (ret) {
16451         case 0:
16452                 break;
16453         case -EINVAL:
16454                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16455                 break;
16456         case -ENODEV:
16457                 printf("invalid port_id %d\n", res->port_id);
16458                 break;
16459         case -ENOTSUP:
16460                 printf("function not implemented\n");
16461                 break;
16462         default:
16463                 printf("programming error: (%s)\n", strerror(-ret));
16464         }
16465 }
16466
16467 cmdline_parse_inst_t cmd_strict_link_prio = {
16468         .f = cmd_strict_link_prio_parsed,
16469         .data = NULL,
16470         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16471         .tokens = {
16472                 (void *)&cmd_vf_tc_bw_set,
16473                 (void *)&cmd_vf_tc_bw_tx,
16474                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16475                 (void *)&cmd_vf_tc_bw_port_id,
16476                 (void *)&cmd_vf_tc_bw_tc_map,
16477                 NULL,
16478         },
16479 };
16480
16481 /* Load dynamic device personalization*/
16482 struct cmd_ddp_add_result {
16483         cmdline_fixed_string_t ddp;
16484         cmdline_fixed_string_t add;
16485         portid_t port_id;
16486         char filepath[];
16487 };
16488
16489 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16490         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16491 cmdline_parse_token_string_t cmd_ddp_add_add =
16492         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16493 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16494         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16495 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16496         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16497
16498 static void
16499 cmd_ddp_add_parsed(
16500         void *parsed_result,
16501         __rte_unused struct cmdline *cl,
16502         __rte_unused void *data)
16503 {
16504         struct cmd_ddp_add_result *res = parsed_result;
16505         uint8_t *buff;
16506         uint32_t size;
16507         char *filepath;
16508         char *file_fld[2];
16509         int file_num;
16510         int ret = -ENOTSUP;
16511
16512         if (!all_ports_stopped()) {
16513                 printf("Please stop all ports first\n");
16514                 return;
16515         }
16516
16517         filepath = strdup(res->filepath);
16518         if (filepath == NULL) {
16519                 printf("Failed to allocate memory\n");
16520                 return;
16521         }
16522         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16523
16524         buff = open_file(file_fld[0], &size);
16525         if (!buff) {
16526                 free((void *)filepath);
16527                 return;
16528         }
16529
16530 #ifdef RTE_LIBRTE_I40E_PMD
16531         if (ret == -ENOTSUP)
16532                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16533                                                buff, size,
16534                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16535 #endif
16536
16537         if (ret == -EEXIST)
16538                 printf("Profile has already existed.\n");
16539         else if (ret < 0)
16540                 printf("Failed to load profile.\n");
16541         else if (file_num == 2)
16542                 save_file(file_fld[1], buff, size);
16543
16544         close_file(buff);
16545         free((void *)filepath);
16546 }
16547
16548 cmdline_parse_inst_t cmd_ddp_add = {
16549         .f = cmd_ddp_add_parsed,
16550         .data = NULL,
16551         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16552         .tokens = {
16553                 (void *)&cmd_ddp_add_ddp,
16554                 (void *)&cmd_ddp_add_add,
16555                 (void *)&cmd_ddp_add_port_id,
16556                 (void *)&cmd_ddp_add_filepath,
16557                 NULL,
16558         },
16559 };
16560
16561 /* Delete dynamic device personalization*/
16562 struct cmd_ddp_del_result {
16563         cmdline_fixed_string_t ddp;
16564         cmdline_fixed_string_t del;
16565         portid_t port_id;
16566         char filepath[];
16567 };
16568
16569 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16571 cmdline_parse_token_string_t cmd_ddp_del_del =
16572         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16573 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16574         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16575 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16576         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16577
16578 static void
16579 cmd_ddp_del_parsed(
16580         void *parsed_result,
16581         __rte_unused struct cmdline *cl,
16582         __rte_unused void *data)
16583 {
16584         struct cmd_ddp_del_result *res = parsed_result;
16585         uint8_t *buff;
16586         uint32_t size;
16587         int ret = -ENOTSUP;
16588
16589         if (!all_ports_stopped()) {
16590                 printf("Please stop all ports first\n");
16591                 return;
16592         }
16593
16594         buff = open_file(res->filepath, &size);
16595         if (!buff)
16596                 return;
16597
16598 #ifdef RTE_LIBRTE_I40E_PMD
16599         if (ret == -ENOTSUP)
16600                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16601                                                buff, size,
16602                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16603 #endif
16604
16605         if (ret == -EACCES)
16606                 printf("Profile does not exist.\n");
16607         else if (ret < 0)
16608                 printf("Failed to delete profile.\n");
16609
16610         close_file(buff);
16611 }
16612
16613 cmdline_parse_inst_t cmd_ddp_del = {
16614         .f = cmd_ddp_del_parsed,
16615         .data = NULL,
16616         .help_str = "ddp del <port_id> <backup_profile_path>",
16617         .tokens = {
16618                 (void *)&cmd_ddp_del_ddp,
16619                 (void *)&cmd_ddp_del_del,
16620                 (void *)&cmd_ddp_del_port_id,
16621                 (void *)&cmd_ddp_del_filepath,
16622                 NULL,
16623         },
16624 };
16625
16626 /* Get dynamic device personalization profile info */
16627 struct cmd_ddp_info_result {
16628         cmdline_fixed_string_t ddp;
16629         cmdline_fixed_string_t get;
16630         cmdline_fixed_string_t info;
16631         char filepath[];
16632 };
16633
16634 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16635         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16636 cmdline_parse_token_string_t cmd_ddp_info_get =
16637         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16638 cmdline_parse_token_string_t cmd_ddp_info_info =
16639         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16640 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16641         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16642
16643 static void
16644 cmd_ddp_info_parsed(
16645         void *parsed_result,
16646         __rte_unused struct cmdline *cl,
16647         __rte_unused void *data)
16648 {
16649         struct cmd_ddp_info_result *res = parsed_result;
16650         uint8_t *pkg;
16651         uint32_t pkg_size;
16652         int ret = -ENOTSUP;
16653 #ifdef RTE_LIBRTE_I40E_PMD
16654         uint32_t i, j, n;
16655         uint8_t *buff;
16656         uint32_t buff_size = 0;
16657         struct rte_pmd_i40e_profile_info info;
16658         uint32_t dev_num = 0;
16659         struct rte_pmd_i40e_ddp_device_id *devs;
16660         uint32_t proto_num = 0;
16661         struct rte_pmd_i40e_proto_info *proto = NULL;
16662         uint32_t pctype_num = 0;
16663         struct rte_pmd_i40e_ptype_info *pctype;
16664         uint32_t ptype_num = 0;
16665         struct rte_pmd_i40e_ptype_info *ptype;
16666         uint8_t proto_id;
16667
16668 #endif
16669
16670         pkg = open_file(res->filepath, &pkg_size);
16671         if (!pkg)
16672                 return;
16673
16674 #ifdef RTE_LIBRTE_I40E_PMD
16675         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16676                                 (uint8_t *)&info, sizeof(info),
16677                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16678         if (!ret) {
16679                 printf("Global Track id:       0x%x\n", info.track_id);
16680                 printf("Global Version:        %d.%d.%d.%d\n",
16681                         info.version.major,
16682                         info.version.minor,
16683                         info.version.update,
16684                         info.version.draft);
16685                 printf("Global Package name:   %s\n\n", info.name);
16686         }
16687
16688         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16689                                 (uint8_t *)&info, sizeof(info),
16690                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16691         if (!ret) {
16692                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16693                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16694                         info.version.major,
16695                         info.version.minor,
16696                         info.version.update,
16697                         info.version.draft);
16698                 printf("i40e Profile name:     %s\n\n", info.name);
16699         }
16700
16701         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16702                                 (uint8_t *)&buff_size, sizeof(buff_size),
16703                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16704         if (!ret && buff_size) {
16705                 buff = (uint8_t *)malloc(buff_size);
16706                 if (buff) {
16707                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16708                                                 buff, buff_size,
16709                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16710                         if (!ret)
16711                                 printf("Package Notes:\n%s\n\n", buff);
16712                         free(buff);
16713                 }
16714         }
16715
16716         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16717                                 (uint8_t *)&dev_num, sizeof(dev_num),
16718                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16719         if (!ret && dev_num) {
16720                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16721                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16722                 if (devs) {
16723                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16724                                                 (uint8_t *)devs, buff_size,
16725                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16726                         if (!ret) {
16727                                 printf("List of supported devices:\n");
16728                                 for (i = 0; i < dev_num; i++) {
16729                                         printf("  %04X:%04X %04X:%04X\n",
16730                                                 devs[i].vendor_dev_id >> 16,
16731                                                 devs[i].vendor_dev_id & 0xFFFF,
16732                                                 devs[i].sub_vendor_dev_id >> 16,
16733                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16734                                 }
16735                                 printf("\n");
16736                         }
16737                         free(devs);
16738                 }
16739         }
16740
16741         /* get information about protocols and packet types */
16742         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16743                 (uint8_t *)&proto_num, sizeof(proto_num),
16744                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16745         if (ret || !proto_num)
16746                 goto no_print_return;
16747
16748         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16749         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16750         if (!proto)
16751                 goto no_print_return;
16752
16753         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16754                                         buff_size,
16755                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16756         if (!ret) {
16757                 printf("List of used protocols:\n");
16758                 for (i = 0; i < proto_num; i++)
16759                         printf("  %2u: %s\n", proto[i].proto_id,
16760                                proto[i].name);
16761                 printf("\n");
16762         }
16763         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16764                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16765                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16766         if (ret || !pctype_num)
16767                 goto no_print_pctypes;
16768
16769         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16770         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16771         if (!pctype)
16772                 goto no_print_pctypes;
16773
16774         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16775                                         buff_size,
16776                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16777         if (ret) {
16778                 free(pctype);
16779                 goto no_print_pctypes;
16780         }
16781
16782         printf("List of defined packet classification types:\n");
16783         for (i = 0; i < pctype_num; i++) {
16784                 printf("  %2u:", pctype[i].ptype_id);
16785                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16786                         proto_id = pctype[i].protocols[j];
16787                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16788                                 for (n = 0; n < proto_num; n++) {
16789                                         if (proto[n].proto_id == proto_id) {
16790                                                 printf(" %s", proto[n].name);
16791                                                 break;
16792                                         }
16793                                 }
16794                         }
16795                 }
16796                 printf("\n");
16797         }
16798         printf("\n");
16799         free(pctype);
16800
16801 no_print_pctypes:
16802
16803         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16804                                         sizeof(ptype_num),
16805                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16806         if (ret || !ptype_num)
16807                 goto no_print_return;
16808
16809         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16810         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16811         if (!ptype)
16812                 goto no_print_return;
16813
16814         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16815                                         buff_size,
16816                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16817         if (ret) {
16818                 free(ptype);
16819                 goto no_print_return;
16820         }
16821         printf("List of defined packet types:\n");
16822         for (i = 0; i < ptype_num; i++) {
16823                 printf("  %2u:", ptype[i].ptype_id);
16824                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16825                         proto_id = ptype[i].protocols[j];
16826                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16827                                 for (n = 0; n < proto_num; n++) {
16828                                         if (proto[n].proto_id == proto_id) {
16829                                                 printf(" %s", proto[n].name);
16830                                                 break;
16831                                         }
16832                                 }
16833                         }
16834                 }
16835                 printf("\n");
16836         }
16837         free(ptype);
16838         printf("\n");
16839
16840         ret = 0;
16841 no_print_return:
16842         if (proto)
16843                 free(proto);
16844 #endif
16845         if (ret == -ENOTSUP)
16846                 printf("Function not supported in PMD driver\n");
16847         close_file(pkg);
16848 }
16849
16850 cmdline_parse_inst_t cmd_ddp_get_info = {
16851         .f = cmd_ddp_info_parsed,
16852         .data = NULL,
16853         .help_str = "ddp get info <profile_path>",
16854         .tokens = {
16855                 (void *)&cmd_ddp_info_ddp,
16856                 (void *)&cmd_ddp_info_get,
16857                 (void *)&cmd_ddp_info_info,
16858                 (void *)&cmd_ddp_info_filepath,
16859                 NULL,
16860         },
16861 };
16862
16863 /* Get dynamic device personalization profile info list*/
16864 #define PROFILE_INFO_SIZE 48
16865 #define MAX_PROFILE_NUM 16
16866
16867 struct cmd_ddp_get_list_result {
16868         cmdline_fixed_string_t ddp;
16869         cmdline_fixed_string_t get;
16870         cmdline_fixed_string_t list;
16871         portid_t port_id;
16872 };
16873
16874 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16875         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16876 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16877         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16878 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16879         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16880 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16881         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16882
16883 static void
16884 cmd_ddp_get_list_parsed(
16885         __rte_unused void *parsed_result,
16886         __rte_unused struct cmdline *cl,
16887         __rte_unused void *data)
16888 {
16889 #ifdef RTE_LIBRTE_I40E_PMD
16890         struct cmd_ddp_get_list_result *res = parsed_result;
16891         struct rte_pmd_i40e_profile_list *p_list;
16892         struct rte_pmd_i40e_profile_info *p_info;
16893         uint32_t p_num;
16894         uint32_t size;
16895         uint32_t i;
16896 #endif
16897         int ret = -ENOTSUP;
16898
16899 #ifdef RTE_LIBRTE_I40E_PMD
16900         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16901         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16902         if (!p_list) {
16903                 printf("%s: Failed to malloc buffer\n", __func__);
16904                 return;
16905         }
16906
16907         if (ret == -ENOTSUP)
16908                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16909                                                 (uint8_t *)p_list, size);
16910
16911         if (!ret) {
16912                 p_num = p_list->p_count;
16913                 printf("Profile number is: %d\n\n", p_num);
16914
16915                 for (i = 0; i < p_num; i++) {
16916                         p_info = &p_list->p_info[i];
16917                         printf("Profile %d:\n", i);
16918                         printf("Track id:     0x%x\n", p_info->track_id);
16919                         printf("Version:      %d.%d.%d.%d\n",
16920                                p_info->version.major,
16921                                p_info->version.minor,
16922                                p_info->version.update,
16923                                p_info->version.draft);
16924                         printf("Profile name: %s\n\n", p_info->name);
16925                 }
16926         }
16927
16928         free(p_list);
16929 #endif
16930
16931         if (ret < 0)
16932                 printf("Failed to get ddp list\n");
16933 }
16934
16935 cmdline_parse_inst_t cmd_ddp_get_list = {
16936         .f = cmd_ddp_get_list_parsed,
16937         .data = NULL,
16938         .help_str = "ddp get list <port_id>",
16939         .tokens = {
16940                 (void *)&cmd_ddp_get_list_ddp,
16941                 (void *)&cmd_ddp_get_list_get,
16942                 (void *)&cmd_ddp_get_list_list,
16943                 (void *)&cmd_ddp_get_list_port_id,
16944                 NULL,
16945         },
16946 };
16947
16948 /* Configure input set */
16949 struct cmd_cfg_input_set_result {
16950         cmdline_fixed_string_t port;
16951         cmdline_fixed_string_t cfg;
16952         portid_t port_id;
16953         cmdline_fixed_string_t pctype;
16954         uint8_t pctype_id;
16955         cmdline_fixed_string_t inset_type;
16956         cmdline_fixed_string_t opt;
16957         cmdline_fixed_string_t field;
16958         uint8_t field_idx;
16959 };
16960
16961 static void
16962 cmd_cfg_input_set_parsed(
16963         __rte_unused void *parsed_result,
16964         __rte_unused struct cmdline *cl,
16965         __rte_unused void *data)
16966 {
16967 #ifdef RTE_LIBRTE_I40E_PMD
16968         struct cmd_cfg_input_set_result *res = parsed_result;
16969         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16970         struct rte_pmd_i40e_inset inset;
16971 #endif
16972         int ret = -ENOTSUP;
16973
16974         if (!all_ports_stopped()) {
16975                 printf("Please stop all ports first\n");
16976                 return;
16977         }
16978
16979 #ifdef RTE_LIBRTE_I40E_PMD
16980         if (!strcmp(res->inset_type, "hash_inset"))
16981                 inset_type = INSET_HASH;
16982         else if (!strcmp(res->inset_type, "fdir_inset"))
16983                 inset_type = INSET_FDIR;
16984         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16985                 inset_type = INSET_FDIR_FLX;
16986         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16987                                      &inset, inset_type);
16988         if (ret) {
16989                 printf("Failed to get input set.\n");
16990                 return;
16991         }
16992
16993         if (!strcmp(res->opt, "get")) {
16994                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16995                                                    res->field_idx);
16996                 if (ret)
16997                         printf("Field index %d is enabled.\n", res->field_idx);
16998                 else
16999                         printf("Field index %d is disabled.\n", res->field_idx);
17000                 return;
17001         } else if (!strcmp(res->opt, "set"))
17002                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17003                                                    res->field_idx);
17004         else if (!strcmp(res->opt, "clear"))
17005                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17006                                                      res->field_idx);
17007         if (ret) {
17008                 printf("Failed to configure input set field.\n");
17009                 return;
17010         }
17011
17012         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17013                                      &inset, inset_type);
17014         if (ret) {
17015                 printf("Failed to set input set.\n");
17016                 return;
17017         }
17018 #endif
17019
17020         if (ret == -ENOTSUP)
17021                 printf("Function not supported\n");
17022 }
17023
17024 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17025         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17026                                  port, "port");
17027 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17028         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17029                                  cfg, "config");
17030 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17031         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17032                               port_id, UINT16);
17033 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17034         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17035                                  pctype, "pctype");
17036 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17037         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17038                               pctype_id, UINT8);
17039 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17040         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17041                                  inset_type,
17042                                  "hash_inset#fdir_inset#fdir_flx_inset");
17043 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17044         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17045                                  opt, "get#set#clear");
17046 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17047         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17048                                  field, "field");
17049 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17050         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17051                               field_idx, UINT8);
17052
17053 cmdline_parse_inst_t cmd_cfg_input_set = {
17054         .f = cmd_cfg_input_set_parsed,
17055         .data = NULL,
17056         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17057                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17058         .tokens = {
17059                 (void *)&cmd_cfg_input_set_port,
17060                 (void *)&cmd_cfg_input_set_cfg,
17061                 (void *)&cmd_cfg_input_set_port_id,
17062                 (void *)&cmd_cfg_input_set_pctype,
17063                 (void *)&cmd_cfg_input_set_pctype_id,
17064                 (void *)&cmd_cfg_input_set_inset_type,
17065                 (void *)&cmd_cfg_input_set_opt,
17066                 (void *)&cmd_cfg_input_set_field,
17067                 (void *)&cmd_cfg_input_set_field_idx,
17068                 NULL,
17069         },
17070 };
17071
17072 /* Clear input set */
17073 struct cmd_clear_input_set_result {
17074         cmdline_fixed_string_t port;
17075         cmdline_fixed_string_t cfg;
17076         portid_t port_id;
17077         cmdline_fixed_string_t pctype;
17078         uint8_t pctype_id;
17079         cmdline_fixed_string_t inset_type;
17080         cmdline_fixed_string_t clear;
17081         cmdline_fixed_string_t all;
17082 };
17083
17084 static void
17085 cmd_clear_input_set_parsed(
17086         __rte_unused void *parsed_result,
17087         __rte_unused struct cmdline *cl,
17088         __rte_unused void *data)
17089 {
17090 #ifdef RTE_LIBRTE_I40E_PMD
17091         struct cmd_clear_input_set_result *res = parsed_result;
17092         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17093         struct rte_pmd_i40e_inset inset;
17094 #endif
17095         int ret = -ENOTSUP;
17096
17097         if (!all_ports_stopped()) {
17098                 printf("Please stop all ports first\n");
17099                 return;
17100         }
17101
17102 #ifdef RTE_LIBRTE_I40E_PMD
17103         if (!strcmp(res->inset_type, "hash_inset"))
17104                 inset_type = INSET_HASH;
17105         else if (!strcmp(res->inset_type, "fdir_inset"))
17106                 inset_type = INSET_FDIR;
17107         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17108                 inset_type = INSET_FDIR_FLX;
17109
17110         memset(&inset, 0, sizeof(inset));
17111
17112         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17113                                      &inset, inset_type);
17114         if (ret) {
17115                 printf("Failed to clear input set.\n");
17116                 return;
17117         }
17118
17119 #endif
17120
17121         if (ret == -ENOTSUP)
17122                 printf("Function not supported\n");
17123 }
17124
17125 cmdline_parse_token_string_t cmd_clear_input_set_port =
17126         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17127                                  port, "port");
17128 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17129         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17130                                  cfg, "config");
17131 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17132         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17133                               port_id, UINT16);
17134 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17135         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17136                                  pctype, "pctype");
17137 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17138         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17139                               pctype_id, UINT8);
17140 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17141         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17142                                  inset_type,
17143                                  "hash_inset#fdir_inset#fdir_flx_inset");
17144 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17145         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17146                                  clear, "clear");
17147 cmdline_parse_token_string_t cmd_clear_input_set_all =
17148         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17149                                  all, "all");
17150
17151 cmdline_parse_inst_t cmd_clear_input_set = {
17152         .f = cmd_clear_input_set_parsed,
17153         .data = NULL,
17154         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17155                     "fdir_inset|fdir_flx_inset clear all",
17156         .tokens = {
17157                 (void *)&cmd_clear_input_set_port,
17158                 (void *)&cmd_clear_input_set_cfg,
17159                 (void *)&cmd_clear_input_set_port_id,
17160                 (void *)&cmd_clear_input_set_pctype,
17161                 (void *)&cmd_clear_input_set_pctype_id,
17162                 (void *)&cmd_clear_input_set_inset_type,
17163                 (void *)&cmd_clear_input_set_clear,
17164                 (void *)&cmd_clear_input_set_all,
17165                 NULL,
17166         },
17167 };
17168
17169 /* show vf stats */
17170
17171 /* Common result structure for show vf stats */
17172 struct cmd_show_vf_stats_result {
17173         cmdline_fixed_string_t show;
17174         cmdline_fixed_string_t vf;
17175         cmdline_fixed_string_t stats;
17176         portid_t port_id;
17177         uint16_t vf_id;
17178 };
17179
17180 /* Common CLI fields show vf stats*/
17181 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17182         TOKEN_STRING_INITIALIZER
17183                 (struct cmd_show_vf_stats_result,
17184                  show, "show");
17185 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17186         TOKEN_STRING_INITIALIZER
17187                 (struct cmd_show_vf_stats_result,
17188                  vf, "vf");
17189 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17190         TOKEN_STRING_INITIALIZER
17191                 (struct cmd_show_vf_stats_result,
17192                  stats, "stats");
17193 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17194         TOKEN_NUM_INITIALIZER
17195                 (struct cmd_show_vf_stats_result,
17196                  port_id, UINT16);
17197 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17198         TOKEN_NUM_INITIALIZER
17199                 (struct cmd_show_vf_stats_result,
17200                  vf_id, UINT16);
17201
17202 static void
17203 cmd_show_vf_stats_parsed(
17204         void *parsed_result,
17205         __rte_unused struct cmdline *cl,
17206         __rte_unused void *data)
17207 {
17208         struct cmd_show_vf_stats_result *res = parsed_result;
17209         struct rte_eth_stats stats;
17210         int ret = -ENOTSUP;
17211         static const char *nic_stats_border = "########################";
17212
17213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17214                 return;
17215
17216         memset(&stats, 0, sizeof(stats));
17217
17218 #ifdef RTE_LIBRTE_I40E_PMD
17219         if (ret == -ENOTSUP)
17220                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17221                                                 res->vf_id,
17222                                                 &stats);
17223 #endif
17224 #ifdef RTE_LIBRTE_BNXT_PMD
17225         if (ret == -ENOTSUP)
17226                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17227                                                 res->vf_id,
17228                                                 &stats);
17229 #endif
17230
17231         switch (ret) {
17232         case 0:
17233                 break;
17234         case -EINVAL:
17235                 printf("invalid vf_id %d\n", res->vf_id);
17236                 break;
17237         case -ENODEV:
17238                 printf("invalid port_id %d\n", res->port_id);
17239                 break;
17240         case -ENOTSUP:
17241                 printf("function not implemented\n");
17242                 break;
17243         default:
17244                 printf("programming error: (%s)\n", strerror(-ret));
17245         }
17246
17247         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17248                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17249
17250         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17251                "%-"PRIu64"\n",
17252                stats.ipackets, stats.imissed, stats.ibytes);
17253         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17254         printf("  RX-nombuf:  %-10"PRIu64"\n",
17255                stats.rx_nombuf);
17256         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17257                "%-"PRIu64"\n",
17258                stats.opackets, stats.oerrors, stats.obytes);
17259
17260         printf("  %s############################%s\n",
17261                                nic_stats_border, nic_stats_border);
17262 }
17263
17264 cmdline_parse_inst_t cmd_show_vf_stats = {
17265         .f = cmd_show_vf_stats_parsed,
17266         .data = NULL,
17267         .help_str = "show vf stats <port_id> <vf_id>",
17268         .tokens = {
17269                 (void *)&cmd_show_vf_stats_show,
17270                 (void *)&cmd_show_vf_stats_vf,
17271                 (void *)&cmd_show_vf_stats_stats,
17272                 (void *)&cmd_show_vf_stats_port_id,
17273                 (void *)&cmd_show_vf_stats_vf_id,
17274                 NULL,
17275         },
17276 };
17277
17278 /* clear vf stats */
17279
17280 /* Common result structure for clear vf stats */
17281 struct cmd_clear_vf_stats_result {
17282         cmdline_fixed_string_t clear;
17283         cmdline_fixed_string_t vf;
17284         cmdline_fixed_string_t stats;
17285         portid_t port_id;
17286         uint16_t vf_id;
17287 };
17288
17289 /* Common CLI fields clear vf stats*/
17290 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_clear_vf_stats_result,
17293                  clear, "clear");
17294 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_clear_vf_stats_result,
17297                  vf, "vf");
17298 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17299         TOKEN_STRING_INITIALIZER
17300                 (struct cmd_clear_vf_stats_result,
17301                  stats, "stats");
17302 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17303         TOKEN_NUM_INITIALIZER
17304                 (struct cmd_clear_vf_stats_result,
17305                  port_id, UINT16);
17306 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17307         TOKEN_NUM_INITIALIZER
17308                 (struct cmd_clear_vf_stats_result,
17309                  vf_id, UINT16);
17310
17311 static void
17312 cmd_clear_vf_stats_parsed(
17313         void *parsed_result,
17314         __rte_unused struct cmdline *cl,
17315         __rte_unused void *data)
17316 {
17317         struct cmd_clear_vf_stats_result *res = parsed_result;
17318         int ret = -ENOTSUP;
17319
17320         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17321                 return;
17322
17323 #ifdef RTE_LIBRTE_I40E_PMD
17324         if (ret == -ENOTSUP)
17325                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17326                                                   res->vf_id);
17327 #endif
17328 #ifdef RTE_LIBRTE_BNXT_PMD
17329         if (ret == -ENOTSUP)
17330                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17331                                                   res->vf_id);
17332 #endif
17333
17334         switch (ret) {
17335         case 0:
17336                 break;
17337         case -EINVAL:
17338                 printf("invalid vf_id %d\n", res->vf_id);
17339                 break;
17340         case -ENODEV:
17341                 printf("invalid port_id %d\n", res->port_id);
17342                 break;
17343         case -ENOTSUP:
17344                 printf("function not implemented\n");
17345                 break;
17346         default:
17347                 printf("programming error: (%s)\n", strerror(-ret));
17348         }
17349 }
17350
17351 cmdline_parse_inst_t cmd_clear_vf_stats = {
17352         .f = cmd_clear_vf_stats_parsed,
17353         .data = NULL,
17354         .help_str = "clear vf stats <port_id> <vf_id>",
17355         .tokens = {
17356                 (void *)&cmd_clear_vf_stats_clear,
17357                 (void *)&cmd_clear_vf_stats_vf,
17358                 (void *)&cmd_clear_vf_stats_stats,
17359                 (void *)&cmd_clear_vf_stats_port_id,
17360                 (void *)&cmd_clear_vf_stats_vf_id,
17361                 NULL,
17362         },
17363 };
17364
17365 /* port config pctype mapping reset */
17366
17367 /* Common result structure for port config pctype mapping reset */
17368 struct cmd_pctype_mapping_reset_result {
17369         cmdline_fixed_string_t port;
17370         cmdline_fixed_string_t config;
17371         portid_t port_id;
17372         cmdline_fixed_string_t pctype;
17373         cmdline_fixed_string_t mapping;
17374         cmdline_fixed_string_t reset;
17375 };
17376
17377 /* Common CLI fields for port config pctype mapping reset*/
17378 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17379         TOKEN_STRING_INITIALIZER
17380                 (struct cmd_pctype_mapping_reset_result,
17381                  port, "port");
17382 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17383         TOKEN_STRING_INITIALIZER
17384                 (struct cmd_pctype_mapping_reset_result,
17385                  config, "config");
17386 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17387         TOKEN_NUM_INITIALIZER
17388                 (struct cmd_pctype_mapping_reset_result,
17389                  port_id, UINT16);
17390 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17391         TOKEN_STRING_INITIALIZER
17392                 (struct cmd_pctype_mapping_reset_result,
17393                  pctype, "pctype");
17394 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17395         TOKEN_STRING_INITIALIZER
17396                 (struct cmd_pctype_mapping_reset_result,
17397                  mapping, "mapping");
17398 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17399         TOKEN_STRING_INITIALIZER
17400                 (struct cmd_pctype_mapping_reset_result,
17401                  reset, "reset");
17402
17403 static void
17404 cmd_pctype_mapping_reset_parsed(
17405         void *parsed_result,
17406         __rte_unused struct cmdline *cl,
17407         __rte_unused void *data)
17408 {
17409         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17410         int ret = -ENOTSUP;
17411
17412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17413                 return;
17414
17415 #ifdef RTE_LIBRTE_I40E_PMD
17416         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17417 #endif
17418
17419         switch (ret) {
17420         case 0:
17421                 break;
17422         case -ENODEV:
17423                 printf("invalid port_id %d\n", res->port_id);
17424                 break;
17425         case -ENOTSUP:
17426                 printf("function not implemented\n");
17427                 break;
17428         default:
17429                 printf("programming error: (%s)\n", strerror(-ret));
17430         }
17431 }
17432
17433 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17434         .f = cmd_pctype_mapping_reset_parsed,
17435         .data = NULL,
17436         .help_str = "port config <port_id> pctype mapping reset",
17437         .tokens = {
17438                 (void *)&cmd_pctype_mapping_reset_port,
17439                 (void *)&cmd_pctype_mapping_reset_config,
17440                 (void *)&cmd_pctype_mapping_reset_port_id,
17441                 (void *)&cmd_pctype_mapping_reset_pctype,
17442                 (void *)&cmd_pctype_mapping_reset_mapping,
17443                 (void *)&cmd_pctype_mapping_reset_reset,
17444                 NULL,
17445         },
17446 };
17447
17448 /* show port pctype mapping */
17449
17450 /* Common result structure for show port pctype mapping */
17451 struct cmd_pctype_mapping_get_result {
17452         cmdline_fixed_string_t show;
17453         cmdline_fixed_string_t port;
17454         portid_t port_id;
17455         cmdline_fixed_string_t pctype;
17456         cmdline_fixed_string_t mapping;
17457 };
17458
17459 /* Common CLI fields for pctype mapping get */
17460 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17461         TOKEN_STRING_INITIALIZER
17462                 (struct cmd_pctype_mapping_get_result,
17463                  show, "show");
17464 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17465         TOKEN_STRING_INITIALIZER
17466                 (struct cmd_pctype_mapping_get_result,
17467                  port, "port");
17468 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17469         TOKEN_NUM_INITIALIZER
17470                 (struct cmd_pctype_mapping_get_result,
17471                  port_id, UINT16);
17472 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17473         TOKEN_STRING_INITIALIZER
17474                 (struct cmd_pctype_mapping_get_result,
17475                  pctype, "pctype");
17476 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17477         TOKEN_STRING_INITIALIZER
17478                 (struct cmd_pctype_mapping_get_result,
17479                  mapping, "mapping");
17480
17481 static void
17482 cmd_pctype_mapping_get_parsed(
17483         void *parsed_result,
17484         __rte_unused struct cmdline *cl,
17485         __rte_unused void *data)
17486 {
17487         struct cmd_pctype_mapping_get_result *res = parsed_result;
17488         int ret = -ENOTSUP;
17489 #ifdef RTE_LIBRTE_I40E_PMD
17490         struct rte_pmd_i40e_flow_type_mapping
17491                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17492         int i, j, first_pctype;
17493 #endif
17494
17495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17496                 return;
17497
17498 #ifdef RTE_LIBRTE_I40E_PMD
17499         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17500 #endif
17501
17502         switch (ret) {
17503         case 0:
17504                 break;
17505         case -ENODEV:
17506                 printf("invalid port_id %d\n", res->port_id);
17507                 return;
17508         case -ENOTSUP:
17509                 printf("function not implemented\n");
17510                 return;
17511         default:
17512                 printf("programming error: (%s)\n", strerror(-ret));
17513                 return;
17514         }
17515
17516 #ifdef RTE_LIBRTE_I40E_PMD
17517         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17518                 if (mapping[i].pctype != 0ULL) {
17519                         first_pctype = 1;
17520
17521                         printf("pctype: ");
17522                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17523                                 if (mapping[i].pctype & (1ULL << j)) {
17524                                         printf(first_pctype ?
17525                                                "%02d" : ",%02d", j);
17526                                         first_pctype = 0;
17527                                 }
17528                         }
17529                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17530                 }
17531         }
17532 #endif
17533 }
17534
17535 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17536         .f = cmd_pctype_mapping_get_parsed,
17537         .data = NULL,
17538         .help_str = "show port <port_id> pctype mapping",
17539         .tokens = {
17540                 (void *)&cmd_pctype_mapping_get_show,
17541                 (void *)&cmd_pctype_mapping_get_port,
17542                 (void *)&cmd_pctype_mapping_get_port_id,
17543                 (void *)&cmd_pctype_mapping_get_pctype,
17544                 (void *)&cmd_pctype_mapping_get_mapping,
17545                 NULL,
17546         },
17547 };
17548
17549 /* port config pctype mapping update */
17550
17551 /* Common result structure for port config pctype mapping update */
17552 struct cmd_pctype_mapping_update_result {
17553         cmdline_fixed_string_t port;
17554         cmdline_fixed_string_t config;
17555         portid_t port_id;
17556         cmdline_fixed_string_t pctype;
17557         cmdline_fixed_string_t mapping;
17558         cmdline_fixed_string_t update;
17559         cmdline_fixed_string_t pctype_list;
17560         uint16_t flow_type;
17561 };
17562
17563 /* Common CLI fields for pctype mapping update*/
17564 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17565         TOKEN_STRING_INITIALIZER
17566                 (struct cmd_pctype_mapping_update_result,
17567                  port, "port");
17568 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17569         TOKEN_STRING_INITIALIZER
17570                 (struct cmd_pctype_mapping_update_result,
17571                  config, "config");
17572 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17573         TOKEN_NUM_INITIALIZER
17574                 (struct cmd_pctype_mapping_update_result,
17575                  port_id, UINT16);
17576 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17577         TOKEN_STRING_INITIALIZER
17578                 (struct cmd_pctype_mapping_update_result,
17579                  pctype, "pctype");
17580 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17581         TOKEN_STRING_INITIALIZER
17582                 (struct cmd_pctype_mapping_update_result,
17583                  mapping, "mapping");
17584 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17585         TOKEN_STRING_INITIALIZER
17586                 (struct cmd_pctype_mapping_update_result,
17587                  update, "update");
17588 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17589         TOKEN_STRING_INITIALIZER
17590                 (struct cmd_pctype_mapping_update_result,
17591                  pctype_list, NULL);
17592 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17593         TOKEN_NUM_INITIALIZER
17594                 (struct cmd_pctype_mapping_update_result,
17595                  flow_type, UINT16);
17596
17597 static void
17598 cmd_pctype_mapping_update_parsed(
17599         void *parsed_result,
17600         __rte_unused struct cmdline *cl,
17601         __rte_unused void *data)
17602 {
17603         struct cmd_pctype_mapping_update_result *res = parsed_result;
17604         int ret = -ENOTSUP;
17605 #ifdef RTE_LIBRTE_I40E_PMD
17606         struct rte_pmd_i40e_flow_type_mapping mapping;
17607         unsigned int i;
17608         unsigned int nb_item;
17609         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17610 #endif
17611
17612         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17613                 return;
17614
17615 #ifdef RTE_LIBRTE_I40E_PMD
17616         nb_item = parse_item_list(res->pctype_list, "pctypes",
17617                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17618         mapping.flow_type = res->flow_type;
17619         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17620                 mapping.pctype |= (1ULL << pctype_list[i]);
17621         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17622                                                 &mapping,
17623                                                 1,
17624                                                 0);
17625 #endif
17626
17627         switch (ret) {
17628         case 0:
17629                 break;
17630         case -EINVAL:
17631                 printf("invalid pctype or flow type\n");
17632                 break;
17633         case -ENODEV:
17634                 printf("invalid port_id %d\n", res->port_id);
17635                 break;
17636         case -ENOTSUP:
17637                 printf("function not implemented\n");
17638                 break;
17639         default:
17640                 printf("programming error: (%s)\n", strerror(-ret));
17641         }
17642 }
17643
17644 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17645         .f = cmd_pctype_mapping_update_parsed,
17646         .data = NULL,
17647         .help_str = "port config <port_id> pctype mapping update"
17648         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17649         .tokens = {
17650                 (void *)&cmd_pctype_mapping_update_port,
17651                 (void *)&cmd_pctype_mapping_update_config,
17652                 (void *)&cmd_pctype_mapping_update_port_id,
17653                 (void *)&cmd_pctype_mapping_update_pctype,
17654                 (void *)&cmd_pctype_mapping_update_mapping,
17655                 (void *)&cmd_pctype_mapping_update_update,
17656                 (void *)&cmd_pctype_mapping_update_pc_type,
17657                 (void *)&cmd_pctype_mapping_update_flow_type,
17658                 NULL,
17659         },
17660 };
17661
17662 /* ptype mapping get */
17663
17664 /* Common result structure for ptype mapping get */
17665 struct cmd_ptype_mapping_get_result {
17666         cmdline_fixed_string_t ptype;
17667         cmdline_fixed_string_t mapping;
17668         cmdline_fixed_string_t get;
17669         portid_t port_id;
17670         uint8_t valid_only;
17671 };
17672
17673 /* Common CLI fields for ptype mapping get */
17674 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17675         TOKEN_STRING_INITIALIZER
17676                 (struct cmd_ptype_mapping_get_result,
17677                  ptype, "ptype");
17678 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17679         TOKEN_STRING_INITIALIZER
17680                 (struct cmd_ptype_mapping_get_result,
17681                  mapping, "mapping");
17682 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17683         TOKEN_STRING_INITIALIZER
17684                 (struct cmd_ptype_mapping_get_result,
17685                  get, "get");
17686 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17687         TOKEN_NUM_INITIALIZER
17688                 (struct cmd_ptype_mapping_get_result,
17689                  port_id, UINT16);
17690 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17691         TOKEN_NUM_INITIALIZER
17692                 (struct cmd_ptype_mapping_get_result,
17693                  valid_only, UINT8);
17694
17695 static void
17696 cmd_ptype_mapping_get_parsed(
17697         void *parsed_result,
17698         __rte_unused struct cmdline *cl,
17699         __rte_unused void *data)
17700 {
17701         struct cmd_ptype_mapping_get_result *res = parsed_result;
17702         int ret = -ENOTSUP;
17703 #ifdef RTE_LIBRTE_I40E_PMD
17704         int max_ptype_num = 256;
17705         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17706         uint16_t count;
17707         int i;
17708 #endif
17709
17710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17711                 return;
17712
17713 #ifdef RTE_LIBRTE_I40E_PMD
17714         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17715                                         mapping,
17716                                         max_ptype_num,
17717                                         &count,
17718                                         res->valid_only);
17719 #endif
17720
17721         switch (ret) {
17722         case 0:
17723                 break;
17724         case -ENODEV:
17725                 printf("invalid port_id %d\n", res->port_id);
17726                 break;
17727         case -ENOTSUP:
17728                 printf("function not implemented\n");
17729                 break;
17730         default:
17731                 printf("programming error: (%s)\n", strerror(-ret));
17732         }
17733
17734 #ifdef RTE_LIBRTE_I40E_PMD
17735         if (!ret) {
17736                 for (i = 0; i < count; i++)
17737                         printf("%3d\t0x%08x\n",
17738                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17739         }
17740 #endif
17741 }
17742
17743 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17744         .f = cmd_ptype_mapping_get_parsed,
17745         .data = NULL,
17746         .help_str = "ptype mapping get <port_id> <valid_only>",
17747         .tokens = {
17748                 (void *)&cmd_ptype_mapping_get_ptype,
17749                 (void *)&cmd_ptype_mapping_get_mapping,
17750                 (void *)&cmd_ptype_mapping_get_get,
17751                 (void *)&cmd_ptype_mapping_get_port_id,
17752                 (void *)&cmd_ptype_mapping_get_valid_only,
17753                 NULL,
17754         },
17755 };
17756
17757 /* ptype mapping replace */
17758
17759 /* Common result structure for ptype mapping replace */
17760 struct cmd_ptype_mapping_replace_result {
17761         cmdline_fixed_string_t ptype;
17762         cmdline_fixed_string_t mapping;
17763         cmdline_fixed_string_t replace;
17764         portid_t port_id;
17765         uint32_t target;
17766         uint8_t mask;
17767         uint32_t pkt_type;
17768 };
17769
17770 /* Common CLI fields for ptype mapping replace */
17771 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17772         TOKEN_STRING_INITIALIZER
17773                 (struct cmd_ptype_mapping_replace_result,
17774                  ptype, "ptype");
17775 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17776         TOKEN_STRING_INITIALIZER
17777                 (struct cmd_ptype_mapping_replace_result,
17778                  mapping, "mapping");
17779 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17780         TOKEN_STRING_INITIALIZER
17781                 (struct cmd_ptype_mapping_replace_result,
17782                  replace, "replace");
17783 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17784         TOKEN_NUM_INITIALIZER
17785                 (struct cmd_ptype_mapping_replace_result,
17786                  port_id, UINT16);
17787 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17788         TOKEN_NUM_INITIALIZER
17789                 (struct cmd_ptype_mapping_replace_result,
17790                  target, UINT32);
17791 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17792         TOKEN_NUM_INITIALIZER
17793                 (struct cmd_ptype_mapping_replace_result,
17794                  mask, UINT8);
17795 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17796         TOKEN_NUM_INITIALIZER
17797                 (struct cmd_ptype_mapping_replace_result,
17798                  pkt_type, UINT32);
17799
17800 static void
17801 cmd_ptype_mapping_replace_parsed(
17802         void *parsed_result,
17803         __rte_unused struct cmdline *cl,
17804         __rte_unused void *data)
17805 {
17806         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17807         int ret = -ENOTSUP;
17808
17809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17810                 return;
17811
17812 #ifdef RTE_LIBRTE_I40E_PMD
17813         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17814                                         res->target,
17815                                         res->mask,
17816                                         res->pkt_type);
17817 #endif
17818
17819         switch (ret) {
17820         case 0:
17821                 break;
17822         case -EINVAL:
17823                 printf("invalid ptype 0x%8x or 0x%8x\n",
17824                                 res->target, res->pkt_type);
17825                 break;
17826         case -ENODEV:
17827                 printf("invalid port_id %d\n", res->port_id);
17828                 break;
17829         case -ENOTSUP:
17830                 printf("function not implemented\n");
17831                 break;
17832         default:
17833                 printf("programming error: (%s)\n", strerror(-ret));
17834         }
17835 }
17836
17837 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17838         .f = cmd_ptype_mapping_replace_parsed,
17839         .data = NULL,
17840         .help_str =
17841                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17842         .tokens = {
17843                 (void *)&cmd_ptype_mapping_replace_ptype,
17844                 (void *)&cmd_ptype_mapping_replace_mapping,
17845                 (void *)&cmd_ptype_mapping_replace_replace,
17846                 (void *)&cmd_ptype_mapping_replace_port_id,
17847                 (void *)&cmd_ptype_mapping_replace_target,
17848                 (void *)&cmd_ptype_mapping_replace_mask,
17849                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17850                 NULL,
17851         },
17852 };
17853
17854 /* ptype mapping reset */
17855
17856 /* Common result structure for ptype mapping reset */
17857 struct cmd_ptype_mapping_reset_result {
17858         cmdline_fixed_string_t ptype;
17859         cmdline_fixed_string_t mapping;
17860         cmdline_fixed_string_t reset;
17861         portid_t port_id;
17862 };
17863
17864 /* Common CLI fields for ptype mapping reset*/
17865 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17866         TOKEN_STRING_INITIALIZER
17867                 (struct cmd_ptype_mapping_reset_result,
17868                  ptype, "ptype");
17869 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17870         TOKEN_STRING_INITIALIZER
17871                 (struct cmd_ptype_mapping_reset_result,
17872                  mapping, "mapping");
17873 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17874         TOKEN_STRING_INITIALIZER
17875                 (struct cmd_ptype_mapping_reset_result,
17876                  reset, "reset");
17877 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17878         TOKEN_NUM_INITIALIZER
17879                 (struct cmd_ptype_mapping_reset_result,
17880                  port_id, UINT16);
17881
17882 static void
17883 cmd_ptype_mapping_reset_parsed(
17884         void *parsed_result,
17885         __rte_unused struct cmdline *cl,
17886         __rte_unused void *data)
17887 {
17888         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17889         int ret = -ENOTSUP;
17890
17891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17892                 return;
17893
17894 #ifdef RTE_LIBRTE_I40E_PMD
17895         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17896 #endif
17897
17898         switch (ret) {
17899         case 0:
17900                 break;
17901         case -ENODEV:
17902                 printf("invalid port_id %d\n", res->port_id);
17903                 break;
17904         case -ENOTSUP:
17905                 printf("function not implemented\n");
17906                 break;
17907         default:
17908                 printf("programming error: (%s)\n", strerror(-ret));
17909         }
17910 }
17911
17912 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17913         .f = cmd_ptype_mapping_reset_parsed,
17914         .data = NULL,
17915         .help_str = "ptype mapping reset <port_id>",
17916         .tokens = {
17917                 (void *)&cmd_ptype_mapping_reset_ptype,
17918                 (void *)&cmd_ptype_mapping_reset_mapping,
17919                 (void *)&cmd_ptype_mapping_reset_reset,
17920                 (void *)&cmd_ptype_mapping_reset_port_id,
17921                 NULL,
17922         },
17923 };
17924
17925 /* ptype mapping update */
17926
17927 /* Common result structure for ptype mapping update */
17928 struct cmd_ptype_mapping_update_result {
17929         cmdline_fixed_string_t ptype;
17930         cmdline_fixed_string_t mapping;
17931         cmdline_fixed_string_t reset;
17932         portid_t port_id;
17933         uint8_t hw_ptype;
17934         uint32_t sw_ptype;
17935 };
17936
17937 /* Common CLI fields for ptype mapping update*/
17938 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17939         TOKEN_STRING_INITIALIZER
17940                 (struct cmd_ptype_mapping_update_result,
17941                  ptype, "ptype");
17942 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17943         TOKEN_STRING_INITIALIZER
17944                 (struct cmd_ptype_mapping_update_result,
17945                  mapping, "mapping");
17946 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17947         TOKEN_STRING_INITIALIZER
17948                 (struct cmd_ptype_mapping_update_result,
17949                  reset, "update");
17950 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17951         TOKEN_NUM_INITIALIZER
17952                 (struct cmd_ptype_mapping_update_result,
17953                  port_id, UINT16);
17954 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17955         TOKEN_NUM_INITIALIZER
17956                 (struct cmd_ptype_mapping_update_result,
17957                  hw_ptype, UINT8);
17958 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17959         TOKEN_NUM_INITIALIZER
17960                 (struct cmd_ptype_mapping_update_result,
17961                  sw_ptype, UINT32);
17962
17963 static void
17964 cmd_ptype_mapping_update_parsed(
17965         void *parsed_result,
17966         __rte_unused struct cmdline *cl,
17967         __rte_unused void *data)
17968 {
17969         struct cmd_ptype_mapping_update_result *res = parsed_result;
17970         int ret = -ENOTSUP;
17971 #ifdef RTE_LIBRTE_I40E_PMD
17972         struct rte_pmd_i40e_ptype_mapping mapping;
17973 #endif
17974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17975                 return;
17976
17977 #ifdef RTE_LIBRTE_I40E_PMD
17978         mapping.hw_ptype = res->hw_ptype;
17979         mapping.sw_ptype = res->sw_ptype;
17980         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17981                                                 &mapping,
17982                                                 1,
17983                                                 0);
17984 #endif
17985
17986         switch (ret) {
17987         case 0:
17988                 break;
17989         case -EINVAL:
17990                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17991                 break;
17992         case -ENODEV:
17993                 printf("invalid port_id %d\n", res->port_id);
17994                 break;
17995         case -ENOTSUP:
17996                 printf("function not implemented\n");
17997                 break;
17998         default:
17999                 printf("programming error: (%s)\n", strerror(-ret));
18000         }
18001 }
18002
18003 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18004         .f = cmd_ptype_mapping_update_parsed,
18005         .data = NULL,
18006         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18007         .tokens = {
18008                 (void *)&cmd_ptype_mapping_update_ptype,
18009                 (void *)&cmd_ptype_mapping_update_mapping,
18010                 (void *)&cmd_ptype_mapping_update_update,
18011                 (void *)&cmd_ptype_mapping_update_port_id,
18012                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18013                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18014                 NULL,
18015         },
18016 };
18017
18018 /* Common result structure for file commands */
18019 struct cmd_cmdfile_result {
18020         cmdline_fixed_string_t load;
18021         cmdline_fixed_string_t filename;
18022 };
18023
18024 /* Common CLI fields for file commands */
18025 cmdline_parse_token_string_t cmd_load_cmdfile =
18026         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18027 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18028         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18029
18030 static void
18031 cmd_load_from_file_parsed(
18032         void *parsed_result,
18033         __rte_unused struct cmdline *cl,
18034         __rte_unused void *data)
18035 {
18036         struct cmd_cmdfile_result *res = parsed_result;
18037
18038         cmdline_read_from_file(res->filename);
18039 }
18040
18041 cmdline_parse_inst_t cmd_load_from_file = {
18042         .f = cmd_load_from_file_parsed,
18043         .data = NULL,
18044         .help_str = "load <filename>",
18045         .tokens = {
18046                 (void *)&cmd_load_cmdfile,
18047                 (void *)&cmd_load_cmdfile_filename,
18048                 NULL,
18049         },
18050 };
18051
18052 /* Get Rx offloads capabilities */
18053 struct cmd_rx_offload_get_capa_result {
18054         cmdline_fixed_string_t show;
18055         cmdline_fixed_string_t port;
18056         portid_t port_id;
18057         cmdline_fixed_string_t rx_offload;
18058         cmdline_fixed_string_t capabilities;
18059 };
18060
18061 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18062         TOKEN_STRING_INITIALIZER
18063                 (struct cmd_rx_offload_get_capa_result,
18064                  show, "show");
18065 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18066         TOKEN_STRING_INITIALIZER
18067                 (struct cmd_rx_offload_get_capa_result,
18068                  port, "port");
18069 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18070         TOKEN_NUM_INITIALIZER
18071                 (struct cmd_rx_offload_get_capa_result,
18072                  port_id, UINT16);
18073 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18074         TOKEN_STRING_INITIALIZER
18075                 (struct cmd_rx_offload_get_capa_result,
18076                  rx_offload, "rx_offload");
18077 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18078         TOKEN_STRING_INITIALIZER
18079                 (struct cmd_rx_offload_get_capa_result,
18080                  capabilities, "capabilities");
18081
18082 static void
18083 print_rx_offloads(uint64_t offloads)
18084 {
18085         uint64_t single_offload;
18086         int begin;
18087         int end;
18088         int bit;
18089
18090         if (offloads == 0)
18091                 return;
18092
18093         begin = __builtin_ctzll(offloads);
18094         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18095
18096         single_offload = 1ULL << begin;
18097         for (bit = begin; bit < end; bit++) {
18098                 if (offloads & single_offload)
18099                         printf(" %s",
18100                                rte_eth_dev_rx_offload_name(single_offload));
18101                 single_offload <<= 1;
18102         }
18103 }
18104
18105 static void
18106 cmd_rx_offload_get_capa_parsed(
18107         void *parsed_result,
18108         __rte_unused struct cmdline *cl,
18109         __rte_unused void *data)
18110 {
18111         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18112         struct rte_eth_dev_info dev_info;
18113         portid_t port_id = res->port_id;
18114         uint64_t queue_offloads;
18115         uint64_t port_offloads;
18116         int ret;
18117
18118         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18119         if (ret != 0)
18120                 return;
18121
18122         queue_offloads = dev_info.rx_queue_offload_capa;
18123         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18124
18125         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18126         printf("  Per Queue :");
18127         print_rx_offloads(queue_offloads);
18128
18129         printf("\n");
18130         printf("  Per Port  :");
18131         print_rx_offloads(port_offloads);
18132         printf("\n\n");
18133 }
18134
18135 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18136         .f = cmd_rx_offload_get_capa_parsed,
18137         .data = NULL,
18138         .help_str = "show port <port_id> rx_offload capabilities",
18139         .tokens = {
18140                 (void *)&cmd_rx_offload_get_capa_show,
18141                 (void *)&cmd_rx_offload_get_capa_port,
18142                 (void *)&cmd_rx_offload_get_capa_port_id,
18143                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18144                 (void *)&cmd_rx_offload_get_capa_capabilities,
18145                 NULL,
18146         }
18147 };
18148
18149 /* Get Rx offloads configuration */
18150 struct cmd_rx_offload_get_configuration_result {
18151         cmdline_fixed_string_t show;
18152         cmdline_fixed_string_t port;
18153         portid_t port_id;
18154         cmdline_fixed_string_t rx_offload;
18155         cmdline_fixed_string_t configuration;
18156 };
18157
18158 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18159         TOKEN_STRING_INITIALIZER
18160                 (struct cmd_rx_offload_get_configuration_result,
18161                  show, "show");
18162 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18163         TOKEN_STRING_INITIALIZER
18164                 (struct cmd_rx_offload_get_configuration_result,
18165                  port, "port");
18166 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18167         TOKEN_NUM_INITIALIZER
18168                 (struct cmd_rx_offload_get_configuration_result,
18169                  port_id, UINT16);
18170 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18171         TOKEN_STRING_INITIALIZER
18172                 (struct cmd_rx_offload_get_configuration_result,
18173                  rx_offload, "rx_offload");
18174 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18175         TOKEN_STRING_INITIALIZER
18176                 (struct cmd_rx_offload_get_configuration_result,
18177                  configuration, "configuration");
18178
18179 static void
18180 cmd_rx_offload_get_configuration_parsed(
18181         void *parsed_result,
18182         __rte_unused struct cmdline *cl,
18183         __rte_unused void *data)
18184 {
18185         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18186         struct rte_eth_dev_info dev_info;
18187         portid_t port_id = res->port_id;
18188         struct rte_port *port = &ports[port_id];
18189         uint64_t port_offloads;
18190         uint64_t queue_offloads;
18191         uint16_t nb_rx_queues;
18192         int q;
18193         int ret;
18194
18195         printf("Rx Offloading Configuration of port %d :\n", port_id);
18196
18197         port_offloads = port->dev_conf.rxmode.offloads;
18198         printf("  Port :");
18199         print_rx_offloads(port_offloads);
18200         printf("\n");
18201
18202         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18203         if (ret != 0)
18204                 return;
18205
18206         nb_rx_queues = dev_info.nb_rx_queues;
18207         for (q = 0; q < nb_rx_queues; q++) {
18208                 queue_offloads = port->rx_conf[q].offloads;
18209                 printf("  Queue[%2d] :", q);
18210                 print_rx_offloads(queue_offloads);
18211                 printf("\n");
18212         }
18213         printf("\n");
18214 }
18215
18216 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18217         .f = cmd_rx_offload_get_configuration_parsed,
18218         .data = NULL,
18219         .help_str = "show port <port_id> rx_offload configuration",
18220         .tokens = {
18221                 (void *)&cmd_rx_offload_get_configuration_show,
18222                 (void *)&cmd_rx_offload_get_configuration_port,
18223                 (void *)&cmd_rx_offload_get_configuration_port_id,
18224                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18225                 (void *)&cmd_rx_offload_get_configuration_configuration,
18226                 NULL,
18227         }
18228 };
18229
18230 /* Enable/Disable a per port offloading */
18231 struct cmd_config_per_port_rx_offload_result {
18232         cmdline_fixed_string_t port;
18233         cmdline_fixed_string_t config;
18234         portid_t port_id;
18235         cmdline_fixed_string_t rx_offload;
18236         cmdline_fixed_string_t offload;
18237         cmdline_fixed_string_t on_off;
18238 };
18239
18240 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18241         TOKEN_STRING_INITIALIZER
18242                 (struct cmd_config_per_port_rx_offload_result,
18243                  port, "port");
18244 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18245         TOKEN_STRING_INITIALIZER
18246                 (struct cmd_config_per_port_rx_offload_result,
18247                  config, "config");
18248 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18249         TOKEN_NUM_INITIALIZER
18250                 (struct cmd_config_per_port_rx_offload_result,
18251                  port_id, UINT16);
18252 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18253         TOKEN_STRING_INITIALIZER
18254                 (struct cmd_config_per_port_rx_offload_result,
18255                  rx_offload, "rx_offload");
18256 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18257         TOKEN_STRING_INITIALIZER
18258                 (struct cmd_config_per_port_rx_offload_result,
18259                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18260                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18261                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18262                            "scatter#timestamp#security#keep_crc#rss_hash");
18263 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18264         TOKEN_STRING_INITIALIZER
18265                 (struct cmd_config_per_port_rx_offload_result,
18266                  on_off, "on#off");
18267
18268 static uint64_t
18269 search_rx_offload(const char *name)
18270 {
18271         uint64_t single_offload;
18272         const char *single_name;
18273         int found = 0;
18274         unsigned int bit;
18275
18276         single_offload = 1;
18277         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18278                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18279                 if (!strcasecmp(single_name, name)) {
18280                         found = 1;
18281                         break;
18282                 }
18283                 single_offload <<= 1;
18284         }
18285
18286         if (found)
18287                 return single_offload;
18288
18289         return 0;
18290 }
18291
18292 static void
18293 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18294                                 __rte_unused struct cmdline *cl,
18295                                 __rte_unused void *data)
18296 {
18297         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18298         portid_t port_id = res->port_id;
18299         struct rte_eth_dev_info dev_info;
18300         struct rte_port *port = &ports[port_id];
18301         uint64_t single_offload;
18302         uint16_t nb_rx_queues;
18303         int q;
18304         int ret;
18305
18306         if (port->port_status != RTE_PORT_STOPPED) {
18307                 printf("Error: Can't config offload when Port %d "
18308                        "is not stopped\n", port_id);
18309                 return;
18310         }
18311
18312         single_offload = search_rx_offload(res->offload);
18313         if (single_offload == 0) {
18314                 printf("Unknown offload name: %s\n", res->offload);
18315                 return;
18316         }
18317
18318         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18319         if (ret != 0)
18320                 return;
18321
18322         nb_rx_queues = dev_info.nb_rx_queues;
18323         if (!strcmp(res->on_off, "on")) {
18324                 port->dev_conf.rxmode.offloads |= single_offload;
18325                 for (q = 0; q < nb_rx_queues; q++)
18326                         port->rx_conf[q].offloads |= single_offload;
18327         } else {
18328                 port->dev_conf.rxmode.offloads &= ~single_offload;
18329                 for (q = 0; q < nb_rx_queues; q++)
18330                         port->rx_conf[q].offloads &= ~single_offload;
18331         }
18332
18333         cmd_reconfig_device_queue(port_id, 1, 1);
18334 }
18335
18336 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18337         .f = cmd_config_per_port_rx_offload_parsed,
18338         .data = NULL,
18339         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18340                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18341                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18342                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18343                     "on|off",
18344         .tokens = {
18345                 (void *)&cmd_config_per_port_rx_offload_result_port,
18346                 (void *)&cmd_config_per_port_rx_offload_result_config,
18347                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18348                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18349                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18350                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18351                 NULL,
18352         }
18353 };
18354
18355 /* Enable/Disable a per queue offloading */
18356 struct cmd_config_per_queue_rx_offload_result {
18357         cmdline_fixed_string_t port;
18358         portid_t port_id;
18359         cmdline_fixed_string_t rxq;
18360         uint16_t queue_id;
18361         cmdline_fixed_string_t rx_offload;
18362         cmdline_fixed_string_t offload;
18363         cmdline_fixed_string_t on_off;
18364 };
18365
18366 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18367         TOKEN_STRING_INITIALIZER
18368                 (struct cmd_config_per_queue_rx_offload_result,
18369                  port, "port");
18370 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18371         TOKEN_NUM_INITIALIZER
18372                 (struct cmd_config_per_queue_rx_offload_result,
18373                  port_id, UINT16);
18374 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18375         TOKEN_STRING_INITIALIZER
18376                 (struct cmd_config_per_queue_rx_offload_result,
18377                  rxq, "rxq");
18378 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18379         TOKEN_NUM_INITIALIZER
18380                 (struct cmd_config_per_queue_rx_offload_result,
18381                  queue_id, UINT16);
18382 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18383         TOKEN_STRING_INITIALIZER
18384                 (struct cmd_config_per_queue_rx_offload_result,
18385                  rx_offload, "rx_offload");
18386 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18387         TOKEN_STRING_INITIALIZER
18388                 (struct cmd_config_per_queue_rx_offload_result,
18389                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18390                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18391                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18392                            "scatter#timestamp#security#keep_crc");
18393 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18394         TOKEN_STRING_INITIALIZER
18395                 (struct cmd_config_per_queue_rx_offload_result,
18396                  on_off, "on#off");
18397
18398 static void
18399 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18400                                 __rte_unused struct cmdline *cl,
18401                                 __rte_unused void *data)
18402 {
18403         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18404         struct rte_eth_dev_info dev_info;
18405         portid_t port_id = res->port_id;
18406         uint16_t queue_id = res->queue_id;
18407         struct rte_port *port = &ports[port_id];
18408         uint64_t single_offload;
18409         int ret;
18410
18411         if (port->port_status != RTE_PORT_STOPPED) {
18412                 printf("Error: Can't config offload when Port %d "
18413                        "is not stopped\n", port_id);
18414                 return;
18415         }
18416
18417         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18418         if (ret != 0)
18419                 return;
18420
18421         if (queue_id >= dev_info.nb_rx_queues) {
18422                 printf("Error: input queue_id should be 0 ... "
18423                        "%d\n", dev_info.nb_rx_queues - 1);
18424                 return;
18425         }
18426
18427         single_offload = search_rx_offload(res->offload);
18428         if (single_offload == 0) {
18429                 printf("Unknown offload name: %s\n", res->offload);
18430                 return;
18431         }
18432
18433         if (!strcmp(res->on_off, "on"))
18434                 port->rx_conf[queue_id].offloads |= single_offload;
18435         else
18436                 port->rx_conf[queue_id].offloads &= ~single_offload;
18437
18438         cmd_reconfig_device_queue(port_id, 1, 1);
18439 }
18440
18441 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18442         .f = cmd_config_per_queue_rx_offload_parsed,
18443         .data = NULL,
18444         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18445                     "vlan_strip|ipv4_cksum|"
18446                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18447                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18448                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18449                     "on|off",
18450         .tokens = {
18451                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18452                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18453                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18454                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18455                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18456                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18457                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18458                 NULL,
18459         }
18460 };
18461
18462 /* Get Tx offloads capabilities */
18463 struct cmd_tx_offload_get_capa_result {
18464         cmdline_fixed_string_t show;
18465         cmdline_fixed_string_t port;
18466         portid_t port_id;
18467         cmdline_fixed_string_t tx_offload;
18468         cmdline_fixed_string_t capabilities;
18469 };
18470
18471 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18472         TOKEN_STRING_INITIALIZER
18473                 (struct cmd_tx_offload_get_capa_result,
18474                  show, "show");
18475 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18476         TOKEN_STRING_INITIALIZER
18477                 (struct cmd_tx_offload_get_capa_result,
18478                  port, "port");
18479 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18480         TOKEN_NUM_INITIALIZER
18481                 (struct cmd_tx_offload_get_capa_result,
18482                  port_id, UINT16);
18483 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18484         TOKEN_STRING_INITIALIZER
18485                 (struct cmd_tx_offload_get_capa_result,
18486                  tx_offload, "tx_offload");
18487 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18488         TOKEN_STRING_INITIALIZER
18489                 (struct cmd_tx_offload_get_capa_result,
18490                  capabilities, "capabilities");
18491
18492 static void
18493 print_tx_offloads(uint64_t offloads)
18494 {
18495         uint64_t single_offload;
18496         int begin;
18497         int end;
18498         int bit;
18499
18500         if (offloads == 0)
18501                 return;
18502
18503         begin = __builtin_ctzll(offloads);
18504         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18505
18506         single_offload = 1ULL << begin;
18507         for (bit = begin; bit < end; bit++) {
18508                 if (offloads & single_offload)
18509                         printf(" %s",
18510                                rte_eth_dev_tx_offload_name(single_offload));
18511                 single_offload <<= 1;
18512         }
18513 }
18514
18515 static void
18516 cmd_tx_offload_get_capa_parsed(
18517         void *parsed_result,
18518         __rte_unused struct cmdline *cl,
18519         __rte_unused void *data)
18520 {
18521         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18522         struct rte_eth_dev_info dev_info;
18523         portid_t port_id = res->port_id;
18524         uint64_t queue_offloads;
18525         uint64_t port_offloads;
18526         int ret;
18527
18528         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18529         if (ret != 0)
18530                 return;
18531
18532         queue_offloads = dev_info.tx_queue_offload_capa;
18533         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18534
18535         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18536         printf("  Per Queue :");
18537         print_tx_offloads(queue_offloads);
18538
18539         printf("\n");
18540         printf("  Per Port  :");
18541         print_tx_offloads(port_offloads);
18542         printf("\n\n");
18543 }
18544
18545 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18546         .f = cmd_tx_offload_get_capa_parsed,
18547         .data = NULL,
18548         .help_str = "show port <port_id> tx_offload capabilities",
18549         .tokens = {
18550                 (void *)&cmd_tx_offload_get_capa_show,
18551                 (void *)&cmd_tx_offload_get_capa_port,
18552                 (void *)&cmd_tx_offload_get_capa_port_id,
18553                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18554                 (void *)&cmd_tx_offload_get_capa_capabilities,
18555                 NULL,
18556         }
18557 };
18558
18559 /* Get Tx offloads configuration */
18560 struct cmd_tx_offload_get_configuration_result {
18561         cmdline_fixed_string_t show;
18562         cmdline_fixed_string_t port;
18563         portid_t port_id;
18564         cmdline_fixed_string_t tx_offload;
18565         cmdline_fixed_string_t configuration;
18566 };
18567
18568 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18569         TOKEN_STRING_INITIALIZER
18570                 (struct cmd_tx_offload_get_configuration_result,
18571                  show, "show");
18572 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18573         TOKEN_STRING_INITIALIZER
18574                 (struct cmd_tx_offload_get_configuration_result,
18575                  port, "port");
18576 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18577         TOKEN_NUM_INITIALIZER
18578                 (struct cmd_tx_offload_get_configuration_result,
18579                  port_id, UINT16);
18580 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18581         TOKEN_STRING_INITIALIZER
18582                 (struct cmd_tx_offload_get_configuration_result,
18583                  tx_offload, "tx_offload");
18584 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18585         TOKEN_STRING_INITIALIZER
18586                 (struct cmd_tx_offload_get_configuration_result,
18587                  configuration, "configuration");
18588
18589 static void
18590 cmd_tx_offload_get_configuration_parsed(
18591         void *parsed_result,
18592         __rte_unused struct cmdline *cl,
18593         __rte_unused void *data)
18594 {
18595         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18596         struct rte_eth_dev_info dev_info;
18597         portid_t port_id = res->port_id;
18598         struct rte_port *port = &ports[port_id];
18599         uint64_t port_offloads;
18600         uint64_t queue_offloads;
18601         uint16_t nb_tx_queues;
18602         int q;
18603         int ret;
18604
18605         printf("Tx Offloading Configuration of port %d :\n", port_id);
18606
18607         port_offloads = port->dev_conf.txmode.offloads;
18608         printf("  Port :");
18609         print_tx_offloads(port_offloads);
18610         printf("\n");
18611
18612         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18613         if (ret != 0)
18614                 return;
18615
18616         nb_tx_queues = dev_info.nb_tx_queues;
18617         for (q = 0; q < nb_tx_queues; q++) {
18618                 queue_offloads = port->tx_conf[q].offloads;
18619                 printf("  Queue[%2d] :", q);
18620                 print_tx_offloads(queue_offloads);
18621                 printf("\n");
18622         }
18623         printf("\n");
18624 }
18625
18626 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18627         .f = cmd_tx_offload_get_configuration_parsed,
18628         .data = NULL,
18629         .help_str = "show port <port_id> tx_offload configuration",
18630         .tokens = {
18631                 (void *)&cmd_tx_offload_get_configuration_show,
18632                 (void *)&cmd_tx_offload_get_configuration_port,
18633                 (void *)&cmd_tx_offload_get_configuration_port_id,
18634                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18635                 (void *)&cmd_tx_offload_get_configuration_configuration,
18636                 NULL,
18637         }
18638 };
18639
18640 /* Enable/Disable a per port offloading */
18641 struct cmd_config_per_port_tx_offload_result {
18642         cmdline_fixed_string_t port;
18643         cmdline_fixed_string_t config;
18644         portid_t port_id;
18645         cmdline_fixed_string_t tx_offload;
18646         cmdline_fixed_string_t offload;
18647         cmdline_fixed_string_t on_off;
18648 };
18649
18650 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18651         TOKEN_STRING_INITIALIZER
18652                 (struct cmd_config_per_port_tx_offload_result,
18653                  port, "port");
18654 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18655         TOKEN_STRING_INITIALIZER
18656                 (struct cmd_config_per_port_tx_offload_result,
18657                  config, "config");
18658 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18659         TOKEN_NUM_INITIALIZER
18660                 (struct cmd_config_per_port_tx_offload_result,
18661                  port_id, UINT16);
18662 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18663         TOKEN_STRING_INITIALIZER
18664                 (struct cmd_config_per_port_tx_offload_result,
18665                  tx_offload, "tx_offload");
18666 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18667         TOKEN_STRING_INITIALIZER
18668                 (struct cmd_config_per_port_tx_offload_result,
18669                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18670                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18671                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18672                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18673                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18674 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18675         TOKEN_STRING_INITIALIZER
18676                 (struct cmd_config_per_port_tx_offload_result,
18677                  on_off, "on#off");
18678
18679 static uint64_t
18680 search_tx_offload(const char *name)
18681 {
18682         uint64_t single_offload;
18683         const char *single_name;
18684         int found = 0;
18685         unsigned int bit;
18686
18687         single_offload = 1;
18688         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18689                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18690                 if (single_name == NULL)
18691                         break;
18692                 if (!strcasecmp(single_name, name)) {
18693                         found = 1;
18694                         break;
18695                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18696                         break;
18697                 single_offload <<= 1;
18698         }
18699
18700         if (found)
18701                 return single_offload;
18702
18703         return 0;
18704 }
18705
18706 static void
18707 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18708                                 __rte_unused struct cmdline *cl,
18709                                 __rte_unused void *data)
18710 {
18711         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18712         portid_t port_id = res->port_id;
18713         struct rte_eth_dev_info dev_info;
18714         struct rte_port *port = &ports[port_id];
18715         uint64_t single_offload;
18716         uint16_t nb_tx_queues;
18717         int q;
18718         int ret;
18719
18720         if (port->port_status != RTE_PORT_STOPPED) {
18721                 printf("Error: Can't config offload when Port %d "
18722                        "is not stopped\n", port_id);
18723                 return;
18724         }
18725
18726         single_offload = search_tx_offload(res->offload);
18727         if (single_offload == 0) {
18728                 printf("Unknown offload name: %s\n", res->offload);
18729                 return;
18730         }
18731
18732         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18733         if (ret != 0)
18734                 return;
18735
18736         nb_tx_queues = dev_info.nb_tx_queues;
18737         if (!strcmp(res->on_off, "on")) {
18738                 port->dev_conf.txmode.offloads |= single_offload;
18739                 for (q = 0; q < nb_tx_queues; q++)
18740                         port->tx_conf[q].offloads |= single_offload;
18741         } else {
18742                 port->dev_conf.txmode.offloads &= ~single_offload;
18743                 for (q = 0; q < nb_tx_queues; q++)
18744                         port->tx_conf[q].offloads &= ~single_offload;
18745         }
18746
18747         cmd_reconfig_device_queue(port_id, 1, 1);
18748 }
18749
18750 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18751         .f = cmd_config_per_port_tx_offload_parsed,
18752         .data = NULL,
18753         .help_str = "port config <port_id> tx_offload "
18754                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18755                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18756                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18757                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18758                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18759         .tokens = {
18760                 (void *)&cmd_config_per_port_tx_offload_result_port,
18761                 (void *)&cmd_config_per_port_tx_offload_result_config,
18762                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18763                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18764                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18765                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18766                 NULL,
18767         }
18768 };
18769
18770 /* Enable/Disable a per queue offloading */
18771 struct cmd_config_per_queue_tx_offload_result {
18772         cmdline_fixed_string_t port;
18773         portid_t port_id;
18774         cmdline_fixed_string_t txq;
18775         uint16_t queue_id;
18776         cmdline_fixed_string_t tx_offload;
18777         cmdline_fixed_string_t offload;
18778         cmdline_fixed_string_t on_off;
18779 };
18780
18781 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18782         TOKEN_STRING_INITIALIZER
18783                 (struct cmd_config_per_queue_tx_offload_result,
18784                  port, "port");
18785 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18786         TOKEN_NUM_INITIALIZER
18787                 (struct cmd_config_per_queue_tx_offload_result,
18788                  port_id, UINT16);
18789 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18790         TOKEN_STRING_INITIALIZER
18791                 (struct cmd_config_per_queue_tx_offload_result,
18792                  txq, "txq");
18793 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18794         TOKEN_NUM_INITIALIZER
18795                 (struct cmd_config_per_queue_tx_offload_result,
18796                  queue_id, UINT16);
18797 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18798         TOKEN_STRING_INITIALIZER
18799                 (struct cmd_config_per_queue_tx_offload_result,
18800                  tx_offload, "tx_offload");
18801 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18802         TOKEN_STRING_INITIALIZER
18803                 (struct cmd_config_per_queue_tx_offload_result,
18804                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18805                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18806                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18807                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18808                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18809 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18810         TOKEN_STRING_INITIALIZER
18811                 (struct cmd_config_per_queue_tx_offload_result,
18812                  on_off, "on#off");
18813
18814 static void
18815 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18816                                 __rte_unused struct cmdline *cl,
18817                                 __rte_unused void *data)
18818 {
18819         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18820         struct rte_eth_dev_info dev_info;
18821         portid_t port_id = res->port_id;
18822         uint16_t queue_id = res->queue_id;
18823         struct rte_port *port = &ports[port_id];
18824         uint64_t single_offload;
18825         int ret;
18826
18827         if (port->port_status != RTE_PORT_STOPPED) {
18828                 printf("Error: Can't config offload when Port %d "
18829                        "is not stopped\n", port_id);
18830                 return;
18831         }
18832
18833         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18834         if (ret != 0)
18835                 return;
18836
18837         if (queue_id >= dev_info.nb_tx_queues) {
18838                 printf("Error: input queue_id should be 0 ... "
18839                        "%d\n", dev_info.nb_tx_queues - 1);
18840                 return;
18841         }
18842
18843         single_offload = search_tx_offload(res->offload);
18844         if (single_offload == 0) {
18845                 printf("Unknown offload name: %s\n", res->offload);
18846                 return;
18847         }
18848
18849         if (!strcmp(res->on_off, "on"))
18850                 port->tx_conf[queue_id].offloads |= single_offload;
18851         else
18852                 port->tx_conf[queue_id].offloads &= ~single_offload;
18853
18854         cmd_reconfig_device_queue(port_id, 1, 1);
18855 }
18856
18857 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18858         .f = cmd_config_per_queue_tx_offload_parsed,
18859         .data = NULL,
18860         .help_str = "port <port_id> txq <queue_id> tx_offload "
18861                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18862                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18863                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18864                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18865                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18866                     "on|off",
18867         .tokens = {
18868                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18869                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18870                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18871                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18872                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18873                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18874                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18875                 NULL,
18876         }
18877 };
18878
18879 /* *** configure tx_metadata for specific port *** */
18880 struct cmd_config_tx_metadata_specific_result {
18881         cmdline_fixed_string_t port;
18882         cmdline_fixed_string_t keyword;
18883         uint16_t port_id;
18884         cmdline_fixed_string_t item;
18885         uint32_t value;
18886 };
18887
18888 static void
18889 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18890                                 __rte_unused struct cmdline *cl,
18891                                 __rte_unused void *data)
18892 {
18893         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18894
18895         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18896                 return;
18897         ports[res->port_id].tx_metadata = res->value;
18898         /* Add/remove callback to insert valid metadata in every Tx packet. */
18899         if (ports[res->port_id].tx_metadata)
18900                 add_tx_md_callback(res->port_id);
18901         else
18902                 remove_tx_md_callback(res->port_id);
18903         rte_flow_dynf_metadata_register();
18904 }
18905
18906 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18907         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18908                         port, "port");
18909 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18910         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18911                         keyword, "config");
18912 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18913         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18914                         port_id, UINT16);
18915 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18916         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18917                         item, "tx_metadata");
18918 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18919         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18920                         value, UINT32);
18921
18922 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18923         .f = cmd_config_tx_metadata_specific_parsed,
18924         .data = NULL,
18925         .help_str = "port config <port_id> tx_metadata <value>",
18926         .tokens = {
18927                 (void *)&cmd_config_tx_metadata_specific_port,
18928                 (void *)&cmd_config_tx_metadata_specific_keyword,
18929                 (void *)&cmd_config_tx_metadata_specific_id,
18930                 (void *)&cmd_config_tx_metadata_specific_item,
18931                 (void *)&cmd_config_tx_metadata_specific_value,
18932                 NULL,
18933         },
18934 };
18935
18936 /* *** set dynf *** */
18937 struct cmd_config_tx_dynf_specific_result {
18938         cmdline_fixed_string_t port;
18939         cmdline_fixed_string_t keyword;
18940         uint16_t port_id;
18941         cmdline_fixed_string_t item;
18942         cmdline_fixed_string_t name;
18943         cmdline_fixed_string_t value;
18944 };
18945
18946 static void
18947 cmd_config_dynf_specific_parsed(void *parsed_result,
18948                                 __rte_unused struct cmdline *cl,
18949                                 __rte_unused void *data)
18950 {
18951         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18952         struct rte_mbuf_dynflag desc_flag;
18953         int flag;
18954         uint64_t old_port_flags;
18955
18956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18957                 return;
18958         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18959         if (flag <= 0) {
18960                 if (strlcpy(desc_flag.name, res->name,
18961                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18962                         printf("Flag name too long\n");
18963                         return;
18964                 }
18965                 desc_flag.flags = 0;
18966                 flag = rte_mbuf_dynflag_register(&desc_flag);
18967                 if (flag < 0) {
18968                         printf("Can't register flag\n");
18969                         return;
18970                 }
18971                 strcpy(dynf_names[flag], desc_flag.name);
18972         }
18973         old_port_flags = ports[res->port_id].mbuf_dynf;
18974         if (!strcmp(res->value, "set")) {
18975                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18976                 if (old_port_flags == 0)
18977                         add_tx_dynf_callback(res->port_id);
18978         } else {
18979                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18980                 if (ports[res->port_id].mbuf_dynf == 0)
18981                         remove_tx_dynf_callback(res->port_id);
18982         }
18983 }
18984
18985 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18986         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18987                         keyword, "port");
18988 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18989         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18990                         keyword, "config");
18991 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18992         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18993                         port_id, UINT16);
18994 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18995         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18996                         item, "dynf");
18997 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18998         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18999                         name, NULL);
19000 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19001         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19002                         value, "set#clear");
19003
19004 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19005         .f = cmd_config_dynf_specific_parsed,
19006         .data = NULL,
19007         .help_str = "port config <port id> dynf <name> set|clear",
19008         .tokens = {
19009                 (void *)&cmd_config_tx_dynf_specific_port,
19010                 (void *)&cmd_config_tx_dynf_specific_keyword,
19011                 (void *)&cmd_config_tx_dynf_specific_port_id,
19012                 (void *)&cmd_config_tx_dynf_specific_item,
19013                 (void *)&cmd_config_tx_dynf_specific_name,
19014                 (void *)&cmd_config_tx_dynf_specific_value,
19015                 NULL,
19016         },
19017 };
19018
19019 /* *** display tx_metadata per port configuration *** */
19020 struct cmd_show_tx_metadata_result {
19021         cmdline_fixed_string_t cmd_show;
19022         cmdline_fixed_string_t cmd_port;
19023         cmdline_fixed_string_t cmd_keyword;
19024         portid_t cmd_pid;
19025 };
19026
19027 static void
19028 cmd_show_tx_metadata_parsed(void *parsed_result,
19029                 __rte_unused struct cmdline *cl,
19030                 __rte_unused void *data)
19031 {
19032         struct cmd_show_tx_metadata_result *res = parsed_result;
19033
19034         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19035                 printf("invalid port id %u\n", res->cmd_pid);
19036                 return;
19037         }
19038         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19039                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19040                        ports[res->cmd_pid].tx_metadata);
19041         }
19042 }
19043
19044 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19045         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19046                         cmd_show, "show");
19047 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19048         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19049                         cmd_port, "port");
19050 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19051         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19052                         cmd_pid, UINT16);
19053 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19054         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19055                         cmd_keyword, "tx_metadata");
19056
19057 cmdline_parse_inst_t cmd_show_tx_metadata = {
19058         .f = cmd_show_tx_metadata_parsed,
19059         .data = NULL,
19060         .help_str = "show port <port_id> tx_metadata",
19061         .tokens = {
19062                 (void *)&cmd_show_tx_metadata_show,
19063                 (void *)&cmd_show_tx_metadata_port,
19064                 (void *)&cmd_show_tx_metadata_pid,
19065                 (void *)&cmd_show_tx_metadata_keyword,
19066                 NULL,
19067         },
19068 };
19069
19070 /* show port supported ptypes */
19071
19072 /* Common result structure for show port ptypes */
19073 struct cmd_show_port_supported_ptypes_result {
19074         cmdline_fixed_string_t show;
19075         cmdline_fixed_string_t port;
19076         portid_t port_id;
19077         cmdline_fixed_string_t ptypes;
19078 };
19079
19080 /* Common CLI fields for show port ptypes */
19081 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19082         TOKEN_STRING_INITIALIZER
19083                 (struct cmd_show_port_supported_ptypes_result,
19084                  show, "show");
19085 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19086         TOKEN_STRING_INITIALIZER
19087                 (struct cmd_show_port_supported_ptypes_result,
19088                  port, "port");
19089 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19090         TOKEN_NUM_INITIALIZER
19091                 (struct cmd_show_port_supported_ptypes_result,
19092                  port_id, UINT16);
19093 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19094         TOKEN_STRING_INITIALIZER
19095                 (struct cmd_show_port_supported_ptypes_result,
19096                  ptypes, "ptypes");
19097
19098 static void
19099 cmd_show_port_supported_ptypes_parsed(
19100         void *parsed_result,
19101         __rte_unused struct cmdline *cl,
19102         __rte_unused void *data)
19103 {
19104 #define RSVD_PTYPE_MASK       0xf0000000
19105 #define MAX_PTYPES_PER_LAYER  16
19106 #define LTYPE_NAMESIZE        32
19107 #define PTYPE_NAMESIZE        256
19108         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19109         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19110         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19111         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19112         uint16_t port_id = res->port_id;
19113         int ret, i;
19114
19115         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19116         if (ret < 0)
19117                 return;
19118
19119         while (ptype_mask != RSVD_PTYPE_MASK) {
19120
19121                 switch (ptype_mask) {
19122                 case RTE_PTYPE_L2_MASK:
19123                         strlcpy(ltype, "L2", sizeof(ltype));
19124                         break;
19125                 case RTE_PTYPE_L3_MASK:
19126                         strlcpy(ltype, "L3", sizeof(ltype));
19127                         break;
19128                 case RTE_PTYPE_L4_MASK:
19129                         strlcpy(ltype, "L4", sizeof(ltype));
19130                         break;
19131                 case RTE_PTYPE_TUNNEL_MASK:
19132                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19133                         break;
19134                 case RTE_PTYPE_INNER_L2_MASK:
19135                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19136                         break;
19137                 case RTE_PTYPE_INNER_L3_MASK:
19138                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19139                         break;
19140                 case RTE_PTYPE_INNER_L4_MASK:
19141                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19142                         break;
19143                 default:
19144                         return;
19145                 }
19146
19147                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19148                                                        ptype_mask, ptypes,
19149                                                        MAX_PTYPES_PER_LAYER);
19150
19151                 if (ret > 0)
19152                         printf("Supported %s ptypes:\n", ltype);
19153                 else
19154                         printf("%s ptypes unsupported\n", ltype);
19155
19156                 for (i = 0; i < ret; ++i) {
19157                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19158                         printf("%s\n", buf);
19159                 }
19160
19161                 ptype_mask <<= 4;
19162         }
19163 }
19164
19165 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19166         .f = cmd_show_port_supported_ptypes_parsed,
19167         .data = NULL,
19168         .help_str = "show port <port_id> ptypes",
19169         .tokens = {
19170                 (void *)&cmd_show_port_supported_ptypes_show,
19171                 (void *)&cmd_show_port_supported_ptypes_port,
19172                 (void *)&cmd_show_port_supported_ptypes_port_id,
19173                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19174                 NULL,
19175         },
19176 };
19177
19178 /* *** display rx/tx descriptor status *** */
19179 struct cmd_show_rx_tx_desc_status_result {
19180         cmdline_fixed_string_t cmd_show;
19181         cmdline_fixed_string_t cmd_port;
19182         cmdline_fixed_string_t cmd_keyword;
19183         cmdline_fixed_string_t cmd_desc;
19184         cmdline_fixed_string_t cmd_status;
19185         portid_t cmd_pid;
19186         portid_t cmd_qid;
19187         portid_t cmd_did;
19188 };
19189
19190 static void
19191 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19192                 __rte_unused struct cmdline *cl,
19193                 __rte_unused void *data)
19194 {
19195         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19196         int rc;
19197
19198         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19199                 printf("invalid port id %u\n", res->cmd_pid);
19200                 return;
19201         }
19202
19203         if (!strcmp(res->cmd_keyword, "rxq")) {
19204                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19205                                              res->cmd_did);
19206                 if (rc < 0) {
19207                         printf("Invalid queueid = %d\n", res->cmd_qid);
19208                         return;
19209                 }
19210                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19211                         printf("Desc status = AVAILABLE\n");
19212                 else if (rc == RTE_ETH_RX_DESC_DONE)
19213                         printf("Desc status = DONE\n");
19214                 else
19215                         printf("Desc status = UNAVAILABLE\n");
19216         } else if (!strcmp(res->cmd_keyword, "txq")) {
19217                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19218                                              res->cmd_did);
19219                 if (rc < 0) {
19220                         printf("Invalid queueid = %d\n", res->cmd_qid);
19221                         return;
19222                 }
19223                 if (rc == RTE_ETH_TX_DESC_FULL)
19224                         printf("Desc status = FULL\n");
19225                 else if (rc == RTE_ETH_TX_DESC_DONE)
19226                         printf("Desc status = DONE\n");
19227                 else
19228                         printf("Desc status = UNAVAILABLE\n");
19229         }
19230 }
19231
19232 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19233         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19234                         cmd_show, "show");
19235 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19236         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19237                         cmd_port, "port");
19238 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19239         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19240                         cmd_pid, UINT16);
19241 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19242         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19243                         cmd_keyword, "rxq#txq");
19244 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19245         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19246                         cmd_qid, UINT16);
19247 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19248         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19249                         cmd_desc, "desc");
19250 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19251         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19252                         cmd_did, UINT16);
19253 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19254         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19255                         cmd_status, "status");
19256 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19257         .f = cmd_show_rx_tx_desc_status_parsed,
19258         .data = NULL,
19259         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19260                 "status",
19261         .tokens = {
19262                 (void *)&cmd_show_rx_tx_desc_status_show,
19263                 (void *)&cmd_show_rx_tx_desc_status_port,
19264                 (void *)&cmd_show_rx_tx_desc_status_pid,
19265                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19266                 (void *)&cmd_show_rx_tx_desc_status_qid,
19267                 (void *)&cmd_show_rx_tx_desc_status_desc,
19268                 (void *)&cmd_show_rx_tx_desc_status_did,
19269                 (void *)&cmd_show_rx_tx_desc_status_status,
19270                 NULL,
19271         },
19272 };
19273
19274 /* Common result structure for set port ptypes */
19275 struct cmd_set_port_ptypes_result {
19276         cmdline_fixed_string_t set;
19277         cmdline_fixed_string_t port;
19278         portid_t port_id;
19279         cmdline_fixed_string_t ptype_mask;
19280         uint32_t mask;
19281 };
19282
19283 /* Common CLI fields for set port ptypes */
19284 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19285         TOKEN_STRING_INITIALIZER
19286                 (struct cmd_set_port_ptypes_result,
19287                  set, "set");
19288 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19289         TOKEN_STRING_INITIALIZER
19290                 (struct cmd_set_port_ptypes_result,
19291                  port, "port");
19292 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19293         TOKEN_NUM_INITIALIZER
19294                 (struct cmd_set_port_ptypes_result,
19295                  port_id, UINT16);
19296 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19297         TOKEN_STRING_INITIALIZER
19298                 (struct cmd_set_port_ptypes_result,
19299                  ptype_mask, "ptype_mask");
19300 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19301         TOKEN_NUM_INITIALIZER
19302                 (struct cmd_set_port_ptypes_result,
19303                  mask, UINT32);
19304
19305 static void
19306 cmd_set_port_ptypes_parsed(
19307         void *parsed_result,
19308         __rte_unused struct cmdline *cl,
19309         __rte_unused void *data)
19310 {
19311         struct cmd_set_port_ptypes_result *res = parsed_result;
19312 #define PTYPE_NAMESIZE        256
19313         char ptype_name[PTYPE_NAMESIZE];
19314         uint16_t port_id = res->port_id;
19315         uint32_t ptype_mask = res->mask;
19316         int ret, i;
19317
19318         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19319                                                NULL, 0);
19320         if (ret <= 0) {
19321                 printf("Port %d doesn't support any ptypes.\n", port_id);
19322                 return;
19323         }
19324
19325         uint32_t ptypes[ret];
19326
19327         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19328         if (ret < 0) {
19329                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19330                 return;
19331         }
19332
19333         printf("Successfully set following ptypes for Port %d\n", port_id);
19334         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19335                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19336                 printf("%s\n", ptype_name);
19337         }
19338
19339         clear_ptypes = false;
19340 }
19341
19342 cmdline_parse_inst_t cmd_set_port_ptypes = {
19343         .f = cmd_set_port_ptypes_parsed,
19344         .data = NULL,
19345         .help_str = "set port <port_id> ptype_mask <mask>",
19346         .tokens = {
19347                 (void *)&cmd_set_port_ptypes_set,
19348                 (void *)&cmd_set_port_ptypes_port,
19349                 (void *)&cmd_set_port_ptypes_port_id,
19350                 (void *)&cmd_set_port_ptypes_mask_str,
19351                 (void *)&cmd_set_port_ptypes_mask_u32,
19352                 NULL,
19353         },
19354 };
19355
19356 /* *** display mac addresses added to a port *** */
19357 struct cmd_showport_macs_result {
19358         cmdline_fixed_string_t cmd_show;
19359         cmdline_fixed_string_t cmd_port;
19360         cmdline_fixed_string_t cmd_keyword;
19361         portid_t cmd_pid;
19362 };
19363
19364 static void
19365 cmd_showport_macs_parsed(void *parsed_result,
19366                 __rte_unused struct cmdline *cl,
19367                 __rte_unused void *data)
19368 {
19369         struct cmd_showport_macs_result *res = parsed_result;
19370
19371         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19372                 return;
19373
19374         if (!strcmp(res->cmd_keyword, "macs"))
19375                 show_macs(res->cmd_pid);
19376         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19377                 show_mcast_macs(res->cmd_pid);
19378 }
19379
19380 cmdline_parse_token_string_t cmd_showport_macs_show =
19381         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19382                         cmd_show, "show");
19383 cmdline_parse_token_string_t cmd_showport_macs_port =
19384         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19385                         cmd_port, "port");
19386 cmdline_parse_token_num_t cmd_showport_macs_pid =
19387         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19388                         cmd_pid, UINT16);
19389 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19390         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19391                         cmd_keyword, "macs#mcast_macs");
19392
19393 cmdline_parse_inst_t cmd_showport_macs = {
19394         .f = cmd_showport_macs_parsed,
19395         .data = NULL,
19396         .help_str = "show port <port_id> macs|mcast_macs",
19397         .tokens = {
19398                 (void *)&cmd_showport_macs_show,
19399                 (void *)&cmd_showport_macs_port,
19400                 (void *)&cmd_showport_macs_pid,
19401                 (void *)&cmd_showport_macs_keyword,
19402                 NULL,
19403         },
19404 };
19405
19406 /* ******************************************************************************** */
19407
19408 /* list of instructions */
19409 cmdline_parse_ctx_t main_ctx[] = {
19410         (cmdline_parse_inst_t *)&cmd_help_brief,
19411         (cmdline_parse_inst_t *)&cmd_help_long,
19412         (cmdline_parse_inst_t *)&cmd_quit,
19413         (cmdline_parse_inst_t *)&cmd_load_from_file,
19414         (cmdline_parse_inst_t *)&cmd_showport,
19415         (cmdline_parse_inst_t *)&cmd_showqueue,
19416         (cmdline_parse_inst_t *)&cmd_showportall,
19417         (cmdline_parse_inst_t *)&cmd_showdevice,
19418         (cmdline_parse_inst_t *)&cmd_showcfg,
19419         (cmdline_parse_inst_t *)&cmd_showfwdall,
19420         (cmdline_parse_inst_t *)&cmd_start,
19421         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19422         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19423         (cmdline_parse_inst_t *)&cmd_set_link_up,
19424         (cmdline_parse_inst_t *)&cmd_set_link_down,
19425         (cmdline_parse_inst_t *)&cmd_reset,
19426         (cmdline_parse_inst_t *)&cmd_set_numbers,
19427         (cmdline_parse_inst_t *)&cmd_set_log,
19428         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19429         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19430         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19431         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19432         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19433         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19434         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19435         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19436         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19437         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19438         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19439         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19440         (cmdline_parse_inst_t *)&cmd_set_link_check,
19441         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19442         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19443         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19444         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19445 #ifdef RTE_LIBRTE_PMD_BOND
19446         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19447         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19448         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19449         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19450         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19451         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19452         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19453         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19454         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19455         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19456         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19457 #endif
19458         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19459         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19460         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19461         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19462         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19463         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19464         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19465         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19466         (cmdline_parse_inst_t *)&cmd_csum_set,
19467         (cmdline_parse_inst_t *)&cmd_csum_show,
19468         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19469         (cmdline_parse_inst_t *)&cmd_tso_set,
19470         (cmdline_parse_inst_t *)&cmd_tso_show,
19471         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19472         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19473         (cmdline_parse_inst_t *)&cmd_gro_enable,
19474         (cmdline_parse_inst_t *)&cmd_gro_flush,
19475         (cmdline_parse_inst_t *)&cmd_gro_show,
19476         (cmdline_parse_inst_t *)&cmd_gso_enable,
19477         (cmdline_parse_inst_t *)&cmd_gso_size,
19478         (cmdline_parse_inst_t *)&cmd_gso_show,
19479         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19480         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19481         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19482         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19483         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19484         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19485         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19486         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19487         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19488         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19489         (cmdline_parse_inst_t *)&cmd_config_dcb,
19490         (cmdline_parse_inst_t *)&cmd_read_reg,
19491         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19492         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19493         (cmdline_parse_inst_t *)&cmd_write_reg,
19494         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19495         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19496         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19497         (cmdline_parse_inst_t *)&cmd_stop,
19498         (cmdline_parse_inst_t *)&cmd_mac_addr,
19499         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19500         (cmdline_parse_inst_t *)&cmd_set_qmap,
19501         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19502         (cmdline_parse_inst_t *)&cmd_operate_port,
19503         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19504         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19505         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19506         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19507         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19508         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19509         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19510         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19511         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19512         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19513         (cmdline_parse_inst_t *)&cmd_config_mtu,
19514         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19515         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19516         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19517         (cmdline_parse_inst_t *)&cmd_config_rss,
19518         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19519         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19520         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19521         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19522         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19523         (cmdline_parse_inst_t *)&cmd_showport_reta,
19524         (cmdline_parse_inst_t *)&cmd_showport_macs,
19525         (cmdline_parse_inst_t *)&cmd_config_burst,
19526         (cmdline_parse_inst_t *)&cmd_config_thresh,
19527         (cmdline_parse_inst_t *)&cmd_config_threshold,
19528         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19529         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19530         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19531         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19532         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19533         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19534         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19535         (cmdline_parse_inst_t *)&cmd_global_config,
19536         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19537         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19538         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19539         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19540         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19541         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19542         (cmdline_parse_inst_t *)&cmd_dump,
19543         (cmdline_parse_inst_t *)&cmd_dump_one,
19544         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19545         (cmdline_parse_inst_t *)&cmd_syn_filter,
19546         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19547         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19548         (cmdline_parse_inst_t *)&cmd_flex_filter,
19549         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19550         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19551         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19552         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19553         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19554         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19555         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19556         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19557         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19558         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19559         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19560         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19561         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19562         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19563         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19564         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19565         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19566         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19567         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19568         (cmdline_parse_inst_t *)&cmd_flow,
19569         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19570         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19571         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19572         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19573         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19574         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19575         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19576         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19577         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19578         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19579         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19580         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19581         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19582         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19583         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19584         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19585         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19586         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19587         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19588         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19589         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19590         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19591         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19592         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19593         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19594         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19595         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19596         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19597         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19598         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19599         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19600         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19601         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19602         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19603         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19604         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19605         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19606         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19607         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19608         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19609         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19610         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19611         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19612         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19613         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19614         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19615         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19616         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19617         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19618 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19619         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19620 #endif
19621         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19622         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19623         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19624         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19625         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19626         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19627         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19628         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19629         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19630         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19631         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19632         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19633         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19634         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19635         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19636         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19637         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19638         (cmdline_parse_inst_t *)&cmd_ddp_add,
19639         (cmdline_parse_inst_t *)&cmd_ddp_del,
19640         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19641         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19642         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19643         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19644         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19645         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19646         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19647         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19648         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19649         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19650         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19651         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19652
19653         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19654         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19655         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19656         (cmdline_parse_inst_t *)&cmd_queue_region,
19657         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19658         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19659         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19660         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19661         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19662         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19663         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19664         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19665         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19666         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19667         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19668         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19669         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19670         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19671         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19672         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19673         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19674         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19675         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19676         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19677         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19678         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19679         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19680         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19681         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19682         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19683         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19684         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19685         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19686         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19687         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19688         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19689         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19690         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19691         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19692 #ifdef RTE_LIBRTE_BPF
19693         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19694         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19695 #endif
19696         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19697         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19698         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19699         (cmdline_parse_inst_t *)&cmd_set_raw,
19700         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19701         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19702         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19703         NULL,
19704 };
19705
19706 /* read cmdline commands from file */
19707 void
19708 cmdline_read_from_file(const char *filename)
19709 {
19710         struct cmdline *cl;
19711
19712         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19713         if (cl == NULL) {
19714                 printf("Failed to create file based cmdline context: %s\n",
19715                        filename);
19716                 return;
19717         }
19718
19719         cmdline_interact(cl);
19720         cmdline_quit(cl);
19721
19722         cmdline_free(cl);
19723
19724         printf("Read CLI commands from %s\n", filename);
19725 }
19726
19727 /* prompt function, called from main on MASTER lcore */
19728 void
19729 prompt(void)
19730 {
19731         /* initialize non-constant commands */
19732         cmd_set_fwd_mode_init();
19733         cmd_set_fwd_retry_mode_init();
19734
19735         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19736         if (testpmd_cl == NULL)
19737                 return;
19738         cmdline_interact(testpmd_cl);
19739         cmdline_stdin_exit(testpmd_cl);
19740 }
19741
19742 void
19743 prompt_exit(void)
19744 {
19745         if (testpmd_cl != NULL)
19746                 cmdline_quit(testpmd_cl);
19747 }
19748
19749 static void
19750 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19751 {
19752         if (id == (portid_t)RTE_PORT_ALL) {
19753                 portid_t pid;
19754
19755                 RTE_ETH_FOREACH_DEV(pid) {
19756                         /* check if need_reconfig has been set to 1 */
19757                         if (ports[pid].need_reconfig == 0)
19758                                 ports[pid].need_reconfig = dev;
19759                         /* check if need_reconfig_queues has been set to 1 */
19760                         if (ports[pid].need_reconfig_queues == 0)
19761                                 ports[pid].need_reconfig_queues = queue;
19762                 }
19763         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19764                 /* check if need_reconfig has been set to 1 */
19765                 if (ports[id].need_reconfig == 0)
19766                         ports[id].need_reconfig = dev;
19767                 /* check if need_reconfig_queues has been set to 1 */
19768                 if (ports[id].need_reconfig_queues == 0)
19769                         ports[id].need_reconfig_queues = queue;
19770         }
19771 }