app/testpmd: fix hot-unplug detaching
[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(__attribute__((unused)) void *parsed_result,
84                                   struct cmdline *cl,
85                                   __attribute__((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 commmands.\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                                  __attribute__((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|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                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1129                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1130                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1134                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1135                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1136                         " eth-dst (eth-dst)\n"
1137                         "       Configure the VXLAN encapsulation for flows.\n\n"
1138
1139                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1140                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1141                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1142                         " eth-dst (eth-dst)\n"
1143                         "       Configure the VXLAN encapsulation for flows.\n\n"
1144
1145                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1146                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1147                         " (eth-dst)\n"
1148                         "       Configure the NVGRE encapsulation for flows.\n\n"
1149
1150                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1151                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1152                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1153                         "       Configure the NVGRE encapsulation for flows.\n\n"
1154
1155                         "set raw_encap {flow items}\n"
1156                         "       Configure the encapsulation with raw data.\n\n"
1157
1158                         "set raw_decap {flow items}\n"
1159                         "       Configure the decapsulation with raw data.\n\n"
1160
1161                 );
1162         }
1163
1164         if (show_all || !strcmp(res->section, "traffic_management")) {
1165                 cmdline_printf(
1166                         cl,
1167                         "\n"
1168                         "Traffic Management:\n"
1169                         "--------------\n"
1170                         "show port tm cap (port_id)\n"
1171                         "       Display the port TM capability.\n\n"
1172
1173                         "show port tm level cap (port_id) (level_id)\n"
1174                         "       Display the port TM hierarchical level capability.\n\n"
1175
1176                         "show port tm node cap (port_id) (node_id)\n"
1177                         "       Display the port TM node capability.\n\n"
1178
1179                         "show port tm node type (port_id) (node_id)\n"
1180                         "       Display the port TM node type.\n\n"
1181
1182                         "show port tm node stats (port_id) (node_id) (clear)\n"
1183                         "       Display the port TM node stats.\n\n"
1184
1185 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1186                         "set port tm hierarchy default (port_id)\n"
1187                         "       Set default traffic Management hierarchy on a port\n\n"
1188 #endif
1189
1190                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1191                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1192                         " (packet_length_adjust)\n"
1193                         "       Add port tm node private shaper profile.\n\n"
1194
1195                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1196                         "       Delete port tm node private shaper profile.\n\n"
1197
1198                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1199                         " (shaper_profile_id)\n"
1200                         "       Add/update port tm node shared shaper.\n\n"
1201
1202                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1203                         "       Delete port tm node shared shaper.\n\n"
1204
1205                         "set port tm node shaper profile (port_id) (node_id)"
1206                         " (shaper_profile_id)\n"
1207                         "       Set port tm node shaper profile.\n\n"
1208
1209                         "add port tm node wred profile (port_id) (wred_profile_id)"
1210                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1211                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1212                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1213                         "       Add port tm node wred profile.\n\n"
1214
1215                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1216                         "       Delete port tm node wred profile.\n\n"
1217
1218                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1219                         " (priority) (weight) (level_id) (shaper_profile_id)"
1220                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1221                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1222                         "       Add port tm nonleaf node.\n\n"
1223
1224                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1225                         " (priority) (weight) (level_id) (shaper_profile_id)"
1226                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1227                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1228                         "       Add port tm leaf node.\n\n"
1229
1230                         "del port tm node (port_id) (node_id)\n"
1231                         "       Delete port tm node.\n\n"
1232
1233                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1234                         " (priority) (weight)\n"
1235                         "       Set port tm node parent.\n\n"
1236
1237                         "suspend port tm node (port_id) (node_id)"
1238                         "       Suspend tm node.\n\n"
1239
1240                         "resume port tm node (port_id) (node_id)"
1241                         "       Resume tm node.\n\n"
1242
1243                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1244                         "       Commit tm hierarchy.\n\n"
1245
1246                         "set port tm mark ip_ecn (port) (green) (yellow)"
1247                         " (red)\n"
1248                         "    Enables/Disables the traffic management marking"
1249                         " for IP ECN (Explicit Congestion Notification)"
1250                         " packets on a given port\n\n"
1251
1252                         "set port tm mark ip_dscp (port) (green) (yellow)"
1253                         " (red)\n"
1254                         "    Enables/Disables the traffic management marking"
1255                         " on the port for IP dscp packets\n\n"
1256
1257                         "set port tm mark vlan_dei (port) (green) (yellow)"
1258                         " (red)\n"
1259                         "    Enables/Disables the traffic management marking"
1260                         " on the port for VLAN packets with DEI enabled\n\n"
1261                 );
1262         }
1263
1264         if (show_all || !strcmp(res->section, "devices")) {
1265                 cmdline_printf(
1266                         cl,
1267                         "\n"
1268                         "Device Operations:\n"
1269                         "--------------\n"
1270                         "device detach (identifier)\n"
1271                         "       Detach device by identifier.\n\n"
1272                 );
1273         }
1274
1275 }
1276
1277 cmdline_parse_token_string_t cmd_help_long_help =
1278         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1279
1280 cmdline_parse_token_string_t cmd_help_long_section =
1281         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1282                         "all#control#display#config#"
1283                         "ports#registers#filters#traffic_management#devices");
1284
1285 cmdline_parse_inst_t cmd_help_long = {
1286         .f = cmd_help_long_parsed,
1287         .data = NULL,
1288         .help_str = "help all|control|display|config|ports|register|"
1289                 "filters|traffic_management|devices: "
1290                 "Show help",
1291         .tokens = {
1292                 (void *)&cmd_help_long_help,
1293                 (void *)&cmd_help_long_section,
1294                 NULL,
1295         },
1296 };
1297
1298
1299 /* *** start/stop/close all ports *** */
1300 struct cmd_operate_port_result {
1301         cmdline_fixed_string_t keyword;
1302         cmdline_fixed_string_t name;
1303         cmdline_fixed_string_t value;
1304 };
1305
1306 static void cmd_operate_port_parsed(void *parsed_result,
1307                                 __attribute__((unused)) struct cmdline *cl,
1308                                 __attribute__((unused)) void *data)
1309 {
1310         struct cmd_operate_port_result *res = parsed_result;
1311
1312         if (!strcmp(res->name, "start"))
1313                 start_port(RTE_PORT_ALL);
1314         else if (!strcmp(res->name, "stop"))
1315                 stop_port(RTE_PORT_ALL);
1316         else if (!strcmp(res->name, "close"))
1317                 close_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "reset"))
1319                 reset_port(RTE_PORT_ALL);
1320         else
1321                 printf("Unknown parameter\n");
1322 }
1323
1324 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1325         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1326                                                                 "port");
1327 cmdline_parse_token_string_t cmd_operate_port_all_port =
1328         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1329                                                 "start#stop#close#reset");
1330 cmdline_parse_token_string_t cmd_operate_port_all_all =
1331         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1332
1333 cmdline_parse_inst_t cmd_operate_port = {
1334         .f = cmd_operate_port_parsed,
1335         .data = NULL,
1336         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1337         .tokens = {
1338                 (void *)&cmd_operate_port_all_cmd,
1339                 (void *)&cmd_operate_port_all_port,
1340                 (void *)&cmd_operate_port_all_all,
1341                 NULL,
1342         },
1343 };
1344
1345 /* *** start/stop/close specific port *** */
1346 struct cmd_operate_specific_port_result {
1347         cmdline_fixed_string_t keyword;
1348         cmdline_fixed_string_t name;
1349         uint8_t value;
1350 };
1351
1352 static void cmd_operate_specific_port_parsed(void *parsed_result,
1353                         __attribute__((unused)) struct cmdline *cl,
1354                                 __attribute__((unused)) void *data)
1355 {
1356         struct cmd_operate_specific_port_result *res = parsed_result;
1357
1358         if (!strcmp(res->name, "start"))
1359                 start_port(res->value);
1360         else if (!strcmp(res->name, "stop"))
1361                 stop_port(res->value);
1362         else if (!strcmp(res->name, "close"))
1363                 close_port(res->value);
1364         else if (!strcmp(res->name, "reset"))
1365                 reset_port(res->value);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1372                                                         keyword, "port");
1373 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1375                                                 name, "start#stop#close#reset");
1376 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1377         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1378                                                         value, UINT8);
1379
1380 cmdline_parse_inst_t cmd_operate_specific_port = {
1381         .f = cmd_operate_specific_port_parsed,
1382         .data = NULL,
1383         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1384         .tokens = {
1385                 (void *)&cmd_operate_specific_port_cmd,
1386                 (void *)&cmd_operate_specific_port_port,
1387                 (void *)&cmd_operate_specific_port_id,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** enable port setup (after attach) via iterator or event *** */
1393 struct cmd_set_port_setup_on_result {
1394         cmdline_fixed_string_t set;
1395         cmdline_fixed_string_t port;
1396         cmdline_fixed_string_t setup;
1397         cmdline_fixed_string_t on;
1398         cmdline_fixed_string_t mode;
1399 };
1400
1401 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1402                                 __attribute__((unused)) struct cmdline *cl,
1403                                 __attribute__((unused)) void *data)
1404 {
1405         struct cmd_set_port_setup_on_result *res = parsed_result;
1406
1407         if (strcmp(res->mode, "event") == 0)
1408                 setup_on_probe_event = true;
1409         else if (strcmp(res->mode, "iterator") == 0)
1410                 setup_on_probe_event = false;
1411         else
1412                 printf("Unknown mode\n");
1413 }
1414
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         set, "set");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1419         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420                         port, "port");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1422         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423                         setup, "setup");
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1425         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426                         on, "on");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1428         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429                         mode, "iterator#event");
1430
1431 cmdline_parse_inst_t cmd_set_port_setup_on = {
1432         .f = cmd_set_port_setup_on_parsed,
1433         .data = NULL,
1434         .help_str = "set port setup on iterator|event",
1435         .tokens = {
1436                 (void *)&cmd_set_port_setup_on_set,
1437                 (void *)&cmd_set_port_setup_on_port,
1438                 (void *)&cmd_set_port_setup_on_setup,
1439                 (void *)&cmd_set_port_setup_on_on,
1440                 (void *)&cmd_set_port_setup_on_mode,
1441                 NULL,
1442         },
1443 };
1444
1445 /* *** attach a specified port *** */
1446 struct cmd_operate_attach_port_result {
1447         cmdline_fixed_string_t port;
1448         cmdline_fixed_string_t keyword;
1449         cmdline_fixed_string_t identifier;
1450 };
1451
1452 static void cmd_operate_attach_port_parsed(void *parsed_result,
1453                                 __attribute__((unused)) struct cmdline *cl,
1454                                 __attribute__((unused)) void *data)
1455 {
1456         struct cmd_operate_attach_port_result *res = parsed_result;
1457
1458         if (!strcmp(res->keyword, "attach"))
1459                 attach_port(res->identifier);
1460         else
1461                 printf("Unknown parameter\n");
1462 }
1463
1464 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1465         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1466                         port, "port");
1467 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1468         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1469                         keyword, "attach");
1470 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1471         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1472                         identifier, NULL);
1473
1474 cmdline_parse_inst_t cmd_operate_attach_port = {
1475         .f = cmd_operate_attach_port_parsed,
1476         .data = NULL,
1477         .help_str = "port attach <identifier>: "
1478                 "(identifier: pci address or virtual dev name)",
1479         .tokens = {
1480                 (void *)&cmd_operate_attach_port_port,
1481                 (void *)&cmd_operate_attach_port_keyword,
1482                 (void *)&cmd_operate_attach_port_identifier,
1483                 NULL,
1484         },
1485 };
1486
1487 /* *** detach a specified port *** */
1488 struct cmd_operate_detach_port_result {
1489         cmdline_fixed_string_t port;
1490         cmdline_fixed_string_t keyword;
1491         portid_t port_id;
1492 };
1493
1494 static void cmd_operate_detach_port_parsed(void *parsed_result,
1495                                 __attribute__((unused)) struct cmdline *cl,
1496                                 __attribute__((unused)) void *data)
1497 {
1498         struct cmd_operate_detach_port_result *res = parsed_result;
1499
1500         if (!strcmp(res->keyword, "detach")) {
1501                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1502                 detach_port_device(res->port_id);
1503         } else {
1504                 printf("Unknown parameter\n");
1505         }
1506 }
1507
1508 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1509         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1510                         port, "port");
1511 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1512         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1513                         keyword, "detach");
1514 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1515         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1516                         port_id, UINT16);
1517
1518 cmdline_parse_inst_t cmd_operate_detach_port = {
1519         .f = cmd_operate_detach_port_parsed,
1520         .data = NULL,
1521         .help_str = "port detach <port_id>",
1522         .tokens = {
1523                 (void *)&cmd_operate_detach_port_port,
1524                 (void *)&cmd_operate_detach_port_keyword,
1525                 (void *)&cmd_operate_detach_port_port_id,
1526                 NULL,
1527         },
1528 };
1529
1530 /* *** detach device by identifier *** */
1531 struct cmd_operate_detach_device_result {
1532         cmdline_fixed_string_t device;
1533         cmdline_fixed_string_t keyword;
1534         cmdline_fixed_string_t identifier;
1535 };
1536
1537 static void cmd_operate_detach_device_parsed(void *parsed_result,
1538                                 __attribute__((unused)) struct cmdline *cl,
1539                                 __attribute__((unused)) void *data)
1540 {
1541         struct cmd_operate_detach_device_result *res = parsed_result;
1542
1543         if (!strcmp(res->keyword, "detach"))
1544                 detach_devargs(res->identifier);
1545         else
1546                 printf("Unknown parameter\n");
1547 }
1548
1549 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1550         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1551                         device, "device");
1552 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1553         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1554                         keyword, "detach");
1555 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1556         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1557                         identifier, NULL);
1558
1559 cmdline_parse_inst_t cmd_operate_detach_device = {
1560         .f = cmd_operate_detach_device_parsed,
1561         .data = NULL,
1562         .help_str = "device detach <identifier>:"
1563                 "(identifier: pci address or virtual dev name)",
1564         .tokens = {
1565                 (void *)&cmd_operate_detach_device_device,
1566                 (void *)&cmd_operate_detach_device_keyword,
1567                 (void *)&cmd_operate_detach_device_identifier,
1568                 NULL,
1569         },
1570 };
1571 /* *** configure speed for all ports *** */
1572 struct cmd_config_speed_all {
1573         cmdline_fixed_string_t port;
1574         cmdline_fixed_string_t keyword;
1575         cmdline_fixed_string_t all;
1576         cmdline_fixed_string_t item1;
1577         cmdline_fixed_string_t item2;
1578         cmdline_fixed_string_t value1;
1579         cmdline_fixed_string_t value2;
1580 };
1581
1582 static int
1583 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1584 {
1585
1586         int duplex;
1587
1588         if (!strcmp(duplexstr, "half")) {
1589                 duplex = ETH_LINK_HALF_DUPLEX;
1590         } else if (!strcmp(duplexstr, "full")) {
1591                 duplex = ETH_LINK_FULL_DUPLEX;
1592         } else if (!strcmp(duplexstr, "auto")) {
1593                 duplex = ETH_LINK_FULL_DUPLEX;
1594         } else {
1595                 printf("Unknown duplex parameter\n");
1596                 return -1;
1597         }
1598
1599         if (!strcmp(speedstr, "10")) {
1600                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1601                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1602         } else if (!strcmp(speedstr, "100")) {
1603                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1604                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1605         } else {
1606                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1607                         printf("Invalid speed/duplex parameters\n");
1608                         return -1;
1609                 }
1610                 if (!strcmp(speedstr, "1000")) {
1611                         *speed = ETH_LINK_SPEED_1G;
1612                 } else if (!strcmp(speedstr, "10000")) {
1613                         *speed = ETH_LINK_SPEED_10G;
1614                 } else if (!strcmp(speedstr, "25000")) {
1615                         *speed = ETH_LINK_SPEED_25G;
1616                 } else if (!strcmp(speedstr, "40000")) {
1617                         *speed = ETH_LINK_SPEED_40G;
1618                 } else if (!strcmp(speedstr, "50000")) {
1619                         *speed = ETH_LINK_SPEED_50G;
1620                 } else if (!strcmp(speedstr, "100000")) {
1621                         *speed = ETH_LINK_SPEED_100G;
1622                 } else if (!strcmp(speedstr, "auto")) {
1623                         *speed = ETH_LINK_SPEED_AUTONEG;
1624                 } else {
1625                         printf("Unknown speed parameter\n");
1626                         return -1;
1627                 }
1628         }
1629
1630         return 0;
1631 }
1632
1633 static void
1634 cmd_config_speed_all_parsed(void *parsed_result,
1635                         __attribute__((unused)) struct cmdline *cl,
1636                         __attribute__((unused)) void *data)
1637 {
1638         struct cmd_config_speed_all *res = parsed_result;
1639         uint32_t link_speed;
1640         portid_t pid;
1641
1642         if (!all_ports_stopped()) {
1643                 printf("Please stop all ports first\n");
1644                 return;
1645         }
1646
1647         if (parse_and_check_speed_duplex(res->value1, res->value2,
1648                         &link_speed) < 0)
1649                 return;
1650
1651         RTE_ETH_FOREACH_DEV(pid) {
1652                 ports[pid].dev_conf.link_speeds = link_speed;
1653         }
1654
1655         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1656 }
1657
1658 cmdline_parse_token_string_t cmd_config_speed_all_port =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1660 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1662                                                         "config");
1663 cmdline_parse_token_string_t cmd_config_speed_all_all =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1665 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1667 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1669                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1670 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1672 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1673         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1674                                                 "half#full#auto");
1675
1676 cmdline_parse_inst_t cmd_config_speed_all = {
1677         .f = cmd_config_speed_all_parsed,
1678         .data = NULL,
1679         .help_str = "port config all speed "
1680                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1681                                                         "half|full|auto",
1682         .tokens = {
1683                 (void *)&cmd_config_speed_all_port,
1684                 (void *)&cmd_config_speed_all_keyword,
1685                 (void *)&cmd_config_speed_all_all,
1686                 (void *)&cmd_config_speed_all_item1,
1687                 (void *)&cmd_config_speed_all_value1,
1688                 (void *)&cmd_config_speed_all_item2,
1689                 (void *)&cmd_config_speed_all_value2,
1690                 NULL,
1691         },
1692 };
1693
1694 /* *** configure speed for specific port *** */
1695 struct cmd_config_speed_specific {
1696         cmdline_fixed_string_t port;
1697         cmdline_fixed_string_t keyword;
1698         portid_t id;
1699         cmdline_fixed_string_t item1;
1700         cmdline_fixed_string_t item2;
1701         cmdline_fixed_string_t value1;
1702         cmdline_fixed_string_t value2;
1703 };
1704
1705 static void
1706 cmd_config_speed_specific_parsed(void *parsed_result,
1707                                 __attribute__((unused)) struct cmdline *cl,
1708                                 __attribute__((unused)) void *data)
1709 {
1710         struct cmd_config_speed_specific *res = parsed_result;
1711         uint32_t link_speed;
1712
1713         if (!all_ports_stopped()) {
1714                 printf("Please stop all ports first\n");
1715                 return;
1716         }
1717
1718         if (port_id_is_invalid(res->id, ENABLED_WARN))
1719                 return;
1720
1721         if (parse_and_check_speed_duplex(res->value1, res->value2,
1722                         &link_speed) < 0)
1723                 return;
1724
1725         ports[res->id].dev_conf.link_speeds = link_speed;
1726
1727         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1728 }
1729
1730
1731 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1733                                                                 "port");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1736                                                                 "config");
1737 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1738         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1739 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1741                                                                 "speed");
1742 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1743         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1744                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1747                                                                 "duplex");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1750                                                         "half#full#auto");
1751
1752 cmdline_parse_inst_t cmd_config_speed_specific = {
1753         .f = cmd_config_speed_specific_parsed,
1754         .data = NULL,
1755         .help_str = "port config <port_id> speed "
1756                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1757                                                         "half|full|auto",
1758         .tokens = {
1759                 (void *)&cmd_config_speed_specific_port,
1760                 (void *)&cmd_config_speed_specific_keyword,
1761                 (void *)&cmd_config_speed_specific_id,
1762                 (void *)&cmd_config_speed_specific_item1,
1763                 (void *)&cmd_config_speed_specific_value1,
1764                 (void *)&cmd_config_speed_specific_item2,
1765                 (void *)&cmd_config_speed_specific_value2,
1766                 NULL,
1767         },
1768 };
1769
1770 /* *** configure loopback for all ports *** */
1771 struct cmd_config_loopback_all {
1772         cmdline_fixed_string_t port;
1773         cmdline_fixed_string_t keyword;
1774         cmdline_fixed_string_t all;
1775         cmdline_fixed_string_t item;
1776         uint32_t mode;
1777 };
1778
1779 static void
1780 cmd_config_loopback_all_parsed(void *parsed_result,
1781                         __attribute__((unused)) struct cmdline *cl,
1782                         __attribute__((unused)) void *data)
1783 {
1784         struct cmd_config_loopback_all *res = parsed_result;
1785         portid_t pid;
1786
1787         if (!all_ports_stopped()) {
1788                 printf("Please stop all ports first\n");
1789                 return;
1790         }
1791
1792         RTE_ETH_FOREACH_DEV(pid) {
1793                 ports[pid].dev_conf.lpbk_mode = res->mode;
1794         }
1795
1796         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1797 }
1798
1799 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1801 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1802         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1803                                                         "config");
1804 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1806 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1807         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1808                                                         "loopback");
1809 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1810         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1811
1812 cmdline_parse_inst_t cmd_config_loopback_all = {
1813         .f = cmd_config_loopback_all_parsed,
1814         .data = NULL,
1815         .help_str = "port config all loopback <mode>",
1816         .tokens = {
1817                 (void *)&cmd_config_loopback_all_port,
1818                 (void *)&cmd_config_loopback_all_keyword,
1819                 (void *)&cmd_config_loopback_all_all,
1820                 (void *)&cmd_config_loopback_all_item,
1821                 (void *)&cmd_config_loopback_all_mode,
1822                 NULL,
1823         },
1824 };
1825
1826 /* *** configure loopback for specific port *** */
1827 struct cmd_config_loopback_specific {
1828         cmdline_fixed_string_t port;
1829         cmdline_fixed_string_t keyword;
1830         uint16_t port_id;
1831         cmdline_fixed_string_t item;
1832         uint32_t mode;
1833 };
1834
1835 static void
1836 cmd_config_loopback_specific_parsed(void *parsed_result,
1837                                 __attribute__((unused)) struct cmdline *cl,
1838                                 __attribute__((unused)) void *data)
1839 {
1840         struct cmd_config_loopback_specific *res = parsed_result;
1841
1842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1843                 return;
1844
1845         if (!port_is_stopped(res->port_id)) {
1846                 printf("Please stop port %u first\n", res->port_id);
1847                 return;
1848         }
1849
1850         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1851
1852         cmd_reconfig_device_queue(res->port_id, 1, 1);
1853 }
1854
1855
1856 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1858                                                                 "port");
1859 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1861                                                                 "config");
1862 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1863         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1864                                                                 UINT16);
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1867                                                                 "loopback");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1870                               UINT32);
1871
1872 cmdline_parse_inst_t cmd_config_loopback_specific = {
1873         .f = cmd_config_loopback_specific_parsed,
1874         .data = NULL,
1875         .help_str = "port config <port_id> loopback <mode>",
1876         .tokens = {
1877                 (void *)&cmd_config_loopback_specific_port,
1878                 (void *)&cmd_config_loopback_specific_keyword,
1879                 (void *)&cmd_config_loopback_specific_id,
1880                 (void *)&cmd_config_loopback_specific_item,
1881                 (void *)&cmd_config_loopback_specific_mode,
1882                 NULL,
1883         },
1884 };
1885
1886 /* *** configure txq/rxq, txd/rxd *** */
1887 struct cmd_config_rx_tx {
1888         cmdline_fixed_string_t port;
1889         cmdline_fixed_string_t keyword;
1890         cmdline_fixed_string_t all;
1891         cmdline_fixed_string_t name;
1892         uint16_t value;
1893 };
1894
1895 static void
1896 cmd_config_rx_tx_parsed(void *parsed_result,
1897                         __attribute__((unused)) struct cmdline *cl,
1898                         __attribute__((unused)) void *data)
1899 {
1900         struct cmd_config_rx_tx *res = parsed_result;
1901
1902         if (!all_ports_stopped()) {
1903                 printf("Please stop all ports first\n");
1904                 return;
1905         }
1906         if (!strcmp(res->name, "rxq")) {
1907                 if (!res->value && !nb_txq) {
1908                         printf("Warning: Either rx or tx queues should be non zero\n");
1909                         return;
1910                 }
1911                 if (check_nb_rxq(res->value) != 0)
1912                         return;
1913                 nb_rxq = res->value;
1914         }
1915         else if (!strcmp(res->name, "txq")) {
1916                 if (!res->value && !nb_rxq) {
1917                         printf("Warning: Either rx or tx queues should be non zero\n");
1918                         return;
1919                 }
1920                 if (check_nb_txq(res->value) != 0)
1921                         return;
1922                 nb_txq = res->value;
1923         }
1924         else if (!strcmp(res->name, "rxd")) {
1925                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1926                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1927                                         res->value, RTE_TEST_RX_DESC_MAX);
1928                         return;
1929                 }
1930                 nb_rxd = res->value;
1931         } else if (!strcmp(res->name, "txd")) {
1932                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1933                         printf("txd %d invalid - must be > 0 && <= %d\n",
1934                                         res->value, RTE_TEST_TX_DESC_MAX);
1935                         return;
1936                 }
1937                 nb_txd = res->value;
1938         } else {
1939                 printf("Unknown parameter\n");
1940                 return;
1941         }
1942
1943         fwd_config_setup();
1944
1945         init_port_config();
1946
1947         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1954 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1956 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1958                                                 "rxq#txq#rxd#txd");
1959 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1960         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1961
1962 cmdline_parse_inst_t cmd_config_rx_tx = {
1963         .f = cmd_config_rx_tx_parsed,
1964         .data = NULL,
1965         .help_str = "port config all rxq|txq|rxd|txd <value>",
1966         .tokens = {
1967                 (void *)&cmd_config_rx_tx_port,
1968                 (void *)&cmd_config_rx_tx_keyword,
1969                 (void *)&cmd_config_rx_tx_all,
1970                 (void *)&cmd_config_rx_tx_name,
1971                 (void *)&cmd_config_rx_tx_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** config max packet length *** */
1977 struct cmd_config_max_pkt_len_result {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t keyword;
1980         cmdline_fixed_string_t all;
1981         cmdline_fixed_string_t name;
1982         uint32_t value;
1983 };
1984
1985 static void
1986 cmd_config_max_pkt_len_parsed(void *parsed_result,
1987                                 __attribute__((unused)) struct cmdline *cl,
1988                                 __attribute__((unused)) void *data)
1989 {
1990         struct cmd_config_max_pkt_len_result *res = parsed_result;
1991         portid_t pid;
1992
1993         if (!all_ports_stopped()) {
1994                 printf("Please stop all ports first\n");
1995                 return;
1996         }
1997
1998         RTE_ETH_FOREACH_DEV(pid) {
1999                 struct rte_port *port = &ports[pid];
2000                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2001
2002                 if (!strcmp(res->name, "max-pkt-len")) {
2003                         if (res->value < RTE_ETHER_MIN_LEN) {
2004                                 printf("max-pkt-len can not be less than %d\n",
2005                                                 RTE_ETHER_MIN_LEN);
2006                                 return;
2007                         }
2008                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2009                                 return;
2010
2011                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2012                         if (res->value > RTE_ETHER_MAX_LEN)
2013                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2014                         else
2015                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2016                         port->dev_conf.rxmode.offloads = rx_offloads;
2017                 } else {
2018                         printf("Unknown parameter\n");
2019                         return;
2020                 }
2021         }
2022
2023         init_port_config();
2024
2025         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2026 }
2027
2028 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2029         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2030                                                                 "port");
2031 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2032         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2033                                                                 "config");
2034 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2036                                                                 "all");
2037 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2038         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2039                                                                 "max-pkt-len");
2040 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2041         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2042                                                                 UINT32);
2043
2044 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2045         .f = cmd_config_max_pkt_len_parsed,
2046         .data = NULL,
2047         .help_str = "port config all max-pkt-len <value>",
2048         .tokens = {
2049                 (void *)&cmd_config_max_pkt_len_port,
2050                 (void *)&cmd_config_max_pkt_len_keyword,
2051                 (void *)&cmd_config_max_pkt_len_all,
2052                 (void *)&cmd_config_max_pkt_len_name,
2053                 (void *)&cmd_config_max_pkt_len_value,
2054                 NULL,
2055         },
2056 };
2057
2058 /* *** config max LRO aggregated packet size *** */
2059 struct cmd_config_max_lro_pkt_size_result {
2060         cmdline_fixed_string_t port;
2061         cmdline_fixed_string_t keyword;
2062         cmdline_fixed_string_t all;
2063         cmdline_fixed_string_t name;
2064         uint32_t value;
2065 };
2066
2067 static void
2068 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2069                                 __attribute__((unused)) struct cmdline *cl,
2070                                 __attribute__((unused)) void *data)
2071 {
2072         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2073         portid_t pid;
2074
2075         if (!all_ports_stopped()) {
2076                 printf("Please stop all ports first\n");
2077                 return;
2078         }
2079
2080         RTE_ETH_FOREACH_DEV(pid) {
2081                 struct rte_port *port = &ports[pid];
2082
2083                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2084                         if (res->value ==
2085                                         port->dev_conf.rxmode.max_lro_pkt_size)
2086                                 return;
2087
2088                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2089                 } else {
2090                         printf("Unknown parameter\n");
2091                         return;
2092                 }
2093         }
2094
2095         init_port_config();
2096
2097         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2098 }
2099
2100 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2101         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2102                                  port, "port");
2103 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2104         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2105                                  keyword, "config");
2106 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2107         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2108                                  all, "all");
2109 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2111                                  name, "max-lro-pkt-size");
2112 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2113         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114                               value, UINT32);
2115
2116 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2117         .f = cmd_config_max_lro_pkt_size_parsed,
2118         .data = NULL,
2119         .help_str = "port config all max-lro-pkt-size <value>",
2120         .tokens = {
2121                 (void *)&cmd_config_max_lro_pkt_size_port,
2122                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2123                 (void *)&cmd_config_max_lro_pkt_size_all,
2124                 (void *)&cmd_config_max_lro_pkt_size_name,
2125                 (void *)&cmd_config_max_lro_pkt_size_value,
2126                 NULL,
2127         },
2128 };
2129
2130 /* *** configure port MTU *** */
2131 struct cmd_config_mtu_result {
2132         cmdline_fixed_string_t port;
2133         cmdline_fixed_string_t keyword;
2134         cmdline_fixed_string_t mtu;
2135         portid_t port_id;
2136         uint16_t value;
2137 };
2138
2139 static void
2140 cmd_config_mtu_parsed(void *parsed_result,
2141                       __attribute__((unused)) struct cmdline *cl,
2142                       __attribute__((unused)) void *data)
2143 {
2144         struct cmd_config_mtu_result *res = parsed_result;
2145
2146         if (res->value < RTE_ETHER_MIN_LEN) {
2147                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2148                 return;
2149         }
2150         port_mtu_set(res->port_id, res->value);
2151 }
2152
2153 cmdline_parse_token_string_t cmd_config_mtu_port =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2155                                  "port");
2156 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2157         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2158                                  "config");
2159 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2161                                  "mtu");
2162 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2163         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2164 cmdline_parse_token_num_t cmd_config_mtu_value =
2165         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2166
2167 cmdline_parse_inst_t cmd_config_mtu = {
2168         .f = cmd_config_mtu_parsed,
2169         .data = NULL,
2170         .help_str = "port config mtu <port_id> <value>",
2171         .tokens = {
2172                 (void *)&cmd_config_mtu_port,
2173                 (void *)&cmd_config_mtu_keyword,
2174                 (void *)&cmd_config_mtu_mtu,
2175                 (void *)&cmd_config_mtu_port_id,
2176                 (void *)&cmd_config_mtu_value,
2177                 NULL,
2178         },
2179 };
2180
2181 /* *** configure rx mode *** */
2182 struct cmd_config_rx_mode_flag {
2183         cmdline_fixed_string_t port;
2184         cmdline_fixed_string_t keyword;
2185         cmdline_fixed_string_t all;
2186         cmdline_fixed_string_t name;
2187         cmdline_fixed_string_t value;
2188 };
2189
2190 static void
2191 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2192                                 __attribute__((unused)) struct cmdline *cl,
2193                                 __attribute__((unused)) void *data)
2194 {
2195         struct cmd_config_rx_mode_flag *res = parsed_result;
2196
2197         if (!all_ports_stopped()) {
2198                 printf("Please stop all ports first\n");
2199                 return;
2200         }
2201
2202         if (!strcmp(res->name, "drop-en")) {
2203                 if (!strcmp(res->value, "on"))
2204                         rx_drop_en = 1;
2205                 else if (!strcmp(res->value, "off"))
2206                         rx_drop_en = 0;
2207                 else {
2208                         printf("Unknown parameter\n");
2209                         return;
2210                 }
2211         } else {
2212                 printf("Unknown parameter\n");
2213                 return;
2214         }
2215
2216         init_port_config();
2217
2218         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2219 }
2220
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2222         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2225                                                                 "config");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2227         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2228 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2229         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2230                                         "drop-en");
2231 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2232         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2233                                                         "on#off");
2234
2235 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2236         .f = cmd_config_rx_mode_flag_parsed,
2237         .data = NULL,
2238         .help_str = "port config all drop-en on|off",
2239         .tokens = {
2240                 (void *)&cmd_config_rx_mode_flag_port,
2241                 (void *)&cmd_config_rx_mode_flag_keyword,
2242                 (void *)&cmd_config_rx_mode_flag_all,
2243                 (void *)&cmd_config_rx_mode_flag_name,
2244                 (void *)&cmd_config_rx_mode_flag_value,
2245                 NULL,
2246         },
2247 };
2248
2249 /* *** configure rss *** */
2250 struct cmd_config_rss {
2251         cmdline_fixed_string_t port;
2252         cmdline_fixed_string_t keyword;
2253         cmdline_fixed_string_t all;
2254         cmdline_fixed_string_t name;
2255         cmdline_fixed_string_t value;
2256 };
2257
2258 static void
2259 cmd_config_rss_parsed(void *parsed_result,
2260                         __attribute__((unused)) struct cmdline *cl,
2261                         __attribute__((unused)) void *data)
2262 {
2263         struct cmd_config_rss *res = parsed_result;
2264         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2265         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2266         int use_default = 0;
2267         int all_updated = 1;
2268         int diag;
2269         uint16_t i;
2270         int ret;
2271
2272         if (!strcmp(res->value, "all"))
2273                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2274                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2275                                         ETH_RSS_L2_PAYLOAD;
2276         else if (!strcmp(res->value, "ip"))
2277                 rss_conf.rss_hf = ETH_RSS_IP;
2278         else if (!strcmp(res->value, "udp"))
2279                 rss_conf.rss_hf = ETH_RSS_UDP;
2280         else if (!strcmp(res->value, "tcp"))
2281                 rss_conf.rss_hf = ETH_RSS_TCP;
2282         else if (!strcmp(res->value, "sctp"))
2283                 rss_conf.rss_hf = ETH_RSS_SCTP;
2284         else if (!strcmp(res->value, "ether"))
2285                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2286         else if (!strcmp(res->value, "port"))
2287                 rss_conf.rss_hf = ETH_RSS_PORT;
2288         else if (!strcmp(res->value, "vxlan"))
2289                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2290         else if (!strcmp(res->value, "geneve"))
2291                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2292         else if (!strcmp(res->value, "nvgre"))
2293                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2294         else if (!strcmp(res->value, "l3-src-only"))
2295                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2296         else if (!strcmp(res->value, "l3-dst-only"))
2297                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2298         else if (!strcmp(res->value, "l4-src-only"))
2299                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2300         else if (!strcmp(res->value, "l4-dst-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2302         else if (!strcmp(res->value, "none"))
2303                 rss_conf.rss_hf = 0;
2304         else if (!strcmp(res->value, "default"))
2305                 use_default = 1;
2306         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2307                                                 atoi(res->value) < 64)
2308                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2309         else {
2310                 printf("Unknown parameter\n");
2311                 return;
2312         }
2313         rss_conf.rss_key = NULL;
2314         /* Update global configuration for RSS types. */
2315         RTE_ETH_FOREACH_DEV(i) {
2316                 struct rte_eth_rss_conf local_rss_conf;
2317
2318                 ret = eth_dev_info_get_print_err(i, &dev_info);
2319                 if (ret != 0)
2320                         return;
2321
2322                 if (use_default)
2323                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2324
2325                 local_rss_conf = rss_conf;
2326                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2327                         dev_info.flow_type_rss_offloads;
2328                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2329                         printf("Port %u modified RSS hash function based on hardware support,"
2330                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2331                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2332                 }
2333                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2334                 if (diag < 0) {
2335                         all_updated = 0;
2336                         printf("Configuration of RSS hash at ethernet port %d "
2337                                 "failed with error (%d): %s.\n",
2338                                 i, -diag, strerror(-diag));
2339                 }
2340         }
2341         if (all_updated && !use_default)
2342                 rss_hf = rss_conf.rss_hf;
2343 }
2344
2345 cmdline_parse_token_string_t cmd_config_rss_port =
2346         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2347 cmdline_parse_token_string_t cmd_config_rss_keyword =
2348         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2349 cmdline_parse_token_string_t cmd_config_rss_all =
2350         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2351 cmdline_parse_token_string_t cmd_config_rss_name =
2352         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2353 cmdline_parse_token_string_t cmd_config_rss_value =
2354         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2355
2356 cmdline_parse_inst_t cmd_config_rss = {
2357         .f = cmd_config_rss_parsed,
2358         .data = NULL,
2359         .help_str = "port config all rss "
2360                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2361         .tokens = {
2362                 (void *)&cmd_config_rss_port,
2363                 (void *)&cmd_config_rss_keyword,
2364                 (void *)&cmd_config_rss_all,
2365                 (void *)&cmd_config_rss_name,
2366                 (void *)&cmd_config_rss_value,
2367                 NULL,
2368         },
2369 };
2370
2371 /* *** configure rss hash key *** */
2372 struct cmd_config_rss_hash_key {
2373         cmdline_fixed_string_t port;
2374         cmdline_fixed_string_t config;
2375         portid_t port_id;
2376         cmdline_fixed_string_t rss_hash_key;
2377         cmdline_fixed_string_t rss_type;
2378         cmdline_fixed_string_t key;
2379 };
2380
2381 static uint8_t
2382 hexa_digit_to_value(char hexa_digit)
2383 {
2384         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2385                 return (uint8_t) (hexa_digit - '0');
2386         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2387                 return (uint8_t) ((hexa_digit - 'a') + 10);
2388         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2389                 return (uint8_t) ((hexa_digit - 'A') + 10);
2390         /* Invalid hexa digit */
2391         return 0xFF;
2392 }
2393
2394 static uint8_t
2395 parse_and_check_key_hexa_digit(char *key, int idx)
2396 {
2397         uint8_t hexa_v;
2398
2399         hexa_v = hexa_digit_to_value(key[idx]);
2400         if (hexa_v == 0xFF)
2401                 printf("invalid key: character %c at position %d is not a "
2402                        "valid hexa digit\n", key[idx], idx);
2403         return hexa_v;
2404 }
2405
2406 static void
2407 cmd_config_rss_hash_key_parsed(void *parsed_result,
2408                                __attribute__((unused)) struct cmdline *cl,
2409                                __attribute__((unused)) void *data)
2410 {
2411         struct cmd_config_rss_hash_key *res = parsed_result;
2412         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2413         uint8_t xdgt0;
2414         uint8_t xdgt1;
2415         int i;
2416         struct rte_eth_dev_info dev_info;
2417         uint8_t hash_key_size;
2418         uint32_t key_len;
2419         int ret;
2420
2421         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2422         if (ret != 0)
2423                 return;
2424
2425         if (dev_info.hash_key_size > 0 &&
2426                         dev_info.hash_key_size <= sizeof(hash_key))
2427                 hash_key_size = dev_info.hash_key_size;
2428         else {
2429                 printf("dev_info did not provide a valid hash key size\n");
2430                 return;
2431         }
2432         /* Check the length of the RSS hash key */
2433         key_len = strlen(res->key);
2434         if (key_len != (hash_key_size * 2)) {
2435                 printf("key length: %d invalid - key must be a string of %d"
2436                            " hexa-decimal numbers\n",
2437                            (int) key_len, hash_key_size * 2);
2438                 return;
2439         }
2440         /* Translate RSS hash key into binary representation */
2441         for (i = 0; i < hash_key_size; i++) {
2442                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2443                 if (xdgt0 == 0xFF)
2444                         return;
2445                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2446                 if (xdgt1 == 0xFF)
2447                         return;
2448                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2449         }
2450         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2451                         hash_key_size);
2452 }
2453
2454 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2455         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2456 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2457         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2458                                  "config");
2459 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2460         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2461 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2462         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2463                                  rss_hash_key, "rss-hash-key");
2464 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2465         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2466                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2467                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2468                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2469                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2470                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2471 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2473
2474 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2475         .f = cmd_config_rss_hash_key_parsed,
2476         .data = NULL,
2477         .help_str = "port config <port_id> rss-hash-key "
2478                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2479                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2480                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2481                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2482                 "<string of hex digits (variable length, NIC dependent)>",
2483         .tokens = {
2484                 (void *)&cmd_config_rss_hash_key_port,
2485                 (void *)&cmd_config_rss_hash_key_config,
2486                 (void *)&cmd_config_rss_hash_key_port_id,
2487                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2488                 (void *)&cmd_config_rss_hash_key_rss_type,
2489                 (void *)&cmd_config_rss_hash_key_value,
2490                 NULL,
2491         },
2492 };
2493
2494 /* *** configure port rxq/txq ring size *** */
2495 struct cmd_config_rxtx_ring_size {
2496         cmdline_fixed_string_t port;
2497         cmdline_fixed_string_t config;
2498         portid_t portid;
2499         cmdline_fixed_string_t rxtxq;
2500         uint16_t qid;
2501         cmdline_fixed_string_t rsize;
2502         uint16_t size;
2503 };
2504
2505 static void
2506 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2507                                  __attribute__((unused)) struct cmdline *cl,
2508                                  __attribute__((unused)) void *data)
2509 {
2510         struct cmd_config_rxtx_ring_size *res = parsed_result;
2511         struct rte_port *port;
2512         uint8_t isrx;
2513
2514         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2515                 return;
2516
2517         if (res->portid == (portid_t)RTE_PORT_ALL) {
2518                 printf("Invalid port id\n");
2519                 return;
2520         }
2521
2522         port = &ports[res->portid];
2523
2524         if (!strcmp(res->rxtxq, "rxq"))
2525                 isrx = 1;
2526         else if (!strcmp(res->rxtxq, "txq"))
2527                 isrx = 0;
2528         else {
2529                 printf("Unknown parameter\n");
2530                 return;
2531         }
2532
2533         if (isrx && rx_queue_id_is_invalid(res->qid))
2534                 return;
2535         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2536                 return;
2537
2538         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2539                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2540                        rx_free_thresh);
2541                 return;
2542         }
2543
2544         if (isrx)
2545                 port->nb_rx_desc[res->qid] = res->size;
2546         else
2547                 port->nb_tx_desc[res->qid] = res->size;
2548
2549         cmd_reconfig_device_queue(res->portid, 0, 1);
2550 }
2551
2552 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2554                                  port, "port");
2555 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2556         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2557                                  config, "config");
2558 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2559         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2560                                  portid, UINT16);
2561 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2562         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2563                                  rxtxq, "rxq#txq");
2564 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2565         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2566                               qid, UINT16);
2567 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2568         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2569                                  rsize, "ring_size");
2570 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2571         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2572                               size, UINT16);
2573
2574 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2575         .f = cmd_config_rxtx_ring_size_parsed,
2576         .data = NULL,
2577         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2578         .tokens = {
2579                 (void *)&cmd_config_rxtx_ring_size_port,
2580                 (void *)&cmd_config_rxtx_ring_size_config,
2581                 (void *)&cmd_config_rxtx_ring_size_portid,
2582                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2583                 (void *)&cmd_config_rxtx_ring_size_qid,
2584                 (void *)&cmd_config_rxtx_ring_size_rsize,
2585                 (void *)&cmd_config_rxtx_ring_size_size,
2586                 NULL,
2587         },
2588 };
2589
2590 /* *** configure port rxq/txq start/stop *** */
2591 struct cmd_config_rxtx_queue {
2592         cmdline_fixed_string_t port;
2593         portid_t portid;
2594         cmdline_fixed_string_t rxtxq;
2595         uint16_t qid;
2596         cmdline_fixed_string_t opname;
2597 };
2598
2599 static void
2600 cmd_config_rxtx_queue_parsed(void *parsed_result,
2601                         __attribute__((unused)) struct cmdline *cl,
2602                         __attribute__((unused)) void *data)
2603 {
2604         struct cmd_config_rxtx_queue *res = parsed_result;
2605         uint8_t isrx;
2606         uint8_t isstart;
2607         int ret = 0;
2608
2609         if (test_done == 0) {
2610                 printf("Please stop forwarding first\n");
2611                 return;
2612         }
2613
2614         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2615                 return;
2616
2617         if (port_is_started(res->portid) != 1) {
2618                 printf("Please start port %u first\n", res->portid);
2619                 return;
2620         }
2621
2622         if (!strcmp(res->rxtxq, "rxq"))
2623                 isrx = 1;
2624         else if (!strcmp(res->rxtxq, "txq"))
2625                 isrx = 0;
2626         else {
2627                 printf("Unknown parameter\n");
2628                 return;
2629         }
2630
2631         if (isrx && rx_queue_id_is_invalid(res->qid))
2632                 return;
2633         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2634                 return;
2635
2636         if (!strcmp(res->opname, "start"))
2637                 isstart = 1;
2638         else if (!strcmp(res->opname, "stop"))
2639                 isstart = 0;
2640         else {
2641                 printf("Unknown parameter\n");
2642                 return;
2643         }
2644
2645         if (isstart && isrx)
2646                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2647         else if (!isstart && isrx)
2648                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2649         else if (isstart && !isrx)
2650                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2651         else
2652                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2653
2654         if (ret == -ENOTSUP)
2655                 printf("Function not supported in PMD driver\n");
2656 }
2657
2658 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2659         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2660 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2661         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2662 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2663         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2664 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2665         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2666 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2667         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2668                                                 "start#stop");
2669
2670 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2671         .f = cmd_config_rxtx_queue_parsed,
2672         .data = NULL,
2673         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2674         .tokens = {
2675                 (void *)&cmd_config_rxtx_queue_port,
2676                 (void *)&cmd_config_rxtx_queue_portid,
2677                 (void *)&cmd_config_rxtx_queue_rxtxq,
2678                 (void *)&cmd_config_rxtx_queue_qid,
2679                 (void *)&cmd_config_rxtx_queue_opname,
2680                 NULL,
2681         },
2682 };
2683
2684 /* *** configure port rxq/txq deferred start on/off *** */
2685 struct cmd_config_deferred_start_rxtx_queue {
2686         cmdline_fixed_string_t port;
2687         portid_t port_id;
2688         cmdline_fixed_string_t rxtxq;
2689         uint16_t qid;
2690         cmdline_fixed_string_t opname;
2691         cmdline_fixed_string_t state;
2692 };
2693
2694 static void
2695 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2696                         __attribute__((unused)) struct cmdline *cl,
2697                         __attribute__((unused)) void *data)
2698 {
2699         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2700         struct rte_port *port;
2701         uint8_t isrx;
2702         uint8_t ison;
2703         uint8_t needreconfig = 0;
2704
2705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2706                 return;
2707
2708         if (port_is_started(res->port_id) != 0) {
2709                 printf("Please stop port %u first\n", res->port_id);
2710                 return;
2711         }
2712
2713         port = &ports[res->port_id];
2714
2715         isrx = !strcmp(res->rxtxq, "rxq");
2716
2717         if (isrx && rx_queue_id_is_invalid(res->qid))
2718                 return;
2719         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2720                 return;
2721
2722         ison = !strcmp(res->state, "on");
2723
2724         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2725                 port->rx_conf[res->qid].rx_deferred_start = ison;
2726                 needreconfig = 1;
2727         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2728                 port->tx_conf[res->qid].tx_deferred_start = ison;
2729                 needreconfig = 1;
2730         }
2731
2732         if (needreconfig)
2733                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2734 }
2735
2736 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2737         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2738                                                 port, "port");
2739 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2740         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2741                                                 port_id, UINT16);
2742 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2743         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2744                                                 rxtxq, "rxq#txq");
2745 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2746         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2747                                                 qid, UINT16);
2748 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2750                                                 opname, "deferred_start");
2751 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2752         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2753                                                 state, "on#off");
2754
2755 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2756         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2757         .data = NULL,
2758         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2759         .tokens = {
2760                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2761                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2762                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2763                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2764                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2765                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2766                 NULL,
2767         },
2768 };
2769
2770 /* *** configure port rxq/txq setup *** */
2771 struct cmd_setup_rxtx_queue {
2772         cmdline_fixed_string_t port;
2773         portid_t portid;
2774         cmdline_fixed_string_t rxtxq;
2775         uint16_t qid;
2776         cmdline_fixed_string_t setup;
2777 };
2778
2779 /* Common CLI fields for queue setup */
2780 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2781         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2782 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2783         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2784 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2785         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2786 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2787         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2788 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2789         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2790
2791 static void
2792 cmd_setup_rxtx_queue_parsed(
2793         void *parsed_result,
2794         __attribute__((unused)) struct cmdline *cl,
2795         __attribute__((unused)) void *data)
2796 {
2797         struct cmd_setup_rxtx_queue *res = parsed_result;
2798         struct rte_port *port;
2799         struct rte_mempool *mp;
2800         unsigned int socket_id;
2801         uint8_t isrx = 0;
2802         int ret;
2803
2804         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2805                 return;
2806
2807         if (res->portid == (portid_t)RTE_PORT_ALL) {
2808                 printf("Invalid port id\n");
2809                 return;
2810         }
2811
2812         if (!strcmp(res->rxtxq, "rxq"))
2813                 isrx = 1;
2814         else if (!strcmp(res->rxtxq, "txq"))
2815                 isrx = 0;
2816         else {
2817                 printf("Unknown parameter\n");
2818                 return;
2819         }
2820
2821         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2822                 printf("Invalid rx queue\n");
2823                 return;
2824         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2825                 printf("Invalid tx queue\n");
2826                 return;
2827         }
2828
2829         port = &ports[res->portid];
2830         if (isrx) {
2831                 socket_id = rxring_numa[res->portid];
2832                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2833                         socket_id = port->socket_id;
2834
2835                 mp = mbuf_pool_find(socket_id);
2836                 if (mp == NULL) {
2837                         printf("Failed to setup RX queue: "
2838                                 "No mempool allocation"
2839                                 " on the socket %d\n",
2840                                 rxring_numa[res->portid]);
2841                         return;
2842                 }
2843                 ret = rte_eth_rx_queue_setup(res->portid,
2844                                              res->qid,
2845                                              port->nb_rx_desc[res->qid],
2846                                              socket_id,
2847                                              &port->rx_conf[res->qid],
2848                                              mp);
2849                 if (ret)
2850                         printf("Failed to setup RX queue\n");
2851         } else {
2852                 socket_id = txring_numa[res->portid];
2853                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2854                         socket_id = port->socket_id;
2855
2856                 ret = rte_eth_tx_queue_setup(res->portid,
2857                                              res->qid,
2858                                              port->nb_tx_desc[res->qid],
2859                                              socket_id,
2860                                              &port->tx_conf[res->qid]);
2861                 if (ret)
2862                         printf("Failed to setup TX queue\n");
2863         }
2864 }
2865
2866 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2867         .f = cmd_setup_rxtx_queue_parsed,
2868         .data = NULL,
2869         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2870         .tokens = {
2871                 (void *)&cmd_setup_rxtx_queue_port,
2872                 (void *)&cmd_setup_rxtx_queue_portid,
2873                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2874                 (void *)&cmd_setup_rxtx_queue_qid,
2875                 (void *)&cmd_setup_rxtx_queue_setup,
2876                 NULL,
2877         },
2878 };
2879
2880
2881 /* *** Configure RSS RETA *** */
2882 struct cmd_config_rss_reta {
2883         cmdline_fixed_string_t port;
2884         cmdline_fixed_string_t keyword;
2885         portid_t port_id;
2886         cmdline_fixed_string_t name;
2887         cmdline_fixed_string_t list_name;
2888         cmdline_fixed_string_t list_of_items;
2889 };
2890
2891 static int
2892 parse_reta_config(const char *str,
2893                   struct rte_eth_rss_reta_entry64 *reta_conf,
2894                   uint16_t nb_entries)
2895 {
2896         int i;
2897         unsigned size;
2898         uint16_t hash_index, idx, shift;
2899         uint16_t nb_queue;
2900         char s[256];
2901         const char *p, *p0 = str;
2902         char *end;
2903         enum fieldnames {
2904                 FLD_HASH_INDEX = 0,
2905                 FLD_QUEUE,
2906                 _NUM_FLD
2907         };
2908         unsigned long int_fld[_NUM_FLD];
2909         char *str_fld[_NUM_FLD];
2910
2911         while ((p = strchr(p0,'(')) != NULL) {
2912                 ++p;
2913                 if((p0 = strchr(p,')')) == NULL)
2914                         return -1;
2915
2916                 size = p0 - p;
2917                 if(size >= sizeof(s))
2918                         return -1;
2919
2920                 snprintf(s, sizeof(s), "%.*s", size, p);
2921                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2922                         return -1;
2923                 for (i = 0; i < _NUM_FLD; i++) {
2924                         errno = 0;
2925                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2926                         if (errno != 0 || end == str_fld[i] ||
2927                                         int_fld[i] > 65535)
2928                                 return -1;
2929                 }
2930
2931                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2932                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2933
2934                 if (hash_index >= nb_entries) {
2935                         printf("Invalid RETA hash index=%d\n", hash_index);
2936                         return -1;
2937                 }
2938
2939                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2940                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2941                 reta_conf[idx].mask |= (1ULL << shift);
2942                 reta_conf[idx].reta[shift] = nb_queue;
2943         }
2944
2945         return 0;
2946 }
2947
2948 static void
2949 cmd_set_rss_reta_parsed(void *parsed_result,
2950                         __attribute__((unused)) struct cmdline *cl,
2951                         __attribute__((unused)) void *data)
2952 {
2953         int ret;
2954         struct rte_eth_dev_info dev_info;
2955         struct rte_eth_rss_reta_entry64 reta_conf[8];
2956         struct cmd_config_rss_reta *res = parsed_result;
2957
2958         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2959         if (ret != 0)
2960                 return;
2961
2962         if (dev_info.reta_size == 0) {
2963                 printf("Redirection table size is 0 which is "
2964                                         "invalid for RSS\n");
2965                 return;
2966         } else
2967                 printf("The reta size of port %d is %u\n",
2968                         res->port_id, dev_info.reta_size);
2969         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2970                 printf("Currently do not support more than %u entries of "
2971                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2972                 return;
2973         }
2974
2975         memset(reta_conf, 0, sizeof(reta_conf));
2976         if (!strcmp(res->list_name, "reta")) {
2977                 if (parse_reta_config(res->list_of_items, reta_conf,
2978                                                 dev_info.reta_size)) {
2979                         printf("Invalid RSS Redirection Table "
2980                                         "config entered\n");
2981                         return;
2982                 }
2983                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2984                                 reta_conf, dev_info.reta_size);
2985                 if (ret != 0)
2986                         printf("Bad redirection table parameter, "
2987                                         "return code = %d \n", ret);
2988         }
2989 }
2990
2991 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2992         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2993 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2994         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2995 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2996         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2997 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2998         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2999 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3000         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3001 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3002         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3003                                  NULL);
3004 cmdline_parse_inst_t cmd_config_rss_reta = {
3005         .f = cmd_set_rss_reta_parsed,
3006         .data = NULL,
3007         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3008         .tokens = {
3009                 (void *)&cmd_config_rss_reta_port,
3010                 (void *)&cmd_config_rss_reta_keyword,
3011                 (void *)&cmd_config_rss_reta_port_id,
3012                 (void *)&cmd_config_rss_reta_name,
3013                 (void *)&cmd_config_rss_reta_list_name,
3014                 (void *)&cmd_config_rss_reta_list_of_items,
3015                 NULL,
3016         },
3017 };
3018
3019 /* *** SHOW PORT RETA INFO *** */
3020 struct cmd_showport_reta {
3021         cmdline_fixed_string_t show;
3022         cmdline_fixed_string_t port;
3023         portid_t port_id;
3024         cmdline_fixed_string_t rss;
3025         cmdline_fixed_string_t reta;
3026         uint16_t size;
3027         cmdline_fixed_string_t list_of_items;
3028 };
3029
3030 static int
3031 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3032                            uint16_t nb_entries,
3033                            char *str)
3034 {
3035         uint32_t size;
3036         const char *p, *p0 = str;
3037         char s[256];
3038         char *end;
3039         char *str_fld[8];
3040         uint16_t i;
3041         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3042                         RTE_RETA_GROUP_SIZE;
3043         int ret;
3044
3045         p = strchr(p0, '(');
3046         if (p == NULL)
3047                 return -1;
3048         p++;
3049         p0 = strchr(p, ')');
3050         if (p0 == NULL)
3051                 return -1;
3052         size = p0 - p;
3053         if (size >= sizeof(s)) {
3054                 printf("The string size exceeds the internal buffer size\n");
3055                 return -1;
3056         }
3057         snprintf(s, sizeof(s), "%.*s", size, p);
3058         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3059         if (ret <= 0 || ret != num) {
3060                 printf("The bits of masks do not match the number of "
3061                                         "reta entries: %u\n", num);
3062                 return -1;
3063         }
3064         for (i = 0; i < ret; i++)
3065                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3066
3067         return 0;
3068 }
3069
3070 static void
3071 cmd_showport_reta_parsed(void *parsed_result,
3072                          __attribute__((unused)) struct cmdline *cl,
3073                          __attribute__((unused)) void *data)
3074 {
3075         struct cmd_showport_reta *res = parsed_result;
3076         struct rte_eth_rss_reta_entry64 reta_conf[8];
3077         struct rte_eth_dev_info dev_info;
3078         uint16_t max_reta_size;
3079         int ret;
3080
3081         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3082         if (ret != 0)
3083                 return;
3084
3085         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3086         if (res->size == 0 || res->size > max_reta_size) {
3087                 printf("Invalid redirection table size: %u (1-%u)\n",
3088                         res->size, max_reta_size);
3089                 return;
3090         }
3091
3092         memset(reta_conf, 0, sizeof(reta_conf));
3093         if (showport_parse_reta_config(reta_conf, res->size,
3094                                 res->list_of_items) < 0) {
3095                 printf("Invalid string: %s for reta masks\n",
3096                                         res->list_of_items);
3097                 return;
3098         }
3099         port_rss_reta_info(res->port_id, reta_conf, res->size);
3100 }
3101
3102 cmdline_parse_token_string_t cmd_showport_reta_show =
3103         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3104 cmdline_parse_token_string_t cmd_showport_reta_port =
3105         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3106 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3107         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3108 cmdline_parse_token_string_t cmd_showport_reta_rss =
3109         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3110 cmdline_parse_token_string_t cmd_showport_reta_reta =
3111         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3112 cmdline_parse_token_num_t cmd_showport_reta_size =
3113         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3114 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3115         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3116                                         list_of_items, NULL);
3117
3118 cmdline_parse_inst_t cmd_showport_reta = {
3119         .f = cmd_showport_reta_parsed,
3120         .data = NULL,
3121         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3122         .tokens = {
3123                 (void *)&cmd_showport_reta_show,
3124                 (void *)&cmd_showport_reta_port,
3125                 (void *)&cmd_showport_reta_port_id,
3126                 (void *)&cmd_showport_reta_rss,
3127                 (void *)&cmd_showport_reta_reta,
3128                 (void *)&cmd_showport_reta_size,
3129                 (void *)&cmd_showport_reta_list_of_items,
3130                 NULL,
3131         },
3132 };
3133
3134 /* *** Show RSS hash configuration *** */
3135 struct cmd_showport_rss_hash {
3136         cmdline_fixed_string_t show;
3137         cmdline_fixed_string_t port;
3138         portid_t port_id;
3139         cmdline_fixed_string_t rss_hash;
3140         cmdline_fixed_string_t rss_type;
3141         cmdline_fixed_string_t key; /* optional argument */
3142 };
3143
3144 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3145                                 __attribute__((unused)) struct cmdline *cl,
3146                                 void *show_rss_key)
3147 {
3148         struct cmd_showport_rss_hash *res = parsed_result;
3149
3150         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3151 }
3152
3153 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3154         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3155 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3156         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3157 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3158         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3159 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3160         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3161                                  "rss-hash");
3162 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3163         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3164
3165 cmdline_parse_inst_t cmd_showport_rss_hash = {
3166         .f = cmd_showport_rss_hash_parsed,
3167         .data = NULL,
3168         .help_str = "show port <port_id> rss-hash",
3169         .tokens = {
3170                 (void *)&cmd_showport_rss_hash_show,
3171                 (void *)&cmd_showport_rss_hash_port,
3172                 (void *)&cmd_showport_rss_hash_port_id,
3173                 (void *)&cmd_showport_rss_hash_rss_hash,
3174                 NULL,
3175         },
3176 };
3177
3178 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3179         .f = cmd_showport_rss_hash_parsed,
3180         .data = (void *)1,
3181         .help_str = "show port <port_id> rss-hash key",
3182         .tokens = {
3183                 (void *)&cmd_showport_rss_hash_show,
3184                 (void *)&cmd_showport_rss_hash_port,
3185                 (void *)&cmd_showport_rss_hash_port_id,
3186                 (void *)&cmd_showport_rss_hash_rss_hash,
3187                 (void *)&cmd_showport_rss_hash_rss_key,
3188                 NULL,
3189         },
3190 };
3191
3192 /* *** Configure DCB *** */
3193 struct cmd_config_dcb {
3194         cmdline_fixed_string_t port;
3195         cmdline_fixed_string_t config;
3196         portid_t port_id;
3197         cmdline_fixed_string_t dcb;
3198         cmdline_fixed_string_t vt;
3199         cmdline_fixed_string_t vt_en;
3200         uint8_t num_tcs;
3201         cmdline_fixed_string_t pfc;
3202         cmdline_fixed_string_t pfc_en;
3203 };
3204
3205 static void
3206 cmd_config_dcb_parsed(void *parsed_result,
3207                         __attribute__((unused)) struct cmdline *cl,
3208                         __attribute__((unused)) void *data)
3209 {
3210         struct cmd_config_dcb *res = parsed_result;
3211         portid_t port_id = res->port_id;
3212         struct rte_port *port;
3213         uint8_t pfc_en;
3214         int ret;
3215
3216         port = &ports[port_id];
3217         /** Check if the port is not started **/
3218         if (port->port_status != RTE_PORT_STOPPED) {
3219                 printf("Please stop port %d first\n", port_id);
3220                 return;
3221         }
3222
3223         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3224                 printf("The invalid number of traffic class,"
3225                         " only 4 or 8 allowed.\n");
3226                 return;
3227         }
3228
3229         if (nb_fwd_lcores < res->num_tcs) {
3230                 printf("nb_cores shouldn't be less than number of TCs.\n");
3231                 return;
3232         }
3233         if (!strncmp(res->pfc_en, "on", 2))
3234                 pfc_en = 1;
3235         else
3236                 pfc_en = 0;
3237
3238         /* DCB in VT mode */
3239         if (!strncmp(res->vt_en, "on", 2))
3240                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3241                                 (enum rte_eth_nb_tcs)res->num_tcs,
3242                                 pfc_en);
3243         else
3244                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3245                                 (enum rte_eth_nb_tcs)res->num_tcs,
3246                                 pfc_en);
3247
3248
3249         if (ret != 0) {
3250                 printf("Cannot initialize network ports.\n");
3251                 return;
3252         }
3253
3254         cmd_reconfig_device_queue(port_id, 1, 1);
3255 }
3256
3257 cmdline_parse_token_string_t cmd_config_dcb_port =
3258         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3259 cmdline_parse_token_string_t cmd_config_dcb_config =
3260         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3261 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3262         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3263 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3264         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3265 cmdline_parse_token_string_t cmd_config_dcb_vt =
3266         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3267 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3268         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3269 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3270         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3271 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3272         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3273 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3274         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3275
3276 cmdline_parse_inst_t cmd_config_dcb = {
3277         .f = cmd_config_dcb_parsed,
3278         .data = NULL,
3279         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3280         .tokens = {
3281                 (void *)&cmd_config_dcb_port,
3282                 (void *)&cmd_config_dcb_config,
3283                 (void *)&cmd_config_dcb_port_id,
3284                 (void *)&cmd_config_dcb_dcb,
3285                 (void *)&cmd_config_dcb_vt,
3286                 (void *)&cmd_config_dcb_vt_en,
3287                 (void *)&cmd_config_dcb_num_tcs,
3288                 (void *)&cmd_config_dcb_pfc,
3289                 (void *)&cmd_config_dcb_pfc_en,
3290                 NULL,
3291         },
3292 };
3293
3294 /* *** configure number of packets per burst *** */
3295 struct cmd_config_burst {
3296         cmdline_fixed_string_t port;
3297         cmdline_fixed_string_t keyword;
3298         cmdline_fixed_string_t all;
3299         cmdline_fixed_string_t name;
3300         uint16_t value;
3301 };
3302
3303 static void
3304 cmd_config_burst_parsed(void *parsed_result,
3305                         __attribute__((unused)) struct cmdline *cl,
3306                         __attribute__((unused)) void *data)
3307 {
3308         struct cmd_config_burst *res = parsed_result;
3309         struct rte_eth_dev_info dev_info;
3310         uint16_t rec_nb_pkts;
3311         int ret;
3312
3313         if (!all_ports_stopped()) {
3314                 printf("Please stop all ports first\n");
3315                 return;
3316         }
3317
3318         if (!strcmp(res->name, "burst")) {
3319                 if (res->value == 0) {
3320                         /* If user gives a value of zero, query the PMD for
3321                          * its recommended Rx burst size. Testpmd uses a single
3322                          * size for all ports, so assume all ports are the same
3323                          * NIC model and use the values from Port 0.
3324                          */
3325                         ret = eth_dev_info_get_print_err(0, &dev_info);
3326                         if (ret != 0)
3327                                 return;
3328
3329                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3330
3331                         if (rec_nb_pkts == 0) {
3332                                 printf("PMD does not recommend a burst size.\n"
3333                                         "User provided value must be between"
3334                                         " 1 and %d\n", MAX_PKT_BURST);
3335                                 return;
3336                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3337                                 printf("PMD recommended burst size of %d"
3338                                         " exceeds maximum value of %d\n",
3339                                         rec_nb_pkts, MAX_PKT_BURST);
3340                                 return;
3341                         }
3342                         printf("Using PMD-provided burst value of %d\n",
3343                                 rec_nb_pkts);
3344                         nb_pkt_per_burst = rec_nb_pkts;
3345                 } else if (res->value > MAX_PKT_BURST) {
3346                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3347                         return;
3348                 } else
3349                         nb_pkt_per_burst = res->value;
3350         } else {
3351                 printf("Unknown parameter\n");
3352                 return;
3353         }
3354
3355         init_port_config();
3356
3357         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3358 }
3359
3360 cmdline_parse_token_string_t cmd_config_burst_port =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3362 cmdline_parse_token_string_t cmd_config_burst_keyword =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3364 cmdline_parse_token_string_t cmd_config_burst_all =
3365         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3366 cmdline_parse_token_string_t cmd_config_burst_name =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3368 cmdline_parse_token_num_t cmd_config_burst_value =
3369         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3370
3371 cmdline_parse_inst_t cmd_config_burst = {
3372         .f = cmd_config_burst_parsed,
3373         .data = NULL,
3374         .help_str = "port config all burst <value>",
3375         .tokens = {
3376                 (void *)&cmd_config_burst_port,
3377                 (void *)&cmd_config_burst_keyword,
3378                 (void *)&cmd_config_burst_all,
3379                 (void *)&cmd_config_burst_name,
3380                 (void *)&cmd_config_burst_value,
3381                 NULL,
3382         },
3383 };
3384
3385 /* *** configure rx/tx queues *** */
3386 struct cmd_config_thresh {
3387         cmdline_fixed_string_t port;
3388         cmdline_fixed_string_t keyword;
3389         cmdline_fixed_string_t all;
3390         cmdline_fixed_string_t name;
3391         uint8_t value;
3392 };
3393
3394 static void
3395 cmd_config_thresh_parsed(void *parsed_result,
3396                         __attribute__((unused)) struct cmdline *cl,
3397                         __attribute__((unused)) void *data)
3398 {
3399         struct cmd_config_thresh *res = parsed_result;
3400
3401         if (!all_ports_stopped()) {
3402                 printf("Please stop all ports first\n");
3403                 return;
3404         }
3405
3406         if (!strcmp(res->name, "txpt"))
3407                 tx_pthresh = res->value;
3408         else if(!strcmp(res->name, "txht"))
3409                 tx_hthresh = res->value;
3410         else if(!strcmp(res->name, "txwt"))
3411                 tx_wthresh = res->value;
3412         else if(!strcmp(res->name, "rxpt"))
3413                 rx_pthresh = res->value;
3414         else if(!strcmp(res->name, "rxht"))
3415                 rx_hthresh = res->value;
3416         else if(!strcmp(res->name, "rxwt"))
3417                 rx_wthresh = res->value;
3418         else {
3419                 printf("Unknown parameter\n");
3420                 return;
3421         }
3422
3423         init_port_config();
3424
3425         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3426 }
3427
3428 cmdline_parse_token_string_t cmd_config_thresh_port =
3429         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3430 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3431         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3432 cmdline_parse_token_string_t cmd_config_thresh_all =
3433         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3434 cmdline_parse_token_string_t cmd_config_thresh_name =
3435         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3436                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3437 cmdline_parse_token_num_t cmd_config_thresh_value =
3438         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3439
3440 cmdline_parse_inst_t cmd_config_thresh = {
3441         .f = cmd_config_thresh_parsed,
3442         .data = NULL,
3443         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3444         .tokens = {
3445                 (void *)&cmd_config_thresh_port,
3446                 (void *)&cmd_config_thresh_keyword,
3447                 (void *)&cmd_config_thresh_all,
3448                 (void *)&cmd_config_thresh_name,
3449                 (void *)&cmd_config_thresh_value,
3450                 NULL,
3451         },
3452 };
3453
3454 /* *** configure free/rs threshold *** */
3455 struct cmd_config_threshold {
3456         cmdline_fixed_string_t port;
3457         cmdline_fixed_string_t keyword;
3458         cmdline_fixed_string_t all;
3459         cmdline_fixed_string_t name;
3460         uint16_t value;
3461 };
3462
3463 static void
3464 cmd_config_threshold_parsed(void *parsed_result,
3465                         __attribute__((unused)) struct cmdline *cl,
3466                         __attribute__((unused)) void *data)
3467 {
3468         struct cmd_config_threshold *res = parsed_result;
3469
3470         if (!all_ports_stopped()) {
3471                 printf("Please stop all ports first\n");
3472                 return;
3473         }
3474
3475         if (!strcmp(res->name, "txfreet"))
3476                 tx_free_thresh = res->value;
3477         else if (!strcmp(res->name, "txrst"))
3478                 tx_rs_thresh = res->value;
3479         else if (!strcmp(res->name, "rxfreet"))
3480                 rx_free_thresh = res->value;
3481         else {
3482                 printf("Unknown parameter\n");
3483                 return;
3484         }
3485
3486         init_port_config();
3487
3488         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3489 }
3490
3491 cmdline_parse_token_string_t cmd_config_threshold_port =
3492         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3493 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3494         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3495                                                                 "config");
3496 cmdline_parse_token_string_t cmd_config_threshold_all =
3497         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3498 cmdline_parse_token_string_t cmd_config_threshold_name =
3499         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3500                                                 "txfreet#txrst#rxfreet");
3501 cmdline_parse_token_num_t cmd_config_threshold_value =
3502         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3503
3504 cmdline_parse_inst_t cmd_config_threshold = {
3505         .f = cmd_config_threshold_parsed,
3506         .data = NULL,
3507         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3508         .tokens = {
3509                 (void *)&cmd_config_threshold_port,
3510                 (void *)&cmd_config_threshold_keyword,
3511                 (void *)&cmd_config_threshold_all,
3512                 (void *)&cmd_config_threshold_name,
3513                 (void *)&cmd_config_threshold_value,
3514                 NULL,
3515         },
3516 };
3517
3518 /* *** stop *** */
3519 struct cmd_stop_result {
3520         cmdline_fixed_string_t stop;
3521 };
3522
3523 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
3524                             __attribute__((unused)) struct cmdline *cl,
3525                             __attribute__((unused)) void *data)
3526 {
3527         stop_packet_forwarding();
3528 }
3529
3530 cmdline_parse_token_string_t cmd_stop_stop =
3531         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3532
3533 cmdline_parse_inst_t cmd_stop = {
3534         .f = cmd_stop_parsed,
3535         .data = NULL,
3536         .help_str = "stop: Stop packet forwarding",
3537         .tokens = {
3538                 (void *)&cmd_stop_stop,
3539                 NULL,
3540         },
3541 };
3542
3543 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3544
3545 unsigned int
3546 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3547                 unsigned int *parsed_items, int check_unique_values)
3548 {
3549         unsigned int nb_item;
3550         unsigned int value;
3551         unsigned int i;
3552         unsigned int j;
3553         int value_ok;
3554         char c;
3555
3556         /*
3557          * First parse all items in the list and store their value.
3558          */
3559         value = 0;
3560         nb_item = 0;
3561         value_ok = 0;
3562         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3563                 c = str[i];
3564                 if ((c >= '0') && (c <= '9')) {
3565                         value = (unsigned int) (value * 10 + (c - '0'));
3566                         value_ok = 1;
3567                         continue;
3568                 }
3569                 if (c != ',') {
3570                         printf("character %c is not a decimal digit\n", c);
3571                         return 0;
3572                 }
3573                 if (! value_ok) {
3574                         printf("No valid value before comma\n");
3575                         return 0;
3576                 }
3577                 if (nb_item < max_items) {
3578                         parsed_items[nb_item] = value;
3579                         value_ok = 0;
3580                         value = 0;
3581                 }
3582                 nb_item++;
3583         }
3584         if (nb_item >= max_items) {
3585                 printf("Number of %s = %u > %u (maximum items)\n",
3586                        item_name, nb_item + 1, max_items);
3587                 return 0;
3588         }
3589         parsed_items[nb_item++] = value;
3590         if (! check_unique_values)
3591                 return nb_item;
3592
3593         /*
3594          * Then, check that all values in the list are differents.
3595          * No optimization here...
3596          */
3597         for (i = 0; i < nb_item; i++) {
3598                 for (j = i + 1; j < nb_item; j++) {
3599                         if (parsed_items[j] == parsed_items[i]) {
3600                                 printf("duplicated %s %u at index %u and %u\n",
3601                                        item_name, parsed_items[i], i, j);
3602                                 return 0;
3603                         }
3604                 }
3605         }
3606         return nb_item;
3607 }
3608
3609 struct cmd_set_list_result {
3610         cmdline_fixed_string_t cmd_keyword;
3611         cmdline_fixed_string_t list_name;
3612         cmdline_fixed_string_t list_of_items;
3613 };
3614
3615 static void cmd_set_list_parsed(void *parsed_result,
3616                                 __attribute__((unused)) struct cmdline *cl,
3617                                 __attribute__((unused)) void *data)
3618 {
3619         struct cmd_set_list_result *res;
3620         union {
3621                 unsigned int lcorelist[RTE_MAX_LCORE];
3622                 unsigned int portlist[RTE_MAX_ETHPORTS];
3623         } parsed_items;
3624         unsigned int nb_item;
3625
3626         if (test_done == 0) {
3627                 printf("Please stop forwarding first\n");
3628                 return;
3629         }
3630
3631         res = parsed_result;
3632         if (!strcmp(res->list_name, "corelist")) {
3633                 nb_item = parse_item_list(res->list_of_items, "core",
3634                                           RTE_MAX_LCORE,
3635                                           parsed_items.lcorelist, 1);
3636                 if (nb_item > 0) {
3637                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3638                         fwd_config_setup();
3639                 }
3640                 return;
3641         }
3642         if (!strcmp(res->list_name, "portlist")) {
3643                 nb_item = parse_item_list(res->list_of_items, "port",
3644                                           RTE_MAX_ETHPORTS,
3645                                           parsed_items.portlist, 1);
3646                 if (nb_item > 0) {
3647                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3648                         fwd_config_setup();
3649                 }
3650         }
3651 }
3652
3653 cmdline_parse_token_string_t cmd_set_list_keyword =
3654         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3655                                  "set");
3656 cmdline_parse_token_string_t cmd_set_list_name =
3657         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3658                                  "corelist#portlist");
3659 cmdline_parse_token_string_t cmd_set_list_of_items =
3660         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3661                                  NULL);
3662
3663 cmdline_parse_inst_t cmd_set_fwd_list = {
3664         .f = cmd_set_list_parsed,
3665         .data = NULL,
3666         .help_str = "set corelist|portlist <list0[,list1]*>",
3667         .tokens = {
3668                 (void *)&cmd_set_list_keyword,
3669                 (void *)&cmd_set_list_name,
3670                 (void *)&cmd_set_list_of_items,
3671                 NULL,
3672         },
3673 };
3674
3675 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3676
3677 struct cmd_setmask_result {
3678         cmdline_fixed_string_t set;
3679         cmdline_fixed_string_t mask;
3680         uint64_t hexavalue;
3681 };
3682
3683 static void cmd_set_mask_parsed(void *parsed_result,
3684                                 __attribute__((unused)) struct cmdline *cl,
3685                                 __attribute__((unused)) void *data)
3686 {
3687         struct cmd_setmask_result *res = parsed_result;
3688
3689         if (test_done == 0) {
3690                 printf("Please stop forwarding first\n");
3691                 return;
3692         }
3693         if (!strcmp(res->mask, "coremask")) {
3694                 set_fwd_lcores_mask(res->hexavalue);
3695                 fwd_config_setup();
3696         } else if (!strcmp(res->mask, "portmask")) {
3697                 set_fwd_ports_mask(res->hexavalue);
3698                 fwd_config_setup();
3699         }
3700 }
3701
3702 cmdline_parse_token_string_t cmd_setmask_set =
3703         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3704 cmdline_parse_token_string_t cmd_setmask_mask =
3705         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3706                                  "coremask#portmask");
3707 cmdline_parse_token_num_t cmd_setmask_value =
3708         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3709
3710 cmdline_parse_inst_t cmd_set_fwd_mask = {
3711         .f = cmd_set_mask_parsed,
3712         .data = NULL,
3713         .help_str = "set coremask|portmask <hexadecimal value>",
3714         .tokens = {
3715                 (void *)&cmd_setmask_set,
3716                 (void *)&cmd_setmask_mask,
3717                 (void *)&cmd_setmask_value,
3718                 NULL,
3719         },
3720 };
3721
3722 /*
3723  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3724  */
3725 struct cmd_set_result {
3726         cmdline_fixed_string_t set;
3727         cmdline_fixed_string_t what;
3728         uint16_t value;
3729 };
3730
3731 static void cmd_set_parsed(void *parsed_result,
3732                            __attribute__((unused)) struct cmdline *cl,
3733                            __attribute__((unused)) void *data)
3734 {
3735         struct cmd_set_result *res = parsed_result;
3736         if (!strcmp(res->what, "nbport")) {
3737                 set_fwd_ports_number(res->value);
3738                 fwd_config_setup();
3739         } else if (!strcmp(res->what, "nbcore")) {
3740                 set_fwd_lcores_number(res->value);
3741                 fwd_config_setup();
3742         } else if (!strcmp(res->what, "burst"))
3743                 set_nb_pkt_per_burst(res->value);
3744         else if (!strcmp(res->what, "verbose"))
3745                 set_verbose_level(res->value);
3746 }
3747
3748 cmdline_parse_token_string_t cmd_set_set =
3749         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3750 cmdline_parse_token_string_t cmd_set_what =
3751         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3752                                  "nbport#nbcore#burst#verbose");
3753 cmdline_parse_token_num_t cmd_set_value =
3754         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3755
3756 cmdline_parse_inst_t cmd_set_numbers = {
3757         .f = cmd_set_parsed,
3758         .data = NULL,
3759         .help_str = "set nbport|nbcore|burst|verbose <value>",
3760         .tokens = {
3761                 (void *)&cmd_set_set,
3762                 (void *)&cmd_set_what,
3763                 (void *)&cmd_set_value,
3764                 NULL,
3765         },
3766 };
3767
3768 /* *** SET LOG LEVEL CONFIGURATION *** */
3769
3770 struct cmd_set_log_result {
3771         cmdline_fixed_string_t set;
3772         cmdline_fixed_string_t log;
3773         cmdline_fixed_string_t type;
3774         uint32_t level;
3775 };
3776
3777 static void
3778 cmd_set_log_parsed(void *parsed_result,
3779                    __attribute__((unused)) struct cmdline *cl,
3780                    __attribute__((unused)) void *data)
3781 {
3782         struct cmd_set_log_result *res;
3783         int ret;
3784
3785         res = parsed_result;
3786         if (!strcmp(res->type, "global"))
3787                 rte_log_set_global_level(res->level);
3788         else {
3789                 ret = rte_log_set_level_regexp(res->type, res->level);
3790                 if (ret < 0)
3791                         printf("Unable to set log level\n");
3792         }
3793 }
3794
3795 cmdline_parse_token_string_t cmd_set_log_set =
3796         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3797 cmdline_parse_token_string_t cmd_set_log_log =
3798         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3799 cmdline_parse_token_string_t cmd_set_log_type =
3800         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3801 cmdline_parse_token_num_t cmd_set_log_level =
3802         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3803
3804 cmdline_parse_inst_t cmd_set_log = {
3805         .f = cmd_set_log_parsed,
3806         .data = NULL,
3807         .help_str = "set log global|<type> <level>",
3808         .tokens = {
3809                 (void *)&cmd_set_log_set,
3810                 (void *)&cmd_set_log_log,
3811                 (void *)&cmd_set_log_type,
3812                 (void *)&cmd_set_log_level,
3813                 NULL,
3814         },
3815 };
3816
3817 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3818
3819 struct cmd_set_txpkts_result {
3820         cmdline_fixed_string_t cmd_keyword;
3821         cmdline_fixed_string_t txpkts;
3822         cmdline_fixed_string_t seg_lengths;
3823 };
3824
3825 static void
3826 cmd_set_txpkts_parsed(void *parsed_result,
3827                       __attribute__((unused)) struct cmdline *cl,
3828                       __attribute__((unused)) void *data)
3829 {
3830         struct cmd_set_txpkts_result *res;
3831         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3832         unsigned int nb_segs;
3833
3834         res = parsed_result;
3835         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3836                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3837         if (nb_segs > 0)
3838                 set_tx_pkt_segments(seg_lengths, nb_segs);
3839 }
3840
3841 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3842         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3843                                  cmd_keyword, "set");
3844 cmdline_parse_token_string_t cmd_set_txpkts_name =
3845         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3846                                  txpkts, "txpkts");
3847 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3848         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3849                                  seg_lengths, NULL);
3850
3851 cmdline_parse_inst_t cmd_set_txpkts = {
3852         .f = cmd_set_txpkts_parsed,
3853         .data = NULL,
3854         .help_str = "set txpkts <len0[,len1]*>",
3855         .tokens = {
3856                 (void *)&cmd_set_txpkts_keyword,
3857                 (void *)&cmd_set_txpkts_name,
3858                 (void *)&cmd_set_txpkts_lengths,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3864
3865 struct cmd_set_txsplit_result {
3866         cmdline_fixed_string_t cmd_keyword;
3867         cmdline_fixed_string_t txsplit;
3868         cmdline_fixed_string_t mode;
3869 };
3870
3871 static void
3872 cmd_set_txsplit_parsed(void *parsed_result,
3873                       __attribute__((unused)) struct cmdline *cl,
3874                       __attribute__((unused)) void *data)
3875 {
3876         struct cmd_set_txsplit_result *res;
3877
3878         res = parsed_result;
3879         set_tx_pkt_split(res->mode);
3880 }
3881
3882 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3884                                  cmd_keyword, "set");
3885 cmdline_parse_token_string_t cmd_set_txsplit_name =
3886         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3887                                  txsplit, "txsplit");
3888 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3889         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3890                                  mode, NULL);
3891
3892 cmdline_parse_inst_t cmd_set_txsplit = {
3893         .f = cmd_set_txsplit_parsed,
3894         .data = NULL,
3895         .help_str = "set txsplit on|off|rand",
3896         .tokens = {
3897                 (void *)&cmd_set_txsplit_keyword,
3898                 (void *)&cmd_set_txsplit_name,
3899                 (void *)&cmd_set_txsplit_mode,
3900                 NULL,
3901         },
3902 };
3903
3904 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3905 struct cmd_rx_vlan_filter_all_result {
3906         cmdline_fixed_string_t rx_vlan;
3907         cmdline_fixed_string_t what;
3908         cmdline_fixed_string_t all;
3909         portid_t port_id;
3910 };
3911
3912 static void
3913 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3914                               __attribute__((unused)) struct cmdline *cl,
3915                               __attribute__((unused)) void *data)
3916 {
3917         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3918
3919         if (!strcmp(res->what, "add"))
3920                 rx_vlan_all_filter_set(res->port_id, 1);
3921         else
3922                 rx_vlan_all_filter_set(res->port_id, 0);
3923 }
3924
3925 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3926         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3927                                  rx_vlan, "rx_vlan");
3928 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3929         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3930                                  what, "add#rm");
3931 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3932         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3933                                  all, "all");
3934 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3935         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3936                               port_id, UINT16);
3937
3938 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3939         .f = cmd_rx_vlan_filter_all_parsed,
3940         .data = NULL,
3941         .help_str = "rx_vlan add|rm all <port_id>: "
3942                 "Add/Remove all identifiers to/from the set of VLAN "
3943                 "identifiers filtered by a port",
3944         .tokens = {
3945                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3946                 (void *)&cmd_rx_vlan_filter_all_what,
3947                 (void *)&cmd_rx_vlan_filter_all_all,
3948                 (void *)&cmd_rx_vlan_filter_all_portid,
3949                 NULL,
3950         },
3951 };
3952
3953 /* *** VLAN OFFLOAD SET ON A PORT *** */
3954 struct cmd_vlan_offload_result {
3955         cmdline_fixed_string_t vlan;
3956         cmdline_fixed_string_t set;
3957         cmdline_fixed_string_t vlan_type;
3958         cmdline_fixed_string_t what;
3959         cmdline_fixed_string_t on;
3960         cmdline_fixed_string_t port_id;
3961 };
3962
3963 static void
3964 cmd_vlan_offload_parsed(void *parsed_result,
3965                           __attribute__((unused)) struct cmdline *cl,
3966                           __attribute__((unused)) void *data)
3967 {
3968         int on;
3969         struct cmd_vlan_offload_result *res = parsed_result;
3970         char *str;
3971         int i, len = 0;
3972         portid_t port_id = 0;
3973         unsigned int tmp;
3974
3975         str = res->port_id;
3976         len = strnlen(str, STR_TOKEN_SIZE);
3977         i = 0;
3978         /* Get port_id first */
3979         while(i < len){
3980                 if(str[i] == ',')
3981                         break;
3982
3983                 i++;
3984         }
3985         str[i]='\0';
3986         tmp = strtoul(str, NULL, 0);
3987         /* If port_id greater that what portid_t can represent, return */
3988         if(tmp >= RTE_MAX_ETHPORTS)
3989                 return;
3990         port_id = (portid_t)tmp;
3991
3992         if (!strcmp(res->on, "on"))
3993                 on = 1;
3994         else
3995                 on = 0;
3996
3997         if (!strcmp(res->what, "strip"))
3998                 rx_vlan_strip_set(port_id,  on);
3999         else if(!strcmp(res->what, "stripq")){
4000                 uint16_t queue_id = 0;
4001
4002                 /* No queue_id, return */
4003                 if(i + 1 >= len) {
4004                         printf("must specify (port,queue_id)\n");
4005                         return;
4006                 }
4007                 tmp = strtoul(str + i + 1, NULL, 0);
4008                 /* If queue_id greater that what 16-bits can represent, return */
4009                 if(tmp > 0xffff)
4010                         return;
4011
4012                 queue_id = (uint16_t)tmp;
4013                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4014         }
4015         else if (!strcmp(res->what, "filter"))
4016                 rx_vlan_filter_set(port_id, on);
4017         else if (!strcmp(res->what, "qinq_strip"))
4018                 rx_vlan_qinq_strip_set(port_id, on);
4019         else
4020                 vlan_extend_set(port_id, on);
4021
4022         return;
4023 }
4024
4025 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4026         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4027                                  vlan, "vlan");
4028 cmdline_parse_token_string_t cmd_vlan_offload_set =
4029         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4030                                  set, "set");
4031 cmdline_parse_token_string_t cmd_vlan_offload_what =
4032         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4033                                 what, "strip#filter#qinq_strip#extend#stripq");
4034 cmdline_parse_token_string_t cmd_vlan_offload_on =
4035         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4036                               on, "on#off");
4037 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4038         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4039                               port_id, NULL);
4040
4041 cmdline_parse_inst_t cmd_vlan_offload = {
4042         .f = cmd_vlan_offload_parsed,
4043         .data = NULL,
4044         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4045                 "<port_id[,queue_id]>: "
4046                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4047         .tokens = {
4048                 (void *)&cmd_vlan_offload_vlan,
4049                 (void *)&cmd_vlan_offload_set,
4050                 (void *)&cmd_vlan_offload_what,
4051                 (void *)&cmd_vlan_offload_on,
4052                 (void *)&cmd_vlan_offload_portid,
4053                 NULL,
4054         },
4055 };
4056
4057 /* *** VLAN TPID SET ON A PORT *** */
4058 struct cmd_vlan_tpid_result {
4059         cmdline_fixed_string_t vlan;
4060         cmdline_fixed_string_t set;
4061         cmdline_fixed_string_t vlan_type;
4062         cmdline_fixed_string_t what;
4063         uint16_t tp_id;
4064         portid_t port_id;
4065 };
4066
4067 static void
4068 cmd_vlan_tpid_parsed(void *parsed_result,
4069                           __attribute__((unused)) struct cmdline *cl,
4070                           __attribute__((unused)) void *data)
4071 {
4072         struct cmd_vlan_tpid_result *res = parsed_result;
4073         enum rte_vlan_type vlan_type;
4074
4075         if (!strcmp(res->vlan_type, "inner"))
4076                 vlan_type = ETH_VLAN_TYPE_INNER;
4077         else if (!strcmp(res->vlan_type, "outer"))
4078                 vlan_type = ETH_VLAN_TYPE_OUTER;
4079         else {
4080                 printf("Unknown vlan type\n");
4081                 return;
4082         }
4083         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4084 }
4085
4086 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4087         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4088                                  vlan, "vlan");
4089 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4090         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4091                                  set, "set");
4092 cmdline_parse_token_string_t cmd_vlan_type =
4093         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4094                                  vlan_type, "inner#outer");
4095 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4096         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4097                                  what, "tpid");
4098 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4099         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4100                               tp_id, UINT16);
4101 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4102         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4103                               port_id, UINT16);
4104
4105 cmdline_parse_inst_t cmd_vlan_tpid = {
4106         .f = cmd_vlan_tpid_parsed,
4107         .data = NULL,
4108         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4109                 "Set the VLAN Ether type",
4110         .tokens = {
4111                 (void *)&cmd_vlan_tpid_vlan,
4112                 (void *)&cmd_vlan_tpid_set,
4113                 (void *)&cmd_vlan_type,
4114                 (void *)&cmd_vlan_tpid_what,
4115                 (void *)&cmd_vlan_tpid_tpid,
4116                 (void *)&cmd_vlan_tpid_portid,
4117                 NULL,
4118         },
4119 };
4120
4121 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4122 struct cmd_rx_vlan_filter_result {
4123         cmdline_fixed_string_t rx_vlan;
4124         cmdline_fixed_string_t what;
4125         uint16_t vlan_id;
4126         portid_t port_id;
4127 };
4128
4129 static void
4130 cmd_rx_vlan_filter_parsed(void *parsed_result,
4131                           __attribute__((unused)) struct cmdline *cl,
4132                           __attribute__((unused)) void *data)
4133 {
4134         struct cmd_rx_vlan_filter_result *res = parsed_result;
4135
4136         if (!strcmp(res->what, "add"))
4137                 rx_vft_set(res->port_id, res->vlan_id, 1);
4138         else
4139                 rx_vft_set(res->port_id, res->vlan_id, 0);
4140 }
4141
4142 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4143         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4144                                  rx_vlan, "rx_vlan");
4145 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4146         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4147                                  what, "add#rm");
4148 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4149         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4150                               vlan_id, UINT16);
4151 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4152         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4153                               port_id, UINT16);
4154
4155 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4156         .f = cmd_rx_vlan_filter_parsed,
4157         .data = NULL,
4158         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4159                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4160                 "identifiers filtered by a port",
4161         .tokens = {
4162                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4163                 (void *)&cmd_rx_vlan_filter_what,
4164                 (void *)&cmd_rx_vlan_filter_vlanid,
4165                 (void *)&cmd_rx_vlan_filter_portid,
4166                 NULL,
4167         },
4168 };
4169
4170 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4171 struct cmd_tx_vlan_set_result {
4172         cmdline_fixed_string_t tx_vlan;
4173         cmdline_fixed_string_t set;
4174         portid_t port_id;
4175         uint16_t vlan_id;
4176 };
4177
4178 static void
4179 cmd_tx_vlan_set_parsed(void *parsed_result,
4180                        __attribute__((unused)) struct cmdline *cl,
4181                        __attribute__((unused)) void *data)
4182 {
4183         struct cmd_tx_vlan_set_result *res = parsed_result;
4184
4185         if (!port_is_stopped(res->port_id)) {
4186                 printf("Please stop port %d first\n", res->port_id);
4187                 return;
4188         }
4189
4190         tx_vlan_set(res->port_id, res->vlan_id);
4191
4192         cmd_reconfig_device_queue(res->port_id, 1, 1);
4193 }
4194
4195 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4196         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4197                                  tx_vlan, "tx_vlan");
4198 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4199         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4200                                  set, "set");
4201 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4202         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4203                               port_id, UINT16);
4204 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4205         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4206                               vlan_id, UINT16);
4207
4208 cmdline_parse_inst_t cmd_tx_vlan_set = {
4209         .f = cmd_tx_vlan_set_parsed,
4210         .data = NULL,
4211         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4212                 "Enable hardware insertion of a single VLAN header "
4213                 "with a given TAG Identifier in packets sent on a port",
4214         .tokens = {
4215                 (void *)&cmd_tx_vlan_set_tx_vlan,
4216                 (void *)&cmd_tx_vlan_set_set,
4217                 (void *)&cmd_tx_vlan_set_portid,
4218                 (void *)&cmd_tx_vlan_set_vlanid,
4219                 NULL,
4220         },
4221 };
4222
4223 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4224 struct cmd_tx_vlan_set_qinq_result {
4225         cmdline_fixed_string_t tx_vlan;
4226         cmdline_fixed_string_t set;
4227         portid_t port_id;
4228         uint16_t vlan_id;
4229         uint16_t vlan_id_outer;
4230 };
4231
4232 static void
4233 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4234                             __attribute__((unused)) struct cmdline *cl,
4235                             __attribute__((unused)) void *data)
4236 {
4237         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4238
4239         if (!port_is_stopped(res->port_id)) {
4240                 printf("Please stop port %d first\n", res->port_id);
4241                 return;
4242         }
4243
4244         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4245
4246         cmd_reconfig_device_queue(res->port_id, 1, 1);
4247 }
4248
4249 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4250         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4251                 tx_vlan, "tx_vlan");
4252 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4253         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4254                 set, "set");
4255 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4256         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4257                 port_id, UINT16);
4258 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4259         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4260                 vlan_id, UINT16);
4261 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4262         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4263                 vlan_id_outer, UINT16);
4264
4265 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4266         .f = cmd_tx_vlan_set_qinq_parsed,
4267         .data = NULL,
4268         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4269                 "Enable hardware insertion of double VLAN header "
4270                 "with given TAG Identifiers in packets sent on a port",
4271         .tokens = {
4272                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4273                 (void *)&cmd_tx_vlan_set_qinq_set,
4274                 (void *)&cmd_tx_vlan_set_qinq_portid,
4275                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4276                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4277                 NULL,
4278         },
4279 };
4280
4281 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4282 struct cmd_tx_vlan_set_pvid_result {
4283         cmdline_fixed_string_t tx_vlan;
4284         cmdline_fixed_string_t set;
4285         cmdline_fixed_string_t pvid;
4286         portid_t port_id;
4287         uint16_t vlan_id;
4288         cmdline_fixed_string_t mode;
4289 };
4290
4291 static void
4292 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4293                             __attribute__((unused)) struct cmdline *cl,
4294                             __attribute__((unused)) void *data)
4295 {
4296         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4297
4298         if (strcmp(res->mode, "on") == 0)
4299                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4300         else
4301                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4302 }
4303
4304 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4305         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4306                                  tx_vlan, "tx_vlan");
4307 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4308         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4309                                  set, "set");
4310 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4311         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4312                                  pvid, "pvid");
4313 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4314         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4315                              port_id, UINT16);
4316 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4317         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4318                               vlan_id, UINT16);
4319 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4320         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4321                                  mode, "on#off");
4322
4323 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4324         .f = cmd_tx_vlan_set_pvid_parsed,
4325         .data = NULL,
4326         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4327         .tokens = {
4328                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4329                 (void *)&cmd_tx_vlan_set_pvid_set,
4330                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4331                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4332                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4333                 (void *)&cmd_tx_vlan_set_pvid_mode,
4334                 NULL,
4335         },
4336 };
4337
4338 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4339 struct cmd_tx_vlan_reset_result {
4340         cmdline_fixed_string_t tx_vlan;
4341         cmdline_fixed_string_t reset;
4342         portid_t port_id;
4343 };
4344
4345 static void
4346 cmd_tx_vlan_reset_parsed(void *parsed_result,
4347                          __attribute__((unused)) struct cmdline *cl,
4348                          __attribute__((unused)) void *data)
4349 {
4350         struct cmd_tx_vlan_reset_result *res = parsed_result;
4351
4352         if (!port_is_stopped(res->port_id)) {
4353                 printf("Please stop port %d first\n", res->port_id);
4354                 return;
4355         }
4356
4357         tx_vlan_reset(res->port_id);
4358
4359         cmd_reconfig_device_queue(res->port_id, 1, 1);
4360 }
4361
4362 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4363         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4364                                  tx_vlan, "tx_vlan");
4365 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4366         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4367                                  reset, "reset");
4368 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4369         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4370                               port_id, UINT16);
4371
4372 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4373         .f = cmd_tx_vlan_reset_parsed,
4374         .data = NULL,
4375         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4376                 "VLAN header in packets sent on a port",
4377         .tokens = {
4378                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4379                 (void *)&cmd_tx_vlan_reset_reset,
4380                 (void *)&cmd_tx_vlan_reset_portid,
4381                 NULL,
4382         },
4383 };
4384
4385
4386 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4387 struct cmd_csum_result {
4388         cmdline_fixed_string_t csum;
4389         cmdline_fixed_string_t mode;
4390         cmdline_fixed_string_t proto;
4391         cmdline_fixed_string_t hwsw;
4392         portid_t port_id;
4393 };
4394
4395 static void
4396 csum_show(int port_id)
4397 {
4398         struct rte_eth_dev_info dev_info;
4399         uint64_t tx_offloads;
4400         int ret;
4401
4402         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4403         printf("Parse tunnel is %s\n",
4404                 (ports[port_id].parse_tunnel) ? "on" : "off");
4405         printf("IP checksum offload is %s\n",
4406                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4407         printf("UDP checksum offload is %s\n",
4408                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4409         printf("TCP checksum offload is %s\n",
4410                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4411         printf("SCTP checksum offload is %s\n",
4412                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4413         printf("Outer-Ip checksum offload is %s\n",
4414                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4415         printf("Outer-Udp checksum offload is %s\n",
4416                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4417
4418         /* display warnings if configuration is not supported by the NIC */
4419         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4420         if (ret != 0)
4421                 return;
4422
4423         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4424                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4425                 printf("Warning: hardware IP checksum enabled but not "
4426                         "supported by port %d\n", port_id);
4427         }
4428         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4429                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4430                 printf("Warning: hardware UDP checksum enabled but not "
4431                         "supported by port %d\n", port_id);
4432         }
4433         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4434                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4435                 printf("Warning: hardware TCP checksum enabled but not "
4436                         "supported by port %d\n", port_id);
4437         }
4438         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4439                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4440                 printf("Warning: hardware SCTP checksum enabled but not "
4441                         "supported by port %d\n", port_id);
4442         }
4443         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4444                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4445                 printf("Warning: hardware outer IP checksum enabled but not "
4446                         "supported by port %d\n", port_id);
4447         }
4448         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4449                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4450                         == 0) {
4451                 printf("Warning: hardware outer UDP checksum enabled but not "
4452                         "supported by port %d\n", port_id);
4453         }
4454 }
4455
4456 static void
4457 cmd_config_queue_tx_offloads(struct rte_port *port)
4458 {
4459         int k;
4460
4461         /* Apply queue tx offloads configuration */
4462         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4463                 port->tx_conf[k].offloads =
4464                         port->dev_conf.txmode.offloads;
4465 }
4466
4467 static void
4468 cmd_csum_parsed(void *parsed_result,
4469                        __attribute__((unused)) struct cmdline *cl,
4470                        __attribute__((unused)) void *data)
4471 {
4472         struct cmd_csum_result *res = parsed_result;
4473         int hw = 0;
4474         uint64_t csum_offloads = 0;
4475         struct rte_eth_dev_info dev_info;
4476         int ret;
4477
4478         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4479                 printf("invalid port %d\n", res->port_id);
4480                 return;
4481         }
4482         if (!port_is_stopped(res->port_id)) {
4483                 printf("Please stop port %d first\n", res->port_id);
4484                 return;
4485         }
4486
4487         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4488         if (ret != 0)
4489                 return;
4490
4491         if (!strcmp(res->mode, "set")) {
4492
4493                 if (!strcmp(res->hwsw, "hw"))
4494                         hw = 1;
4495
4496                 if (!strcmp(res->proto, "ip")) {
4497                         if (hw == 0 || (dev_info.tx_offload_capa &
4498                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4499                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4500                         } else {
4501                                 printf("IP checksum offload is not supported "
4502                                        "by port %u\n", res->port_id);
4503                         }
4504                 } else if (!strcmp(res->proto, "udp")) {
4505                         if (hw == 0 || (dev_info.tx_offload_capa &
4506                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4507                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4508                         } else {
4509                                 printf("UDP checksum offload is not supported "
4510                                        "by port %u\n", res->port_id);
4511                         }
4512                 } else if (!strcmp(res->proto, "tcp")) {
4513                         if (hw == 0 || (dev_info.tx_offload_capa &
4514                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4515                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4516                         } else {
4517                                 printf("TCP checksum offload is not supported "
4518                                        "by port %u\n", res->port_id);
4519                         }
4520                 } else if (!strcmp(res->proto, "sctp")) {
4521                         if (hw == 0 || (dev_info.tx_offload_capa &
4522                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4523                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4524                         } else {
4525                                 printf("SCTP checksum offload is not supported "
4526                                        "by port %u\n", res->port_id);
4527                         }
4528                 } else if (!strcmp(res->proto, "outer-ip")) {
4529                         if (hw == 0 || (dev_info.tx_offload_capa &
4530                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4531                                 csum_offloads |=
4532                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4533                         } else {
4534                                 printf("Outer IP checksum offload is not "
4535                                        "supported by port %u\n", res->port_id);
4536                         }
4537                 } else if (!strcmp(res->proto, "outer-udp")) {
4538                         if (hw == 0 || (dev_info.tx_offload_capa &
4539                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4540                                 csum_offloads |=
4541                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4542                         } else {
4543                                 printf("Outer UDP checksum offload is not "
4544                                        "supported by port %u\n", res->port_id);
4545                         }
4546                 }
4547
4548                 if (hw) {
4549                         ports[res->port_id].dev_conf.txmode.offloads |=
4550                                                         csum_offloads;
4551                 } else {
4552                         ports[res->port_id].dev_conf.txmode.offloads &=
4553                                                         (~csum_offloads);
4554                 }
4555                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4556         }
4557         csum_show(res->port_id);
4558
4559         cmd_reconfig_device_queue(res->port_id, 1, 1);
4560 }
4561
4562 cmdline_parse_token_string_t cmd_csum_csum =
4563         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4564                                 csum, "csum");
4565 cmdline_parse_token_string_t cmd_csum_mode =
4566         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4567                                 mode, "set");
4568 cmdline_parse_token_string_t cmd_csum_proto =
4569         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4570                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4571 cmdline_parse_token_string_t cmd_csum_hwsw =
4572         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4573                                 hwsw, "hw#sw");
4574 cmdline_parse_token_num_t cmd_csum_portid =
4575         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4576                                 port_id, UINT16);
4577
4578 cmdline_parse_inst_t cmd_csum_set = {
4579         .f = cmd_csum_parsed,
4580         .data = NULL,
4581         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4582                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4583                 "using csum forward engine",
4584         .tokens = {
4585                 (void *)&cmd_csum_csum,
4586                 (void *)&cmd_csum_mode,
4587                 (void *)&cmd_csum_proto,
4588                 (void *)&cmd_csum_hwsw,
4589                 (void *)&cmd_csum_portid,
4590                 NULL,
4591         },
4592 };
4593
4594 cmdline_parse_token_string_t cmd_csum_mode_show =
4595         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4596                                 mode, "show");
4597
4598 cmdline_parse_inst_t cmd_csum_show = {
4599         .f = cmd_csum_parsed,
4600         .data = NULL,
4601         .help_str = "csum show <port_id>: Show checksum offload configuration",
4602         .tokens = {
4603                 (void *)&cmd_csum_csum,
4604                 (void *)&cmd_csum_mode_show,
4605                 (void *)&cmd_csum_portid,
4606                 NULL,
4607         },
4608 };
4609
4610 /* Enable/disable tunnel parsing */
4611 struct cmd_csum_tunnel_result {
4612         cmdline_fixed_string_t csum;
4613         cmdline_fixed_string_t parse;
4614         cmdline_fixed_string_t onoff;
4615         portid_t port_id;
4616 };
4617
4618 static void
4619 cmd_csum_tunnel_parsed(void *parsed_result,
4620                        __attribute__((unused)) struct cmdline *cl,
4621                        __attribute__((unused)) void *data)
4622 {
4623         struct cmd_csum_tunnel_result *res = parsed_result;
4624
4625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4626                 return;
4627
4628         if (!strcmp(res->onoff, "on"))
4629                 ports[res->port_id].parse_tunnel = 1;
4630         else
4631                 ports[res->port_id].parse_tunnel = 0;
4632
4633         csum_show(res->port_id);
4634 }
4635
4636 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4637         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4638                                 csum, "csum");
4639 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4640         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4641                                 parse, "parse-tunnel");
4642 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4643         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4644                                 onoff, "on#off");
4645 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4646         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4647                                 port_id, UINT16);
4648
4649 cmdline_parse_inst_t cmd_csum_tunnel = {
4650         .f = cmd_csum_tunnel_parsed,
4651         .data = NULL,
4652         .help_str = "csum parse-tunnel on|off <port_id>: "
4653                 "Enable/Disable parsing of tunnels for csum engine",
4654         .tokens = {
4655                 (void *)&cmd_csum_tunnel_csum,
4656                 (void *)&cmd_csum_tunnel_parse,
4657                 (void *)&cmd_csum_tunnel_onoff,
4658                 (void *)&cmd_csum_tunnel_portid,
4659                 NULL,
4660         },
4661 };
4662
4663 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4664 struct cmd_tso_set_result {
4665         cmdline_fixed_string_t tso;
4666         cmdline_fixed_string_t mode;
4667         uint16_t tso_segsz;
4668         portid_t port_id;
4669 };
4670
4671 static void
4672 cmd_tso_set_parsed(void *parsed_result,
4673                        __attribute__((unused)) struct cmdline *cl,
4674                        __attribute__((unused)) void *data)
4675 {
4676         struct cmd_tso_set_result *res = parsed_result;
4677         struct rte_eth_dev_info dev_info;
4678         int ret;
4679
4680         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4681                 return;
4682         if (!port_is_stopped(res->port_id)) {
4683                 printf("Please stop port %d first\n", res->port_id);
4684                 return;
4685         }
4686
4687         if (!strcmp(res->mode, "set"))
4688                 ports[res->port_id].tso_segsz = res->tso_segsz;
4689
4690         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4691         if (ret != 0)
4692                 return;
4693
4694         if ((ports[res->port_id].tso_segsz != 0) &&
4695                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4696                 printf("Error: TSO is not supported by port %d\n",
4697                        res->port_id);
4698                 return;
4699         }
4700
4701         if (ports[res->port_id].tso_segsz == 0) {
4702                 ports[res->port_id].dev_conf.txmode.offloads &=
4703                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4704                 printf("TSO for non-tunneled packets is disabled\n");
4705         } else {
4706                 ports[res->port_id].dev_conf.txmode.offloads |=
4707                                                 DEV_TX_OFFLOAD_TCP_TSO;
4708                 printf("TSO segment size for non-tunneled packets is %d\n",
4709                         ports[res->port_id].tso_segsz);
4710         }
4711         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4712
4713         /* display warnings if configuration is not supported by the NIC */
4714         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4715         if (ret != 0)
4716                 return;
4717
4718         if ((ports[res->port_id].tso_segsz != 0) &&
4719                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4720                 printf("Warning: TSO enabled but not "
4721                         "supported by port %d\n", res->port_id);
4722         }
4723
4724         cmd_reconfig_device_queue(res->port_id, 1, 1);
4725 }
4726
4727 cmdline_parse_token_string_t cmd_tso_set_tso =
4728         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4729                                 tso, "tso");
4730 cmdline_parse_token_string_t cmd_tso_set_mode =
4731         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4732                                 mode, "set");
4733 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4734         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4735                                 tso_segsz, UINT16);
4736 cmdline_parse_token_num_t cmd_tso_set_portid =
4737         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4738                                 port_id, UINT16);
4739
4740 cmdline_parse_inst_t cmd_tso_set = {
4741         .f = cmd_tso_set_parsed,
4742         .data = NULL,
4743         .help_str = "tso set <tso_segsz> <port_id>: "
4744                 "Set TSO segment size of non-tunneled packets for csum engine "
4745                 "(0 to disable)",
4746         .tokens = {
4747                 (void *)&cmd_tso_set_tso,
4748                 (void *)&cmd_tso_set_mode,
4749                 (void *)&cmd_tso_set_tso_segsz,
4750                 (void *)&cmd_tso_set_portid,
4751                 NULL,
4752         },
4753 };
4754
4755 cmdline_parse_token_string_t cmd_tso_show_mode =
4756         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4757                                 mode, "show");
4758
4759
4760 cmdline_parse_inst_t cmd_tso_show = {
4761         .f = cmd_tso_set_parsed,
4762         .data = NULL,
4763         .help_str = "tso show <port_id>: "
4764                 "Show TSO segment size of non-tunneled packets for csum engine",
4765         .tokens = {
4766                 (void *)&cmd_tso_set_tso,
4767                 (void *)&cmd_tso_show_mode,
4768                 (void *)&cmd_tso_set_portid,
4769                 NULL,
4770         },
4771 };
4772
4773 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4774 struct cmd_tunnel_tso_set_result {
4775         cmdline_fixed_string_t tso;
4776         cmdline_fixed_string_t mode;
4777         uint16_t tso_segsz;
4778         portid_t port_id;
4779 };
4780
4781 static struct rte_eth_dev_info
4782 check_tunnel_tso_nic_support(portid_t port_id)
4783 {
4784         struct rte_eth_dev_info dev_info;
4785
4786         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4787                 return dev_info;
4788
4789         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4790                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4791                        "not enabled for port %d\n", port_id);
4792         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4793                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4794                        "not enabled for port %d\n", port_id);
4795         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4796                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4797                        "not enabled for port %d\n", port_id);
4798         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4799                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4800                        "not enabled for port %d\n", port_id);
4801         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4802                 printf("Warning: IP TUNNEL TSO not supported therefore "
4803                        "not enabled for port %d\n", port_id);
4804         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4805                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4806                        "not enabled for port %d\n", port_id);
4807         return dev_info;
4808 }
4809
4810 static void
4811 cmd_tunnel_tso_set_parsed(void *parsed_result,
4812                           __attribute__((unused)) struct cmdline *cl,
4813                           __attribute__((unused)) void *data)
4814 {
4815         struct cmd_tunnel_tso_set_result *res = parsed_result;
4816         struct rte_eth_dev_info dev_info;
4817
4818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4819                 return;
4820         if (!port_is_stopped(res->port_id)) {
4821                 printf("Please stop port %d first\n", res->port_id);
4822                 return;
4823         }
4824
4825         if (!strcmp(res->mode, "set"))
4826                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4827
4828         dev_info = check_tunnel_tso_nic_support(res->port_id);
4829         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4830                 ports[res->port_id].dev_conf.txmode.offloads &=
4831                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4832                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4833                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4834                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4835                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4836                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4837                 printf("TSO for tunneled packets is disabled\n");
4838         } else {
4839                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4840                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4841                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4842                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4843                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4844                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4845
4846                 ports[res->port_id].dev_conf.txmode.offloads |=
4847                         (tso_offloads & dev_info.tx_offload_capa);
4848                 printf("TSO segment size for tunneled packets is %d\n",
4849                         ports[res->port_id].tunnel_tso_segsz);
4850
4851                 /* Below conditions are needed to make it work:
4852                  * (1) tunnel TSO is supported by the NIC;
4853                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4854                  * are recognized;
4855                  * (3) for tunneled pkts with outer L3 of IPv4,
4856                  * "csum set outer-ip" must be set to hw, because after tso,
4857                  * total_len of outer IP header is changed, and the checksum
4858                  * of outer IP header calculated by sw should be wrong; that
4859                  * is not necessary for IPv6 tunneled pkts because there's no
4860                  * checksum in IP header anymore.
4861                  */
4862
4863                 if (!ports[res->port_id].parse_tunnel)
4864                         printf("Warning: csum parse_tunnel must be set "
4865                                 "so that tunneled packets are recognized\n");
4866                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4867                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4868                         printf("Warning: csum set outer-ip must be set to hw "
4869                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4870         }
4871
4872         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4873         cmd_reconfig_device_queue(res->port_id, 1, 1);
4874 }
4875
4876 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4877         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4878                                 tso, "tunnel_tso");
4879 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4880         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4881                                 mode, "set");
4882 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4883         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4884                                 tso_segsz, UINT16);
4885 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4886         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4887                                 port_id, UINT16);
4888
4889 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4890         .f = cmd_tunnel_tso_set_parsed,
4891         .data = NULL,
4892         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4893                 "Set TSO segment size of tunneled packets for csum engine "
4894                 "(0 to disable)",
4895         .tokens = {
4896                 (void *)&cmd_tunnel_tso_set_tso,
4897                 (void *)&cmd_tunnel_tso_set_mode,
4898                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4899                 (void *)&cmd_tunnel_tso_set_portid,
4900                 NULL,
4901         },
4902 };
4903
4904 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4905         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4906                                 mode, "show");
4907
4908
4909 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4910         .f = cmd_tunnel_tso_set_parsed,
4911         .data = NULL,
4912         .help_str = "tunnel_tso show <port_id> "
4913                 "Show TSO segment size of tunneled packets for csum engine",
4914         .tokens = {
4915                 (void *)&cmd_tunnel_tso_set_tso,
4916                 (void *)&cmd_tunnel_tso_show_mode,
4917                 (void *)&cmd_tunnel_tso_set_portid,
4918                 NULL,
4919         },
4920 };
4921
4922 /* *** SET GRO FOR A PORT *** */
4923 struct cmd_gro_enable_result {
4924         cmdline_fixed_string_t cmd_set;
4925         cmdline_fixed_string_t cmd_port;
4926         cmdline_fixed_string_t cmd_keyword;
4927         cmdline_fixed_string_t cmd_onoff;
4928         portid_t cmd_pid;
4929 };
4930
4931 static void
4932 cmd_gro_enable_parsed(void *parsed_result,
4933                 __attribute__((unused)) struct cmdline *cl,
4934                 __attribute__((unused)) void *data)
4935 {
4936         struct cmd_gro_enable_result *res;
4937
4938         res = parsed_result;
4939         if (!strcmp(res->cmd_keyword, "gro"))
4940                 setup_gro(res->cmd_onoff, res->cmd_pid);
4941 }
4942
4943 cmdline_parse_token_string_t cmd_gro_enable_set =
4944         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4945                         cmd_set, "set");
4946 cmdline_parse_token_string_t cmd_gro_enable_port =
4947         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4948                         cmd_keyword, "port");
4949 cmdline_parse_token_num_t cmd_gro_enable_pid =
4950         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4951                         cmd_pid, UINT16);
4952 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4953         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4954                         cmd_keyword, "gro");
4955 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4956         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4957                         cmd_onoff, "on#off");
4958
4959 cmdline_parse_inst_t cmd_gro_enable = {
4960         .f = cmd_gro_enable_parsed,
4961         .data = NULL,
4962         .help_str = "set port <port_id> gro on|off",
4963         .tokens = {
4964                 (void *)&cmd_gro_enable_set,
4965                 (void *)&cmd_gro_enable_port,
4966                 (void *)&cmd_gro_enable_pid,
4967                 (void *)&cmd_gro_enable_keyword,
4968                 (void *)&cmd_gro_enable_onoff,
4969                 NULL,
4970         },
4971 };
4972
4973 /* *** DISPLAY GRO CONFIGURATION *** */
4974 struct cmd_gro_show_result {
4975         cmdline_fixed_string_t cmd_show;
4976         cmdline_fixed_string_t cmd_port;
4977         cmdline_fixed_string_t cmd_keyword;
4978         portid_t cmd_pid;
4979 };
4980
4981 static void
4982 cmd_gro_show_parsed(void *parsed_result,
4983                 __attribute__((unused)) struct cmdline *cl,
4984                 __attribute__((unused)) void *data)
4985 {
4986         struct cmd_gro_show_result *res;
4987
4988         res = parsed_result;
4989         if (!strcmp(res->cmd_keyword, "gro"))
4990                 show_gro(res->cmd_pid);
4991 }
4992
4993 cmdline_parse_token_string_t cmd_gro_show_show =
4994         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4995                         cmd_show, "show");
4996 cmdline_parse_token_string_t cmd_gro_show_port =
4997         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4998                         cmd_port, "port");
4999 cmdline_parse_token_num_t cmd_gro_show_pid =
5000         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5001                         cmd_pid, UINT16);
5002 cmdline_parse_token_string_t cmd_gro_show_keyword =
5003         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5004                         cmd_keyword, "gro");
5005
5006 cmdline_parse_inst_t cmd_gro_show = {
5007         .f = cmd_gro_show_parsed,
5008         .data = NULL,
5009         .help_str = "show port <port_id> gro",
5010         .tokens = {
5011                 (void *)&cmd_gro_show_show,
5012                 (void *)&cmd_gro_show_port,
5013                 (void *)&cmd_gro_show_pid,
5014                 (void *)&cmd_gro_show_keyword,
5015                 NULL,
5016         },
5017 };
5018
5019 /* *** SET FLUSH CYCLES FOR GRO *** */
5020 struct cmd_gro_flush_result {
5021         cmdline_fixed_string_t cmd_set;
5022         cmdline_fixed_string_t cmd_keyword;
5023         cmdline_fixed_string_t cmd_flush;
5024         uint8_t cmd_cycles;
5025 };
5026
5027 static void
5028 cmd_gro_flush_parsed(void *parsed_result,
5029                 __attribute__((unused)) struct cmdline *cl,
5030                 __attribute__((unused)) void *data)
5031 {
5032         struct cmd_gro_flush_result *res;
5033
5034         res = parsed_result;
5035         if ((!strcmp(res->cmd_keyword, "gro")) &&
5036                         (!strcmp(res->cmd_flush, "flush")))
5037                 setup_gro_flush_cycles(res->cmd_cycles);
5038 }
5039
5040 cmdline_parse_token_string_t cmd_gro_flush_set =
5041         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5042                         cmd_set, "set");
5043 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5044         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5045                         cmd_keyword, "gro");
5046 cmdline_parse_token_string_t cmd_gro_flush_flush =
5047         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5048                         cmd_flush, "flush");
5049 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5050         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5051                         cmd_cycles, UINT8);
5052
5053 cmdline_parse_inst_t cmd_gro_flush = {
5054         .f = cmd_gro_flush_parsed,
5055         .data = NULL,
5056         .help_str = "set gro flush <cycles>",
5057         .tokens = {
5058                 (void *)&cmd_gro_flush_set,
5059                 (void *)&cmd_gro_flush_keyword,
5060                 (void *)&cmd_gro_flush_flush,
5061                 (void *)&cmd_gro_flush_cycles,
5062                 NULL,
5063         },
5064 };
5065
5066 /* *** ENABLE/DISABLE GSO *** */
5067 struct cmd_gso_enable_result {
5068         cmdline_fixed_string_t cmd_set;
5069         cmdline_fixed_string_t cmd_port;
5070         cmdline_fixed_string_t cmd_keyword;
5071         cmdline_fixed_string_t cmd_mode;
5072         portid_t cmd_pid;
5073 };
5074
5075 static void
5076 cmd_gso_enable_parsed(void *parsed_result,
5077                 __attribute__((unused)) struct cmdline *cl,
5078                 __attribute__((unused)) void *data)
5079 {
5080         struct cmd_gso_enable_result *res;
5081
5082         res = parsed_result;
5083         if (!strcmp(res->cmd_keyword, "gso"))
5084                 setup_gso(res->cmd_mode, res->cmd_pid);
5085 }
5086
5087 cmdline_parse_token_string_t cmd_gso_enable_set =
5088         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5089                         cmd_set, "set");
5090 cmdline_parse_token_string_t cmd_gso_enable_port =
5091         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5092                         cmd_port, "port");
5093 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5094         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5095                         cmd_keyword, "gso");
5096 cmdline_parse_token_string_t cmd_gso_enable_mode =
5097         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5098                         cmd_mode, "on#off");
5099 cmdline_parse_token_num_t cmd_gso_enable_pid =
5100         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5101                         cmd_pid, UINT16);
5102
5103 cmdline_parse_inst_t cmd_gso_enable = {
5104         .f = cmd_gso_enable_parsed,
5105         .data = NULL,
5106         .help_str = "set port <port_id> gso on|off",
5107         .tokens = {
5108                 (void *)&cmd_gso_enable_set,
5109                 (void *)&cmd_gso_enable_port,
5110                 (void *)&cmd_gso_enable_pid,
5111                 (void *)&cmd_gso_enable_keyword,
5112                 (void *)&cmd_gso_enable_mode,
5113                 NULL,
5114         },
5115 };
5116
5117 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5118 struct cmd_gso_size_result {
5119         cmdline_fixed_string_t cmd_set;
5120         cmdline_fixed_string_t cmd_keyword;
5121         cmdline_fixed_string_t cmd_segsz;
5122         uint16_t cmd_size;
5123 };
5124
5125 static void
5126 cmd_gso_size_parsed(void *parsed_result,
5127                        __attribute__((unused)) struct cmdline *cl,
5128                        __attribute__((unused)) void *data)
5129 {
5130         struct cmd_gso_size_result *res = parsed_result;
5131
5132         if (test_done == 0) {
5133                 printf("Before setting GSO segsz, please first"
5134                                 " stop fowarding\n");
5135                 return;
5136         }
5137
5138         if (!strcmp(res->cmd_keyword, "gso") &&
5139                         !strcmp(res->cmd_segsz, "segsz")) {
5140                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5141                         printf("gso_size should be larger than %zu."
5142                                         " Please input a legal value\n",
5143                                         RTE_GSO_SEG_SIZE_MIN);
5144                 else
5145                         gso_max_segment_size = res->cmd_size;
5146         }
5147 }
5148
5149 cmdline_parse_token_string_t cmd_gso_size_set =
5150         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5151                                 cmd_set, "set");
5152 cmdline_parse_token_string_t cmd_gso_size_keyword =
5153         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5154                                 cmd_keyword, "gso");
5155 cmdline_parse_token_string_t cmd_gso_size_segsz =
5156         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5157                                 cmd_segsz, "segsz");
5158 cmdline_parse_token_num_t cmd_gso_size_size =
5159         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5160                                 cmd_size, UINT16);
5161
5162 cmdline_parse_inst_t cmd_gso_size = {
5163         .f = cmd_gso_size_parsed,
5164         .data = NULL,
5165         .help_str = "set gso segsz <length>",
5166         .tokens = {
5167                 (void *)&cmd_gso_size_set,
5168                 (void *)&cmd_gso_size_keyword,
5169                 (void *)&cmd_gso_size_segsz,
5170                 (void *)&cmd_gso_size_size,
5171                 NULL,
5172         },
5173 };
5174
5175 /* *** SHOW GSO CONFIGURATION *** */
5176 struct cmd_gso_show_result {
5177         cmdline_fixed_string_t cmd_show;
5178         cmdline_fixed_string_t cmd_port;
5179         cmdline_fixed_string_t cmd_keyword;
5180         portid_t cmd_pid;
5181 };
5182
5183 static void
5184 cmd_gso_show_parsed(void *parsed_result,
5185                        __attribute__((unused)) struct cmdline *cl,
5186                        __attribute__((unused)) void *data)
5187 {
5188         struct cmd_gso_show_result *res = parsed_result;
5189
5190         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5191                 printf("invalid port id %u\n", res->cmd_pid);
5192                 return;
5193         }
5194         if (!strcmp(res->cmd_keyword, "gso")) {
5195                 if (gso_ports[res->cmd_pid].enable) {
5196                         printf("Max GSO'd packet size: %uB\n"
5197                                         "Supported GSO types: TCP/IPv4, "
5198                                         "UDP/IPv4, VxLAN with inner "
5199                                         "TCP/IPv4 packet, GRE with inner "
5200                                         "TCP/IPv4 packet\n",
5201                                         gso_max_segment_size);
5202                 } else
5203                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5204         }
5205 }
5206
5207 cmdline_parse_token_string_t cmd_gso_show_show =
5208 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5209                 cmd_show, "show");
5210 cmdline_parse_token_string_t cmd_gso_show_port =
5211 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5212                 cmd_port, "port");
5213 cmdline_parse_token_string_t cmd_gso_show_keyword =
5214         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5215                                 cmd_keyword, "gso");
5216 cmdline_parse_token_num_t cmd_gso_show_pid =
5217         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5218                                 cmd_pid, UINT16);
5219
5220 cmdline_parse_inst_t cmd_gso_show = {
5221         .f = cmd_gso_show_parsed,
5222         .data = NULL,
5223         .help_str = "show port <port_id> gso",
5224         .tokens = {
5225                 (void *)&cmd_gso_show_show,
5226                 (void *)&cmd_gso_show_port,
5227                 (void *)&cmd_gso_show_pid,
5228                 (void *)&cmd_gso_show_keyword,
5229                 NULL,
5230         },
5231 };
5232
5233 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5234 struct cmd_set_flush_rx {
5235         cmdline_fixed_string_t set;
5236         cmdline_fixed_string_t flush_rx;
5237         cmdline_fixed_string_t mode;
5238 };
5239
5240 static void
5241 cmd_set_flush_rx_parsed(void *parsed_result,
5242                 __attribute__((unused)) struct cmdline *cl,
5243                 __attribute__((unused)) void *data)
5244 {
5245         struct cmd_set_flush_rx *res = parsed_result;
5246         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5247 }
5248
5249 cmdline_parse_token_string_t cmd_setflushrx_set =
5250         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5251                         set, "set");
5252 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5253         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5254                         flush_rx, "flush_rx");
5255 cmdline_parse_token_string_t cmd_setflushrx_mode =
5256         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5257                         mode, "on#off");
5258
5259
5260 cmdline_parse_inst_t cmd_set_flush_rx = {
5261         .f = cmd_set_flush_rx_parsed,
5262         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5263         .data = NULL,
5264         .tokens = {
5265                 (void *)&cmd_setflushrx_set,
5266                 (void *)&cmd_setflushrx_flush_rx,
5267                 (void *)&cmd_setflushrx_mode,
5268                 NULL,
5269         },
5270 };
5271
5272 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5273 struct cmd_set_link_check {
5274         cmdline_fixed_string_t set;
5275         cmdline_fixed_string_t link_check;
5276         cmdline_fixed_string_t mode;
5277 };
5278
5279 static void
5280 cmd_set_link_check_parsed(void *parsed_result,
5281                 __attribute__((unused)) struct cmdline *cl,
5282                 __attribute__((unused)) void *data)
5283 {
5284         struct cmd_set_link_check *res = parsed_result;
5285         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5286 }
5287
5288 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5289         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5290                         set, "set");
5291 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5292         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5293                         link_check, "link_check");
5294 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5295         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5296                         mode, "on#off");
5297
5298
5299 cmdline_parse_inst_t cmd_set_link_check = {
5300         .f = cmd_set_link_check_parsed,
5301         .help_str = "set link_check on|off: Enable/Disable link status check "
5302                     "when starting/stopping a port",
5303         .data = NULL,
5304         .tokens = {
5305                 (void *)&cmd_setlinkcheck_set,
5306                 (void *)&cmd_setlinkcheck_link_check,
5307                 (void *)&cmd_setlinkcheck_mode,
5308                 NULL,
5309         },
5310 };
5311
5312 /* *** SET NIC BYPASS MODE *** */
5313 struct cmd_set_bypass_mode_result {
5314         cmdline_fixed_string_t set;
5315         cmdline_fixed_string_t bypass;
5316         cmdline_fixed_string_t mode;
5317         cmdline_fixed_string_t value;
5318         portid_t port_id;
5319 };
5320
5321 static void
5322 cmd_set_bypass_mode_parsed(void *parsed_result,
5323                 __attribute__((unused)) struct cmdline *cl,
5324                 __attribute__((unused)) void *data)
5325 {
5326         struct cmd_set_bypass_mode_result *res = parsed_result;
5327         portid_t port_id = res->port_id;
5328         int32_t rc = -EINVAL;
5329
5330 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5331         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5332
5333         if (!strcmp(res->value, "bypass"))
5334                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5335         else if (!strcmp(res->value, "isolate"))
5336                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5337         else
5338                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5339
5340         /* Set the bypass mode for the relevant port. */
5341         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5342 #endif
5343         if (rc != 0)
5344                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5345 }
5346
5347 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5348         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5349                         set, "set");
5350 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5351         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5352                         bypass, "bypass");
5353 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5354         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5355                         mode, "mode");
5356 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5357         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5358                         value, "normal#bypass#isolate");
5359 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5360         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5361                                 port_id, UINT16);
5362
5363 cmdline_parse_inst_t cmd_set_bypass_mode = {
5364         .f = cmd_set_bypass_mode_parsed,
5365         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5366                     "Set the NIC bypass mode for port_id",
5367         .data = NULL,
5368         .tokens = {
5369                 (void *)&cmd_setbypass_mode_set,
5370                 (void *)&cmd_setbypass_mode_bypass,
5371                 (void *)&cmd_setbypass_mode_mode,
5372                 (void *)&cmd_setbypass_mode_value,
5373                 (void *)&cmd_setbypass_mode_port,
5374                 NULL,
5375         },
5376 };
5377
5378 /* *** SET NIC BYPASS EVENT *** */
5379 struct cmd_set_bypass_event_result {
5380         cmdline_fixed_string_t set;
5381         cmdline_fixed_string_t bypass;
5382         cmdline_fixed_string_t event;
5383         cmdline_fixed_string_t event_value;
5384         cmdline_fixed_string_t mode;
5385         cmdline_fixed_string_t mode_value;
5386         portid_t port_id;
5387 };
5388
5389 static void
5390 cmd_set_bypass_event_parsed(void *parsed_result,
5391                 __attribute__((unused)) struct cmdline *cl,
5392                 __attribute__((unused)) void *data)
5393 {
5394         int32_t rc = -EINVAL;
5395         struct cmd_set_bypass_event_result *res = parsed_result;
5396         portid_t port_id = res->port_id;
5397
5398 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5399         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5400         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5401
5402         if (!strcmp(res->event_value, "timeout"))
5403                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5404         else if (!strcmp(res->event_value, "os_on"))
5405                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5406         else if (!strcmp(res->event_value, "os_off"))
5407                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5408         else if (!strcmp(res->event_value, "power_on"))
5409                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5410         else if (!strcmp(res->event_value, "power_off"))
5411                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5412         else
5413                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5414
5415         if (!strcmp(res->mode_value, "bypass"))
5416                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5417         else if (!strcmp(res->mode_value, "isolate"))
5418                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5419         else
5420                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5421
5422         /* Set the watchdog timeout. */
5423         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5424
5425                 rc = -EINVAL;
5426                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5427                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5428                                                            bypass_timeout);
5429                 }
5430                 if (rc != 0) {
5431                         printf("Failed to set timeout value %u "
5432                         "for port %d, errto code: %d.\n",
5433                         bypass_timeout, port_id, rc);
5434                 }
5435         }
5436
5437         /* Set the bypass event to transition to bypass mode. */
5438         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5439                                               bypass_mode);
5440 #endif
5441
5442         if (rc != 0)
5443                 printf("\t Failed to set bypass event for port = %d.\n",
5444                        port_id);
5445 }
5446
5447 cmdline_parse_token_string_t cmd_setbypass_event_set =
5448         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5449                         set, "set");
5450 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5451         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5452                         bypass, "bypass");
5453 cmdline_parse_token_string_t cmd_setbypass_event_event =
5454         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5455                         event, "event");
5456 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5457         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5458                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5459 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5460         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5461                         mode, "mode");
5462 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5463         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5464                         mode_value, "normal#bypass#isolate");
5465 cmdline_parse_token_num_t cmd_setbypass_event_port =
5466         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5467                                 port_id, UINT16);
5468
5469 cmdline_parse_inst_t cmd_set_bypass_event = {
5470         .f = cmd_set_bypass_event_parsed,
5471         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5472                 "power_off mode normal|bypass|isolate <port_id>: "
5473                 "Set the NIC bypass event mode for port_id",
5474         .data = NULL,
5475         .tokens = {
5476                 (void *)&cmd_setbypass_event_set,
5477                 (void *)&cmd_setbypass_event_bypass,
5478                 (void *)&cmd_setbypass_event_event,
5479                 (void *)&cmd_setbypass_event_event_value,
5480                 (void *)&cmd_setbypass_event_mode,
5481                 (void *)&cmd_setbypass_event_mode_value,
5482                 (void *)&cmd_setbypass_event_port,
5483                 NULL,
5484         },
5485 };
5486
5487
5488 /* *** SET NIC BYPASS TIMEOUT *** */
5489 struct cmd_set_bypass_timeout_result {
5490         cmdline_fixed_string_t set;
5491         cmdline_fixed_string_t bypass;
5492         cmdline_fixed_string_t timeout;
5493         cmdline_fixed_string_t value;
5494 };
5495
5496 static void
5497 cmd_set_bypass_timeout_parsed(void *parsed_result,
5498                 __attribute__((unused)) struct cmdline *cl,
5499                 __attribute__((unused)) void *data)
5500 {
5501         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5502
5503 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5504         if (!strcmp(res->value, "1.5"))
5505                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5506         else if (!strcmp(res->value, "2"))
5507                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5508         else if (!strcmp(res->value, "3"))
5509                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5510         else if (!strcmp(res->value, "4"))
5511                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5512         else if (!strcmp(res->value, "8"))
5513                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5514         else if (!strcmp(res->value, "16"))
5515                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5516         else if (!strcmp(res->value, "32"))
5517                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5518         else
5519                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5520 #endif
5521 }
5522
5523 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5524         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5525                         set, "set");
5526 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5527         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5528                         bypass, "bypass");
5529 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5530         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5531                         timeout, "timeout");
5532 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5534                         value, "0#1.5#2#3#4#8#16#32");
5535
5536 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5537         .f = cmd_set_bypass_timeout_parsed,
5538         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5539                 "Set the NIC bypass watchdog timeout in seconds",
5540         .data = NULL,
5541         .tokens = {
5542                 (void *)&cmd_setbypass_timeout_set,
5543                 (void *)&cmd_setbypass_timeout_bypass,
5544                 (void *)&cmd_setbypass_timeout_timeout,
5545                 (void *)&cmd_setbypass_timeout_value,
5546                 NULL,
5547         },
5548 };
5549
5550 /* *** SHOW NIC BYPASS MODE *** */
5551 struct cmd_show_bypass_config_result {
5552         cmdline_fixed_string_t show;
5553         cmdline_fixed_string_t bypass;
5554         cmdline_fixed_string_t config;
5555         portid_t port_id;
5556 };
5557
5558 static void
5559 cmd_show_bypass_config_parsed(void *parsed_result,
5560                 __attribute__((unused)) struct cmdline *cl,
5561                 __attribute__((unused)) void *data)
5562 {
5563         struct cmd_show_bypass_config_result *res = parsed_result;
5564         portid_t port_id = res->port_id;
5565         int rc = -EINVAL;
5566 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5567         uint32_t event_mode;
5568         uint32_t bypass_mode;
5569         uint32_t timeout = bypass_timeout;
5570         unsigned int i;
5571
5572         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5573                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5574         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5575                 {"UNKNOWN", "normal", "bypass", "isolate"};
5576         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5577                 "NONE",
5578                 "OS/board on",
5579                 "power supply on",
5580                 "OS/board off",
5581                 "power supply off",
5582                 "timeout"};
5583
5584         /* Display the bypass mode.*/
5585         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5586                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5587                 return;
5588         }
5589         else {
5590                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5591                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5592
5593                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5594         }
5595
5596         /* Display the bypass timeout.*/
5597         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5598                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5599
5600         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5601
5602         /* Display the bypass events and associated modes. */
5603         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5604
5605                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5606                         printf("\tFailed to get bypass mode for event = %s\n",
5607                                 events[i]);
5608                 } else {
5609                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5610                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5611
5612                         printf("\tbypass event: %-16s = %s\n", events[i],
5613                                 modes[event_mode]);
5614                 }
5615         }
5616 #endif
5617         if (rc != 0)
5618                 printf("\tFailed to get bypass configuration for port = %d\n",
5619                        port_id);
5620 }
5621
5622 cmdline_parse_token_string_t cmd_showbypass_config_show =
5623         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5624                         show, "show");
5625 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5626         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5627                         bypass, "bypass");
5628 cmdline_parse_token_string_t cmd_showbypass_config_config =
5629         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5630                         config, "config");
5631 cmdline_parse_token_num_t cmd_showbypass_config_port =
5632         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5633                                 port_id, UINT16);
5634
5635 cmdline_parse_inst_t cmd_show_bypass_config = {
5636         .f = cmd_show_bypass_config_parsed,
5637         .help_str = "show bypass config <port_id>: "
5638                     "Show the NIC bypass config for port_id",
5639         .data = NULL,
5640         .tokens = {
5641                 (void *)&cmd_showbypass_config_show,
5642                 (void *)&cmd_showbypass_config_bypass,
5643                 (void *)&cmd_showbypass_config_config,
5644                 (void *)&cmd_showbypass_config_port,
5645                 NULL,
5646         },
5647 };
5648
5649 #ifdef RTE_LIBRTE_PMD_BOND
5650 /* *** SET BONDING MODE *** */
5651 struct cmd_set_bonding_mode_result {
5652         cmdline_fixed_string_t set;
5653         cmdline_fixed_string_t bonding;
5654         cmdline_fixed_string_t mode;
5655         uint8_t value;
5656         portid_t port_id;
5657 };
5658
5659 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5660                 __attribute__((unused))  struct cmdline *cl,
5661                 __attribute__((unused)) void *data)
5662 {
5663         struct cmd_set_bonding_mode_result *res = parsed_result;
5664         portid_t port_id = res->port_id;
5665
5666         /* Set the bonding mode for the relevant port. */
5667         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5668                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5669 }
5670
5671 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5672 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5673                 set, "set");
5674 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5675 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5676                 bonding, "bonding");
5677 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5678 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5679                 mode, "mode");
5680 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5681 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5682                 value, UINT8);
5683 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5684 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5685                 port_id, UINT16);
5686
5687 cmdline_parse_inst_t cmd_set_bonding_mode = {
5688                 .f = cmd_set_bonding_mode_parsed,
5689                 .help_str = "set bonding mode <mode_value> <port_id>: "
5690                         "Set the bonding mode for port_id",
5691                 .data = NULL,
5692                 .tokens = {
5693                                 (void *) &cmd_setbonding_mode_set,
5694                                 (void *) &cmd_setbonding_mode_bonding,
5695                                 (void *) &cmd_setbonding_mode_mode,
5696                                 (void *) &cmd_setbonding_mode_value,
5697                                 (void *) &cmd_setbonding_mode_port,
5698                                 NULL
5699                 }
5700 };
5701
5702 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5703 struct cmd_set_bonding_lacp_dedicated_queues_result {
5704         cmdline_fixed_string_t set;
5705         cmdline_fixed_string_t bonding;
5706         cmdline_fixed_string_t lacp;
5707         cmdline_fixed_string_t dedicated_queues;
5708         portid_t port_id;
5709         cmdline_fixed_string_t mode;
5710 };
5711
5712 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5713                 __attribute__((unused))  struct cmdline *cl,
5714                 __attribute__((unused)) void *data)
5715 {
5716         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5717         portid_t port_id = res->port_id;
5718         struct rte_port *port;
5719
5720         port = &ports[port_id];
5721
5722         /** Check if the port is not started **/
5723         if (port->port_status != RTE_PORT_STOPPED) {
5724                 printf("Please stop port %d first\n", port_id);
5725                 return;
5726         }
5727
5728         if (!strcmp(res->mode, "enable")) {
5729                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5730                         printf("Dedicate queues for LACP control packets"
5731                                         " enabled\n");
5732                 else
5733                         printf("Enabling dedicate queues for LACP control "
5734                                         "packets on port %d failed\n", port_id);
5735         } else if (!strcmp(res->mode, "disable")) {
5736                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5737                         printf("Dedicated queues for LACP control packets "
5738                                         "disabled\n");
5739                 else
5740                         printf("Disabling dedicated queues for LACP control "
5741                                         "traffic on port %d failed\n", port_id);
5742         }
5743 }
5744
5745 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5746 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5747                 set, "set");
5748 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5749 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5750                 bonding, "bonding");
5751 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5752 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5753                 lacp, "lacp");
5754 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5755 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5756                 dedicated_queues, "dedicated_queues");
5757 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5758 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5759                 port_id, UINT16);
5760 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5761 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5762                 mode, "enable#disable");
5763
5764 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5765                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5766                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5767                         "enable|disable: "
5768                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5769                 .data = NULL,
5770                 .tokens = {
5771                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5772                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5773                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5774                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5775                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5776                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5777                         NULL
5778                 }
5779 };
5780
5781 /* *** SET BALANCE XMIT POLICY *** */
5782 struct cmd_set_bonding_balance_xmit_policy_result {
5783         cmdline_fixed_string_t set;
5784         cmdline_fixed_string_t bonding;
5785         cmdline_fixed_string_t balance_xmit_policy;
5786         portid_t port_id;
5787         cmdline_fixed_string_t policy;
5788 };
5789
5790 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5791                 __attribute__((unused))  struct cmdline *cl,
5792                 __attribute__((unused)) void *data)
5793 {
5794         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5795         portid_t port_id = res->port_id;
5796         uint8_t policy;
5797
5798         if (!strcmp(res->policy, "l2")) {
5799                 policy = BALANCE_XMIT_POLICY_LAYER2;
5800         } else if (!strcmp(res->policy, "l23")) {
5801                 policy = BALANCE_XMIT_POLICY_LAYER23;
5802         } else if (!strcmp(res->policy, "l34")) {
5803                 policy = BALANCE_XMIT_POLICY_LAYER34;
5804         } else {
5805                 printf("\t Invalid xmit policy selection");
5806                 return;
5807         }
5808
5809         /* Set the bonding mode for the relevant port. */
5810         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5811                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5812                                 port_id);
5813         }
5814 }
5815
5816 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5817 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5818                 set, "set");
5819 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5820 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5821                 bonding, "bonding");
5822 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5823 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5824                 balance_xmit_policy, "balance_xmit_policy");
5825 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5826 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5827                 port_id, UINT16);
5828 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5829 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5830                 policy, "l2#l23#l34");
5831
5832 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5833                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5834                 .help_str = "set bonding balance_xmit_policy <port_id> "
5835                         "l2|l23|l34: "
5836                         "Set the bonding balance_xmit_policy for port_id",
5837                 .data = NULL,
5838                 .tokens = {
5839                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5840                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5841                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5842                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5843                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5844                                 NULL
5845                 }
5846 };
5847
5848 /* *** SHOW NIC BONDING CONFIGURATION *** */
5849 struct cmd_show_bonding_config_result {
5850         cmdline_fixed_string_t show;
5851         cmdline_fixed_string_t bonding;
5852         cmdline_fixed_string_t config;
5853         portid_t port_id;
5854 };
5855
5856 static void cmd_show_bonding_config_parsed(void *parsed_result,
5857                 __attribute__((unused))  struct cmdline *cl,
5858                 __attribute__((unused)) void *data)
5859 {
5860         struct cmd_show_bonding_config_result *res = parsed_result;
5861         int bonding_mode, agg_mode;
5862         portid_t slaves[RTE_MAX_ETHPORTS];
5863         int num_slaves, num_active_slaves;
5864         int primary_id;
5865         int i;
5866         portid_t port_id = res->port_id;
5867
5868         /* Display the bonding mode.*/
5869         bonding_mode = rte_eth_bond_mode_get(port_id);
5870         if (bonding_mode < 0) {
5871                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5872                 return;
5873         } else
5874                 printf("\tBonding mode: %d\n", bonding_mode);
5875
5876         if (bonding_mode == BONDING_MODE_BALANCE) {
5877                 int balance_xmit_policy;
5878
5879                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5880                 if (balance_xmit_policy < 0) {
5881                         printf("\tFailed to get balance xmit policy for port = %d\n",
5882                                         port_id);
5883                         return;
5884                 } else {
5885                         printf("\tBalance Xmit Policy: ");
5886
5887                         switch (balance_xmit_policy) {
5888                         case BALANCE_XMIT_POLICY_LAYER2:
5889                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5890                                 break;
5891                         case BALANCE_XMIT_POLICY_LAYER23:
5892                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5893                                 break;
5894                         case BALANCE_XMIT_POLICY_LAYER34:
5895                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5896                                 break;
5897                         }
5898                         printf("\n");
5899                 }
5900         }
5901
5902         if (bonding_mode == BONDING_MODE_8023AD) {
5903                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5904                 printf("\tIEEE802.3AD Aggregator Mode: ");
5905                 switch (agg_mode) {
5906                 case AGG_BANDWIDTH:
5907                         printf("bandwidth");
5908                         break;
5909                 case AGG_STABLE:
5910                         printf("stable");
5911                         break;
5912                 case AGG_COUNT:
5913                         printf("count");
5914                         break;
5915                 }
5916                 printf("\n");
5917         }
5918
5919         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5920
5921         if (num_slaves < 0) {
5922                 printf("\tFailed to get slave list for port = %d\n", port_id);
5923                 return;
5924         }
5925         if (num_slaves > 0) {
5926                 printf("\tSlaves (%d): [", num_slaves);
5927                 for (i = 0; i < num_slaves - 1; i++)
5928                         printf("%d ", slaves[i]);
5929
5930                 printf("%d]\n", slaves[num_slaves - 1]);
5931         } else {
5932                 printf("\tSlaves: []\n");
5933
5934         }
5935
5936         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5937                         RTE_MAX_ETHPORTS);
5938
5939         if (num_active_slaves < 0) {
5940                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5941                 return;
5942         }
5943         if (num_active_slaves > 0) {
5944                 printf("\tActive Slaves (%d): [", num_active_slaves);
5945                 for (i = 0; i < num_active_slaves - 1; i++)
5946                         printf("%d ", slaves[i]);
5947
5948                 printf("%d]\n", slaves[num_active_slaves - 1]);
5949
5950         } else {
5951                 printf("\tActive Slaves: []\n");
5952
5953         }
5954
5955         primary_id = rte_eth_bond_primary_get(port_id);
5956         if (primary_id < 0) {
5957                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5958                 return;
5959         } else
5960                 printf("\tPrimary: [%d]\n", primary_id);
5961
5962 }
5963
5964 cmdline_parse_token_string_t cmd_showbonding_config_show =
5965 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5966                 show, "show");
5967 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5968 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5969                 bonding, "bonding");
5970 cmdline_parse_token_string_t cmd_showbonding_config_config =
5971 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5972                 config, "config");
5973 cmdline_parse_token_num_t cmd_showbonding_config_port =
5974 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5975                 port_id, UINT16);
5976
5977 cmdline_parse_inst_t cmd_show_bonding_config = {
5978                 .f = cmd_show_bonding_config_parsed,
5979                 .help_str = "show bonding config <port_id>: "
5980                         "Show the bonding config for port_id",
5981                 .data = NULL,
5982                 .tokens = {
5983                                 (void *)&cmd_showbonding_config_show,
5984                                 (void *)&cmd_showbonding_config_bonding,
5985                                 (void *)&cmd_showbonding_config_config,
5986                                 (void *)&cmd_showbonding_config_port,
5987                                 NULL
5988                 }
5989 };
5990
5991 /* *** SET BONDING PRIMARY *** */
5992 struct cmd_set_bonding_primary_result {
5993         cmdline_fixed_string_t set;
5994         cmdline_fixed_string_t bonding;
5995         cmdline_fixed_string_t primary;
5996         portid_t slave_id;
5997         portid_t port_id;
5998 };
5999
6000 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6001                 __attribute__((unused))  struct cmdline *cl,
6002                 __attribute__((unused)) void *data)
6003 {
6004         struct cmd_set_bonding_primary_result *res = parsed_result;
6005         portid_t master_port_id = res->port_id;
6006         portid_t slave_port_id = res->slave_id;
6007
6008         /* Set the primary slave for a bonded device. */
6009         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6010                 printf("\t Failed to set primary slave for port = %d.\n",
6011                                 master_port_id);
6012                 return;
6013         }
6014         init_port_config();
6015 }
6016
6017 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6018 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6019                 set, "set");
6020 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6021 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6022                 bonding, "bonding");
6023 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6024 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6025                 primary, "primary");
6026 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6027 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6028                 slave_id, UINT16);
6029 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6030 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6031                 port_id, UINT16);
6032
6033 cmdline_parse_inst_t cmd_set_bonding_primary = {
6034                 .f = cmd_set_bonding_primary_parsed,
6035                 .help_str = "set bonding primary <slave_id> <port_id>: "
6036                         "Set the primary slave for port_id",
6037                 .data = NULL,
6038                 .tokens = {
6039                                 (void *)&cmd_setbonding_primary_set,
6040                                 (void *)&cmd_setbonding_primary_bonding,
6041                                 (void *)&cmd_setbonding_primary_primary,
6042                                 (void *)&cmd_setbonding_primary_slave,
6043                                 (void *)&cmd_setbonding_primary_port,
6044                                 NULL
6045                 }
6046 };
6047
6048 /* *** ADD SLAVE *** */
6049 struct cmd_add_bonding_slave_result {
6050         cmdline_fixed_string_t add;
6051         cmdline_fixed_string_t bonding;
6052         cmdline_fixed_string_t slave;
6053         portid_t slave_id;
6054         portid_t port_id;
6055 };
6056
6057 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6058                 __attribute__((unused))  struct cmdline *cl,
6059                 __attribute__((unused)) void *data)
6060 {
6061         struct cmd_add_bonding_slave_result *res = parsed_result;
6062         portid_t master_port_id = res->port_id;
6063         portid_t slave_port_id = res->slave_id;
6064
6065         /* add the slave for a bonded device. */
6066         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6067                 printf("\t Failed to add slave %d to master port = %d.\n",
6068                                 slave_port_id, master_port_id);
6069                 return;
6070         }
6071         init_port_config();
6072         set_port_slave_flag(slave_port_id);
6073 }
6074
6075 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6076 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6077                 add, "add");
6078 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6079 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6080                 bonding, "bonding");
6081 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6082 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6083                 slave, "slave");
6084 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6085 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6086                 slave_id, UINT16);
6087 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6088 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6089                 port_id, UINT16);
6090
6091 cmdline_parse_inst_t cmd_add_bonding_slave = {
6092                 .f = cmd_add_bonding_slave_parsed,
6093                 .help_str = "add bonding slave <slave_id> <port_id>: "
6094                         "Add a slave device to a bonded device",
6095                 .data = NULL,
6096                 .tokens = {
6097                                 (void *)&cmd_addbonding_slave_add,
6098                                 (void *)&cmd_addbonding_slave_bonding,
6099                                 (void *)&cmd_addbonding_slave_slave,
6100                                 (void *)&cmd_addbonding_slave_slaveid,
6101                                 (void *)&cmd_addbonding_slave_port,
6102                                 NULL
6103                 }
6104 };
6105
6106 /* *** REMOVE SLAVE *** */
6107 struct cmd_remove_bonding_slave_result {
6108         cmdline_fixed_string_t remove;
6109         cmdline_fixed_string_t bonding;
6110         cmdline_fixed_string_t slave;
6111         portid_t slave_id;
6112         portid_t port_id;
6113 };
6114
6115 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6116                 __attribute__((unused))  struct cmdline *cl,
6117                 __attribute__((unused)) void *data)
6118 {
6119         struct cmd_remove_bonding_slave_result *res = parsed_result;
6120         portid_t master_port_id = res->port_id;
6121         portid_t slave_port_id = res->slave_id;
6122
6123         /* remove the slave from a bonded device. */
6124         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6125                 printf("\t Failed to remove slave %d from master port = %d.\n",
6126                                 slave_port_id, master_port_id);
6127                 return;
6128         }
6129         init_port_config();
6130         clear_port_slave_flag(slave_port_id);
6131 }
6132
6133 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6134                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6135                                 remove, "remove");
6136 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6137                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6138                                 bonding, "bonding");
6139 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6140                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6141                                 slave, "slave");
6142 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6143                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6144                                 slave_id, UINT16);
6145 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6146                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6147                                 port_id, UINT16);
6148
6149 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6150                 .f = cmd_remove_bonding_slave_parsed,
6151                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6152                         "Remove a slave device from a bonded device",
6153                 .data = NULL,
6154                 .tokens = {
6155                                 (void *)&cmd_removebonding_slave_remove,
6156                                 (void *)&cmd_removebonding_slave_bonding,
6157                                 (void *)&cmd_removebonding_slave_slave,
6158                                 (void *)&cmd_removebonding_slave_slaveid,
6159                                 (void *)&cmd_removebonding_slave_port,
6160                                 NULL
6161                 }
6162 };
6163
6164 /* *** CREATE BONDED DEVICE *** */
6165 struct cmd_create_bonded_device_result {
6166         cmdline_fixed_string_t create;
6167         cmdline_fixed_string_t bonded;
6168         cmdline_fixed_string_t device;
6169         uint8_t mode;
6170         uint8_t socket;
6171 };
6172
6173 static int bond_dev_num = 0;
6174
6175 static void cmd_create_bonded_device_parsed(void *parsed_result,
6176                 __attribute__((unused))  struct cmdline *cl,
6177                 __attribute__((unused)) void *data)
6178 {
6179         struct cmd_create_bonded_device_result *res = parsed_result;
6180         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6181         int port_id;
6182         int ret;
6183
6184         if (test_done == 0) {
6185                 printf("Please stop forwarding first\n");
6186                 return;
6187         }
6188
6189         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6190                         bond_dev_num++);
6191
6192         /* Create a new bonded device. */
6193         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6194         if (port_id < 0) {
6195                 printf("\t Failed to create bonded device.\n");
6196                 return;
6197         } else {
6198                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6199                                 port_id);
6200
6201                 /* Update number of ports */
6202                 nb_ports = rte_eth_dev_count_avail();
6203                 reconfig(port_id, res->socket);
6204                 ret = rte_eth_promiscuous_enable(port_id);
6205                 if (ret != 0)
6206                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6207                                 port_id, rte_strerror(-ret));
6208
6209                 ports[port_id].need_setup = 0;
6210                 ports[port_id].port_status = RTE_PORT_STOPPED;
6211         }
6212
6213 }
6214
6215 cmdline_parse_token_string_t cmd_createbonded_device_create =
6216                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6217                                 create, "create");
6218 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6219                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6220                                 bonded, "bonded");
6221 cmdline_parse_token_string_t cmd_createbonded_device_device =
6222                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6223                                 device, "device");
6224 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6225                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6226                                 mode, UINT8);
6227 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6228                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6229                                 socket, UINT8);
6230
6231 cmdline_parse_inst_t cmd_create_bonded_device = {
6232                 .f = cmd_create_bonded_device_parsed,
6233                 .help_str = "create bonded device <mode> <socket>: "
6234                         "Create a new bonded device with specific bonding mode and socket",
6235                 .data = NULL,
6236                 .tokens = {
6237                                 (void *)&cmd_createbonded_device_create,
6238                                 (void *)&cmd_createbonded_device_bonded,
6239                                 (void *)&cmd_createbonded_device_device,
6240                                 (void *)&cmd_createbonded_device_mode,
6241                                 (void *)&cmd_createbonded_device_socket,
6242                                 NULL
6243                 }
6244 };
6245
6246 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6247 struct cmd_set_bond_mac_addr_result {
6248         cmdline_fixed_string_t set;
6249         cmdline_fixed_string_t bonding;
6250         cmdline_fixed_string_t mac_addr;
6251         uint16_t port_num;
6252         struct rte_ether_addr address;
6253 };
6254
6255 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6256                 __attribute__((unused))  struct cmdline *cl,
6257                 __attribute__((unused)) void *data)
6258 {
6259         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6260         int ret;
6261
6262         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6263                 return;
6264
6265         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6266
6267         /* check the return value and print it if is < 0 */
6268         if (ret < 0)
6269                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6270 }
6271
6272 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6273                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6274 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6275                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6276                                 "bonding");
6277 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6278                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6279                                 "mac_addr");
6280 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6281                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6282                                 port_num, UINT16);
6283 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6284                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6285
6286 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6287                 .f = cmd_set_bond_mac_addr_parsed,
6288                 .data = (void *) 0,
6289                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6290                 .tokens = {
6291                                 (void *)&cmd_set_bond_mac_addr_set,
6292                                 (void *)&cmd_set_bond_mac_addr_bonding,
6293                                 (void *)&cmd_set_bond_mac_addr_mac,
6294                                 (void *)&cmd_set_bond_mac_addr_portnum,
6295                                 (void *)&cmd_set_bond_mac_addr_addr,
6296                                 NULL
6297                 }
6298 };
6299
6300
6301 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6302 struct cmd_set_bond_mon_period_result {
6303         cmdline_fixed_string_t set;
6304         cmdline_fixed_string_t bonding;
6305         cmdline_fixed_string_t mon_period;
6306         uint16_t port_num;
6307         uint32_t period_ms;
6308 };
6309
6310 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6311                 __attribute__((unused))  struct cmdline *cl,
6312                 __attribute__((unused)) void *data)
6313 {
6314         struct cmd_set_bond_mon_period_result *res = parsed_result;
6315         int ret;
6316
6317         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6318
6319         /* check the return value and print it if is < 0 */
6320         if (ret < 0)
6321                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6322 }
6323
6324 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6325                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6326                                 set, "set");
6327 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6328                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6329                                 bonding, "bonding");
6330 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6331                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6332                                 mon_period,     "mon_period");
6333 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6334                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6335                                 port_num, UINT16);
6336 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6337                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6338                                 period_ms, UINT32);
6339
6340 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6341                 .f = cmd_set_bond_mon_period_parsed,
6342                 .data = (void *) 0,
6343                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6344                 .tokens = {
6345                                 (void *)&cmd_set_bond_mon_period_set,
6346                                 (void *)&cmd_set_bond_mon_period_bonding,
6347                                 (void *)&cmd_set_bond_mon_period_mon_period,
6348                                 (void *)&cmd_set_bond_mon_period_portnum,
6349                                 (void *)&cmd_set_bond_mon_period_period_ms,
6350                                 NULL
6351                 }
6352 };
6353
6354
6355
6356 struct cmd_set_bonding_agg_mode_policy_result {
6357         cmdline_fixed_string_t set;
6358         cmdline_fixed_string_t bonding;
6359         cmdline_fixed_string_t agg_mode;
6360         uint16_t port_num;
6361         cmdline_fixed_string_t policy;
6362 };
6363
6364
6365 static void
6366 cmd_set_bonding_agg_mode(void *parsed_result,
6367                 __attribute__((unused)) struct cmdline *cl,
6368                 __attribute__((unused)) void *data)
6369 {
6370         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6371         uint8_t policy = AGG_BANDWIDTH;
6372
6373         if (!strcmp(res->policy, "bandwidth"))
6374                 policy = AGG_BANDWIDTH;
6375         else if (!strcmp(res->policy, "stable"))
6376                 policy = AGG_STABLE;
6377         else if (!strcmp(res->policy, "count"))
6378                 policy = AGG_COUNT;
6379
6380         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6381 }
6382
6383
6384 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6385         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6386                                 set, "set");
6387 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6388         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6389                                 bonding, "bonding");
6390
6391 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6392         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6393                                 agg_mode, "agg_mode");
6394
6395 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6396         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6397                                 port_num, UINT16);
6398
6399 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6400         TOKEN_STRING_INITIALIZER(
6401                         struct cmd_set_bonding_balance_xmit_policy_result,
6402                 policy, "stable#bandwidth#count");
6403
6404 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6405         .f = cmd_set_bonding_agg_mode,
6406         .data = (void *) 0,
6407         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6408         .tokens = {
6409                         (void *)&cmd_set_bonding_agg_mode_set,
6410                         (void *)&cmd_set_bonding_agg_mode_bonding,
6411                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6412                         (void *)&cmd_set_bonding_agg_mode_portnum,
6413                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6414                         NULL
6415                 }
6416 };
6417
6418
6419 #endif /* RTE_LIBRTE_PMD_BOND */
6420
6421 /* *** SET FORWARDING MODE *** */
6422 struct cmd_set_fwd_mode_result {
6423         cmdline_fixed_string_t set;
6424         cmdline_fixed_string_t fwd;
6425         cmdline_fixed_string_t mode;
6426 };
6427
6428 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6429                                     __attribute__((unused)) struct cmdline *cl,
6430                                     __attribute__((unused)) void *data)
6431 {
6432         struct cmd_set_fwd_mode_result *res = parsed_result;
6433
6434         retry_enabled = 0;
6435         set_pkt_forwarding_mode(res->mode);
6436 }
6437
6438 cmdline_parse_token_string_t cmd_setfwd_set =
6439         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6440 cmdline_parse_token_string_t cmd_setfwd_fwd =
6441         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6442 cmdline_parse_token_string_t cmd_setfwd_mode =
6443         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6444                 "" /* defined at init */);
6445
6446 cmdline_parse_inst_t cmd_set_fwd_mode = {
6447         .f = cmd_set_fwd_mode_parsed,
6448         .data = NULL,
6449         .help_str = NULL, /* defined at init */
6450         .tokens = {
6451                 (void *)&cmd_setfwd_set,
6452                 (void *)&cmd_setfwd_fwd,
6453                 (void *)&cmd_setfwd_mode,
6454                 NULL,
6455         },
6456 };
6457
6458 static void cmd_set_fwd_mode_init(void)
6459 {
6460         char *modes, *c;
6461         static char token[128];
6462         static char help[256];
6463         cmdline_parse_token_string_t *token_struct;
6464
6465         modes = list_pkt_forwarding_modes();
6466         snprintf(help, sizeof(help), "set fwd %s: "
6467                 "Set packet forwarding mode", modes);
6468         cmd_set_fwd_mode.help_str = help;
6469
6470         /* string token separator is # */
6471         for (c = token; *modes != '\0'; modes++)
6472                 if (*modes == '|')
6473                         *c++ = '#';
6474                 else
6475                         *c++ = *modes;
6476         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6477         token_struct->string_data.str = token;
6478 }
6479
6480 /* *** SET RETRY FORWARDING MODE *** */
6481 struct cmd_set_fwd_retry_mode_result {
6482         cmdline_fixed_string_t set;
6483         cmdline_fixed_string_t fwd;
6484         cmdline_fixed_string_t mode;
6485         cmdline_fixed_string_t retry;
6486 };
6487
6488 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6489                             __attribute__((unused)) struct cmdline *cl,
6490                             __attribute__((unused)) void *data)
6491 {
6492         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6493
6494         retry_enabled = 1;
6495         set_pkt_forwarding_mode(res->mode);
6496 }
6497
6498 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6499         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6500                         set, "set");
6501 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6502         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6503                         fwd, "fwd");
6504 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6505         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6506                         mode,
6507                 "" /* defined at init */);
6508 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6509         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6510                         retry, "retry");
6511
6512 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6513         .f = cmd_set_fwd_retry_mode_parsed,
6514         .data = NULL,
6515         .help_str = NULL, /* defined at init */
6516         .tokens = {
6517                 (void *)&cmd_setfwd_retry_set,
6518                 (void *)&cmd_setfwd_retry_fwd,
6519                 (void *)&cmd_setfwd_retry_mode,
6520                 (void *)&cmd_setfwd_retry_retry,
6521                 NULL,
6522         },
6523 };
6524
6525 static void cmd_set_fwd_retry_mode_init(void)
6526 {
6527         char *modes, *c;
6528         static char token[128];
6529         static char help[256];
6530         cmdline_parse_token_string_t *token_struct;
6531
6532         modes = list_pkt_forwarding_retry_modes();
6533         snprintf(help, sizeof(help), "set fwd %s retry: "
6534                 "Set packet forwarding mode with retry", modes);
6535         cmd_set_fwd_retry_mode.help_str = help;
6536
6537         /* string token separator is # */
6538         for (c = token; *modes != '\0'; modes++)
6539                 if (*modes == '|')
6540                         *c++ = '#';
6541                 else
6542                         *c++ = *modes;
6543         token_struct = (cmdline_parse_token_string_t *)
6544                 cmd_set_fwd_retry_mode.tokens[2];
6545         token_struct->string_data.str = token;
6546 }
6547
6548 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6549 struct cmd_set_burst_tx_retry_result {
6550         cmdline_fixed_string_t set;
6551         cmdline_fixed_string_t burst;
6552         cmdline_fixed_string_t tx;
6553         cmdline_fixed_string_t delay;
6554         uint32_t time;
6555         cmdline_fixed_string_t retry;
6556         uint32_t retry_num;
6557 };
6558
6559 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6560                                         __attribute__((unused)) struct cmdline *cl,
6561                                         __attribute__((unused)) void *data)
6562 {
6563         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6564
6565         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6566                 && !strcmp(res->tx, "tx")) {
6567                 if (!strcmp(res->delay, "delay"))
6568                         burst_tx_delay_time = res->time;
6569                 if (!strcmp(res->retry, "retry"))
6570                         burst_tx_retry_num = res->retry_num;
6571         }
6572
6573 }
6574
6575 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6576         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6577 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6578         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6579                                  "burst");
6580 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6581         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6582 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6583         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6584 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6585         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6586 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6587         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6588 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6589         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6590
6591 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6592         .f = cmd_set_burst_tx_retry_parsed,
6593         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6594         .tokens = {
6595                 (void *)&cmd_set_burst_tx_retry_set,
6596                 (void *)&cmd_set_burst_tx_retry_burst,
6597                 (void *)&cmd_set_burst_tx_retry_tx,
6598                 (void *)&cmd_set_burst_tx_retry_delay,
6599                 (void *)&cmd_set_burst_tx_retry_time,
6600                 (void *)&cmd_set_burst_tx_retry_retry,
6601                 (void *)&cmd_set_burst_tx_retry_retry_num,
6602                 NULL,
6603         },
6604 };
6605
6606 /* *** SET PROMISC MODE *** */
6607 struct cmd_set_promisc_mode_result {
6608         cmdline_fixed_string_t set;
6609         cmdline_fixed_string_t promisc;
6610         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6611         uint16_t port_num;               /* valid if "allports" argument == 0 */
6612         cmdline_fixed_string_t mode;
6613 };
6614
6615 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6616                                         __attribute__((unused)) struct cmdline *cl,
6617                                         void *allports)
6618 {
6619         struct cmd_set_promisc_mode_result *res = parsed_result;
6620         int enable;
6621         portid_t i;
6622
6623         if (!strcmp(res->mode, "on"))
6624                 enable = 1;
6625         else
6626                 enable = 0;
6627
6628         /* all ports */
6629         if (allports) {
6630                 RTE_ETH_FOREACH_DEV(i)
6631                         eth_set_promisc_mode(i, enable);
6632         } else {
6633                 eth_set_promisc_mode(res->port_num, enable);
6634         }
6635 }
6636
6637 cmdline_parse_token_string_t cmd_setpromisc_set =
6638         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6639 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6640         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6641                                  "promisc");
6642 cmdline_parse_token_string_t cmd_setpromisc_portall =
6643         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6644                                  "all");
6645 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6646         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6647                               UINT16);
6648 cmdline_parse_token_string_t cmd_setpromisc_mode =
6649         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6650                                  "on#off");
6651
6652 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6653         .f = cmd_set_promisc_mode_parsed,
6654         .data = (void *)1,
6655         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6656         .tokens = {
6657                 (void *)&cmd_setpromisc_set,
6658                 (void *)&cmd_setpromisc_promisc,
6659                 (void *)&cmd_setpromisc_portall,
6660                 (void *)&cmd_setpromisc_mode,
6661                 NULL,
6662         },
6663 };
6664
6665 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6666         .f = cmd_set_promisc_mode_parsed,
6667         .data = (void *)0,
6668         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6669         .tokens = {
6670                 (void *)&cmd_setpromisc_set,
6671                 (void *)&cmd_setpromisc_promisc,
6672                 (void *)&cmd_setpromisc_portnum,
6673                 (void *)&cmd_setpromisc_mode,
6674                 NULL,
6675         },
6676 };
6677
6678 /* *** SET ALLMULTI MODE *** */
6679 struct cmd_set_allmulti_mode_result {
6680         cmdline_fixed_string_t set;
6681         cmdline_fixed_string_t allmulti;
6682         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6683         uint16_t port_num;               /* valid if "allports" argument == 0 */
6684         cmdline_fixed_string_t mode;
6685 };
6686
6687 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6688                                         __attribute__((unused)) struct cmdline *cl,
6689                                         void *allports)
6690 {
6691         struct cmd_set_allmulti_mode_result *res = parsed_result;
6692         int enable;
6693         portid_t i;
6694
6695         if (!strcmp(res->mode, "on"))
6696                 enable = 1;
6697         else
6698                 enable = 0;
6699
6700         /* all ports */
6701         if (allports) {
6702                 RTE_ETH_FOREACH_DEV(i) {
6703                         eth_set_allmulticast_mode(i, enable);
6704                 }
6705         }
6706         else {
6707                 eth_set_allmulticast_mode(res->port_num, enable);
6708         }
6709 }
6710
6711 cmdline_parse_token_string_t cmd_setallmulti_set =
6712         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6713 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6714         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6715                                  "allmulti");
6716 cmdline_parse_token_string_t cmd_setallmulti_portall =
6717         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6718                                  "all");
6719 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6720         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6721                               UINT16);
6722 cmdline_parse_token_string_t cmd_setallmulti_mode =
6723         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6724                                  "on#off");
6725
6726 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6727         .f = cmd_set_allmulti_mode_parsed,
6728         .data = (void *)1,
6729         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6730         .tokens = {
6731                 (void *)&cmd_setallmulti_set,
6732                 (void *)&cmd_setallmulti_allmulti,
6733                 (void *)&cmd_setallmulti_portall,
6734                 (void *)&cmd_setallmulti_mode,
6735                 NULL,
6736         },
6737 };
6738
6739 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6740         .f = cmd_set_allmulti_mode_parsed,
6741         .data = (void *)0,
6742         .help_str = "set allmulti <port_id> on|off: "
6743                 "Set allmulti mode on port_id",
6744         .tokens = {
6745                 (void *)&cmd_setallmulti_set,
6746                 (void *)&cmd_setallmulti_allmulti,
6747                 (void *)&cmd_setallmulti_portnum,
6748                 (void *)&cmd_setallmulti_mode,
6749                 NULL,
6750         },
6751 };
6752
6753 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6754 struct cmd_link_flow_ctrl_set_result {
6755         cmdline_fixed_string_t set;
6756         cmdline_fixed_string_t flow_ctrl;
6757         cmdline_fixed_string_t rx;
6758         cmdline_fixed_string_t rx_lfc_mode;
6759         cmdline_fixed_string_t tx;
6760         cmdline_fixed_string_t tx_lfc_mode;
6761         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6762         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6763         cmdline_fixed_string_t autoneg_str;
6764         cmdline_fixed_string_t autoneg;
6765         cmdline_fixed_string_t hw_str;
6766         uint32_t high_water;
6767         cmdline_fixed_string_t lw_str;
6768         uint32_t low_water;
6769         cmdline_fixed_string_t pt_str;
6770         uint16_t pause_time;
6771         cmdline_fixed_string_t xon_str;
6772         uint16_t send_xon;
6773         portid_t port_id;
6774 };
6775
6776 cmdline_parse_token_string_t cmd_lfc_set_set =
6777         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6778                                 set, "set");
6779 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6780         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6781                                 flow_ctrl, "flow_ctrl");
6782 cmdline_parse_token_string_t cmd_lfc_set_rx =
6783         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6784                                 rx, "rx");
6785 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6786         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6787                                 rx_lfc_mode, "on#off");
6788 cmdline_parse_token_string_t cmd_lfc_set_tx =
6789         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6790                                 tx, "tx");
6791 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6792         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6793                                 tx_lfc_mode, "on#off");
6794 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6795         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6796                                 hw_str, "high_water");
6797 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6798         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6799                                 high_water, UINT32);
6800 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6801         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6802                                 lw_str, "low_water");
6803 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6804         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6805                                 low_water, UINT32);
6806 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6807         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6808                                 pt_str, "pause_time");
6809 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6810         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6811                                 pause_time, UINT16);
6812 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6813         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6814                                 xon_str, "send_xon");
6815 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6816         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6817                                 send_xon, UINT16);
6818 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6819         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6820                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6821 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6822         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6823                                 mac_ctrl_frame_fwd_mode, "on#off");
6824 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6825         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6826                                 autoneg_str, "autoneg");
6827 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6828         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6829                                 autoneg, "on#off");
6830 cmdline_parse_token_num_t cmd_lfc_set_portid =
6831         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6832                                 port_id, UINT16);
6833
6834 /* forward declaration */
6835 static void
6836 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6837                               void *data);
6838
6839 cmdline_parse_inst_t cmd_link_flow_control_set = {
6840         .f = cmd_link_flow_ctrl_set_parsed,
6841         .data = NULL,
6842         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6843                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6844                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6845         .tokens = {
6846                 (void *)&cmd_lfc_set_set,
6847                 (void *)&cmd_lfc_set_flow_ctrl,
6848                 (void *)&cmd_lfc_set_rx,
6849                 (void *)&cmd_lfc_set_rx_mode,
6850                 (void *)&cmd_lfc_set_tx,
6851                 (void *)&cmd_lfc_set_tx_mode,
6852                 (void *)&cmd_lfc_set_high_water,
6853                 (void *)&cmd_lfc_set_low_water,
6854                 (void *)&cmd_lfc_set_pause_time,
6855                 (void *)&cmd_lfc_set_send_xon,
6856                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6857                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6858                 (void *)&cmd_lfc_set_autoneg_str,
6859                 (void *)&cmd_lfc_set_autoneg,
6860                 (void *)&cmd_lfc_set_portid,
6861                 NULL,
6862         },
6863 };
6864
6865 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6866         .f = cmd_link_flow_ctrl_set_parsed,
6867         .data = (void *)&cmd_link_flow_control_set_rx,
6868         .help_str = "set flow_ctrl rx on|off <port_id>: "
6869                 "Change rx flow control parameter",
6870         .tokens = {
6871                 (void *)&cmd_lfc_set_set,
6872                 (void *)&cmd_lfc_set_flow_ctrl,
6873                 (void *)&cmd_lfc_set_rx,
6874                 (void *)&cmd_lfc_set_rx_mode,
6875                 (void *)&cmd_lfc_set_portid,
6876                 NULL,
6877         },
6878 };
6879
6880 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6881         .f = cmd_link_flow_ctrl_set_parsed,
6882         .data = (void *)&cmd_link_flow_control_set_tx,
6883         .help_str = "set flow_ctrl tx on|off <port_id>: "
6884                 "Change tx flow control parameter",
6885         .tokens = {
6886                 (void *)&cmd_lfc_set_set,
6887                 (void *)&cmd_lfc_set_flow_ctrl,
6888                 (void *)&cmd_lfc_set_tx,
6889                 (void *)&cmd_lfc_set_tx_mode,
6890                 (void *)&cmd_lfc_set_portid,
6891                 NULL,
6892         },
6893 };
6894
6895 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6896         .f = cmd_link_flow_ctrl_set_parsed,
6897         .data = (void *)&cmd_link_flow_control_set_hw,
6898         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6899                 "Change high water flow control parameter",
6900         .tokens = {
6901                 (void *)&cmd_lfc_set_set,
6902                 (void *)&cmd_lfc_set_flow_ctrl,
6903                 (void *)&cmd_lfc_set_high_water_str,
6904                 (void *)&cmd_lfc_set_high_water,
6905                 (void *)&cmd_lfc_set_portid,
6906                 NULL,
6907         },
6908 };
6909
6910 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6911         .f = cmd_link_flow_ctrl_set_parsed,
6912         .data = (void *)&cmd_link_flow_control_set_lw,
6913         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6914                 "Change low water flow control parameter",
6915         .tokens = {
6916                 (void *)&cmd_lfc_set_set,
6917                 (void *)&cmd_lfc_set_flow_ctrl,
6918                 (void *)&cmd_lfc_set_low_water_str,
6919                 (void *)&cmd_lfc_set_low_water,
6920                 (void *)&cmd_lfc_set_portid,
6921                 NULL,
6922         },
6923 };
6924
6925 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6926         .f = cmd_link_flow_ctrl_set_parsed,
6927         .data = (void *)&cmd_link_flow_control_set_pt,
6928         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6929                 "Change pause time flow control parameter",
6930         .tokens = {
6931                 (void *)&cmd_lfc_set_set,
6932                 (void *)&cmd_lfc_set_flow_ctrl,
6933                 (void *)&cmd_lfc_set_pause_time_str,
6934                 (void *)&cmd_lfc_set_pause_time,
6935                 (void *)&cmd_lfc_set_portid,
6936                 NULL,
6937         },
6938 };
6939
6940 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6941         .f = cmd_link_flow_ctrl_set_parsed,
6942         .data = (void *)&cmd_link_flow_control_set_xon,
6943         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6944                 "Change send_xon flow control parameter",
6945         .tokens = {
6946                 (void *)&cmd_lfc_set_set,
6947                 (void *)&cmd_lfc_set_flow_ctrl,
6948                 (void *)&cmd_lfc_set_send_xon_str,
6949                 (void *)&cmd_lfc_set_send_xon,
6950                 (void *)&cmd_lfc_set_portid,
6951                 NULL,
6952         },
6953 };
6954
6955 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6956         .f = cmd_link_flow_ctrl_set_parsed,
6957         .data = (void *)&cmd_link_flow_control_set_macfwd,
6958         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6959                 "Change mac ctrl fwd flow control parameter",
6960         .tokens = {
6961                 (void *)&cmd_lfc_set_set,
6962                 (void *)&cmd_lfc_set_flow_ctrl,
6963                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6964                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6965                 (void *)&cmd_lfc_set_portid,
6966                 NULL,
6967         },
6968 };
6969
6970 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6971         .f = cmd_link_flow_ctrl_set_parsed,
6972         .data = (void *)&cmd_link_flow_control_set_autoneg,
6973         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6974                 "Change autoneg flow control parameter",
6975         .tokens = {
6976                 (void *)&cmd_lfc_set_set,
6977                 (void *)&cmd_lfc_set_flow_ctrl,
6978                 (void *)&cmd_lfc_set_autoneg_str,
6979                 (void *)&cmd_lfc_set_autoneg,
6980                 (void *)&cmd_lfc_set_portid,
6981                 NULL,
6982         },
6983 };
6984
6985 static void
6986 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6987                               __attribute__((unused)) struct cmdline *cl,
6988                               void *data)
6989 {
6990         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6991         cmdline_parse_inst_t *cmd = data;
6992         struct rte_eth_fc_conf fc_conf;
6993         int rx_fc_en = 0;
6994         int tx_fc_en = 0;
6995         int ret;
6996
6997         /*
6998          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6999          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7000          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7001          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7002          */
7003         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7004                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7005         };
7006
7007         /* Partial command line, retrieve current configuration */
7008         if (cmd) {
7009                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7010                 if (ret != 0) {
7011                         printf("cannot get current flow ctrl parameters, return"
7012                                "code = %d\n", ret);
7013                         return;
7014                 }
7015
7016                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7017                     (fc_conf.mode == RTE_FC_FULL))
7018                         rx_fc_en = 1;
7019                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7020                     (fc_conf.mode == RTE_FC_FULL))
7021                         tx_fc_en = 1;
7022         }
7023
7024         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7025                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7026
7027         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7028                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7029
7030         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7031
7032         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7033                 fc_conf.high_water = res->high_water;
7034
7035         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7036                 fc_conf.low_water = res->low_water;
7037
7038         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7039                 fc_conf.pause_time = res->pause_time;
7040
7041         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7042                 fc_conf.send_xon = res->send_xon;
7043
7044         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7045                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7046                         fc_conf.mac_ctrl_frame_fwd = 1;
7047                 else
7048                         fc_conf.mac_ctrl_frame_fwd = 0;
7049         }
7050
7051         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7052                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7053
7054         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7055         if (ret != 0)
7056                 printf("bad flow contrl parameter, return code = %d \n", ret);
7057 }
7058
7059 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7060 struct cmd_priority_flow_ctrl_set_result {
7061         cmdline_fixed_string_t set;
7062         cmdline_fixed_string_t pfc_ctrl;
7063         cmdline_fixed_string_t rx;
7064         cmdline_fixed_string_t rx_pfc_mode;
7065         cmdline_fixed_string_t tx;
7066         cmdline_fixed_string_t tx_pfc_mode;
7067         uint32_t high_water;
7068         uint32_t low_water;
7069         uint16_t pause_time;
7070         uint8_t  priority;
7071         portid_t port_id;
7072 };
7073
7074 static void
7075 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7076                        __attribute__((unused)) struct cmdline *cl,
7077                        __attribute__((unused)) void *data)
7078 {
7079         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7080         struct rte_eth_pfc_conf pfc_conf;
7081         int rx_fc_enable, tx_fc_enable;
7082         int ret;
7083
7084         /*
7085          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7086          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7087          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7088          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7089          */
7090         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7091                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7092         };
7093
7094         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7095         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7096         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7097         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7098         pfc_conf.fc.high_water = res->high_water;
7099         pfc_conf.fc.low_water  = res->low_water;
7100         pfc_conf.fc.pause_time = res->pause_time;
7101         pfc_conf.priority      = res->priority;
7102
7103         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7104         if (ret != 0)
7105                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7106 }
7107
7108 cmdline_parse_token_string_t cmd_pfc_set_set =
7109         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7110                                 set, "set");
7111 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7112         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7113                                 pfc_ctrl, "pfc_ctrl");
7114 cmdline_parse_token_string_t cmd_pfc_set_rx =
7115         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7116                                 rx, "rx");
7117 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7118         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7119                                 rx_pfc_mode, "on#off");
7120 cmdline_parse_token_string_t cmd_pfc_set_tx =
7121         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7122                                 tx, "tx");
7123 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7124         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7125                                 tx_pfc_mode, "on#off");
7126 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7127         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7128                                 high_water, UINT32);
7129 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7130         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7131                                 low_water, UINT32);
7132 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7133         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7134                                 pause_time, UINT16);
7135 cmdline_parse_token_num_t cmd_pfc_set_priority =
7136         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7137                                 priority, UINT8);
7138 cmdline_parse_token_num_t cmd_pfc_set_portid =
7139         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7140                                 port_id, UINT16);
7141
7142 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7143         .f = cmd_priority_flow_ctrl_set_parsed,
7144         .data = NULL,
7145         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7146                 "<pause_time> <priority> <port_id>: "
7147                 "Configure the Ethernet priority flow control",
7148         .tokens = {
7149                 (void *)&cmd_pfc_set_set,
7150                 (void *)&cmd_pfc_set_flow_ctrl,
7151                 (void *)&cmd_pfc_set_rx,
7152                 (void *)&cmd_pfc_set_rx_mode,
7153                 (void *)&cmd_pfc_set_tx,
7154                 (void *)&cmd_pfc_set_tx_mode,
7155                 (void *)&cmd_pfc_set_high_water,
7156                 (void *)&cmd_pfc_set_low_water,
7157                 (void *)&cmd_pfc_set_pause_time,
7158                 (void *)&cmd_pfc_set_priority,
7159                 (void *)&cmd_pfc_set_portid,
7160                 NULL,
7161         },
7162 };
7163
7164 /* *** RESET CONFIGURATION *** */
7165 struct cmd_reset_result {
7166         cmdline_fixed_string_t reset;
7167         cmdline_fixed_string_t def;
7168 };
7169
7170 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
7171                              struct cmdline *cl,
7172                              __attribute__((unused)) void *data)
7173 {
7174         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7175         set_def_fwd_config();
7176 }
7177
7178 cmdline_parse_token_string_t cmd_reset_set =
7179         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7180 cmdline_parse_token_string_t cmd_reset_def =
7181         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7182                                  "default");
7183
7184 cmdline_parse_inst_t cmd_reset = {
7185         .f = cmd_reset_parsed,
7186         .data = NULL,
7187         .help_str = "set default: Reset default forwarding configuration",
7188         .tokens = {
7189                 (void *)&cmd_reset_set,
7190                 (void *)&cmd_reset_def,
7191                 NULL,
7192         },
7193 };
7194
7195 /* *** START FORWARDING *** */
7196 struct cmd_start_result {
7197         cmdline_fixed_string_t start;
7198 };
7199
7200 cmdline_parse_token_string_t cmd_start_start =
7201         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7202
7203 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
7204                              __attribute__((unused)) struct cmdline *cl,
7205                              __attribute__((unused)) void *data)
7206 {
7207         start_packet_forwarding(0);
7208 }
7209
7210 cmdline_parse_inst_t cmd_start = {
7211         .f = cmd_start_parsed,
7212         .data = NULL,
7213         .help_str = "start: Start packet forwarding",
7214         .tokens = {
7215                 (void *)&cmd_start_start,
7216                 NULL,
7217         },
7218 };
7219
7220 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7221 struct cmd_start_tx_first_result {
7222         cmdline_fixed_string_t start;
7223         cmdline_fixed_string_t tx_first;
7224 };
7225
7226 static void
7227 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
7228                           __attribute__((unused)) struct cmdline *cl,
7229                           __attribute__((unused)) void *data)
7230 {
7231         start_packet_forwarding(1);
7232 }
7233
7234 cmdline_parse_token_string_t cmd_start_tx_first_start =
7235         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7236                                  "start");
7237 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7238         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7239                                  tx_first, "tx_first");
7240
7241 cmdline_parse_inst_t cmd_start_tx_first = {
7242         .f = cmd_start_tx_first_parsed,
7243         .data = NULL,
7244         .help_str = "start tx_first: Start packet forwarding, "
7245                 "after sending 1 burst of packets",
7246         .tokens = {
7247                 (void *)&cmd_start_tx_first_start,
7248                 (void *)&cmd_start_tx_first_tx_first,
7249                 NULL,
7250         },
7251 };
7252
7253 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7254 struct cmd_start_tx_first_n_result {
7255         cmdline_fixed_string_t start;
7256         cmdline_fixed_string_t tx_first;
7257         uint32_t tx_num;
7258 };
7259
7260 static void
7261 cmd_start_tx_first_n_parsed(void *parsed_result,
7262                           __attribute__((unused)) struct cmdline *cl,
7263                           __attribute__((unused)) void *data)
7264 {
7265         struct cmd_start_tx_first_n_result *res = parsed_result;
7266
7267         start_packet_forwarding(res->tx_num);
7268 }
7269
7270 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7271         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7272                         start, "start");
7273 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7274         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7275                         tx_first, "tx_first");
7276 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7277         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7278                         tx_num, UINT32);
7279
7280 cmdline_parse_inst_t cmd_start_tx_first_n = {
7281         .f = cmd_start_tx_first_n_parsed,
7282         .data = NULL,
7283         .help_str = "start tx_first <num>: "
7284                 "packet forwarding, after sending <num> bursts of packets",
7285         .tokens = {
7286                 (void *)&cmd_start_tx_first_n_start,
7287                 (void *)&cmd_start_tx_first_n_tx_first,
7288                 (void *)&cmd_start_tx_first_n_tx_num,
7289                 NULL,
7290         },
7291 };
7292
7293 /* *** SET LINK UP *** */
7294 struct cmd_set_link_up_result {
7295         cmdline_fixed_string_t set;
7296         cmdline_fixed_string_t link_up;
7297         cmdline_fixed_string_t port;
7298         portid_t port_id;
7299 };
7300
7301 cmdline_parse_token_string_t cmd_set_link_up_set =
7302         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7303 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7304         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7305                                 "link-up");
7306 cmdline_parse_token_string_t cmd_set_link_up_port =
7307         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7308 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7309         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7310
7311 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
7312                              __attribute__((unused)) struct cmdline *cl,
7313                              __attribute__((unused)) void *data)
7314 {
7315         struct cmd_set_link_up_result *res = parsed_result;
7316         dev_set_link_up(res->port_id);
7317 }
7318
7319 cmdline_parse_inst_t cmd_set_link_up = {
7320         .f = cmd_set_link_up_parsed,
7321         .data = NULL,
7322         .help_str = "set link-up port <port id>",
7323         .tokens = {
7324                 (void *)&cmd_set_link_up_set,
7325                 (void *)&cmd_set_link_up_link_up,
7326                 (void *)&cmd_set_link_up_port,
7327                 (void *)&cmd_set_link_up_port_id,
7328                 NULL,
7329         },
7330 };
7331
7332 /* *** SET LINK DOWN *** */
7333 struct cmd_set_link_down_result {
7334         cmdline_fixed_string_t set;
7335         cmdline_fixed_string_t link_down;
7336         cmdline_fixed_string_t port;
7337         portid_t port_id;
7338 };
7339
7340 cmdline_parse_token_string_t cmd_set_link_down_set =
7341         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7342 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7343         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7344                                 "link-down");
7345 cmdline_parse_token_string_t cmd_set_link_down_port =
7346         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7347 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7348         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7349
7350 static void cmd_set_link_down_parsed(
7351                                 __attribute__((unused)) void *parsed_result,
7352                                 __attribute__((unused)) struct cmdline *cl,
7353                                 __attribute__((unused)) void *data)
7354 {
7355         struct cmd_set_link_down_result *res = parsed_result;
7356         dev_set_link_down(res->port_id);
7357 }
7358
7359 cmdline_parse_inst_t cmd_set_link_down = {
7360         .f = cmd_set_link_down_parsed,
7361         .data = NULL,
7362         .help_str = "set link-down port <port id>",
7363         .tokens = {
7364                 (void *)&cmd_set_link_down_set,
7365                 (void *)&cmd_set_link_down_link_down,
7366                 (void *)&cmd_set_link_down_port,
7367                 (void *)&cmd_set_link_down_port_id,
7368                 NULL,
7369         },
7370 };
7371
7372 /* *** SHOW CFG *** */
7373 struct cmd_showcfg_result {
7374         cmdline_fixed_string_t show;
7375         cmdline_fixed_string_t cfg;
7376         cmdline_fixed_string_t what;
7377 };
7378
7379 static void cmd_showcfg_parsed(void *parsed_result,
7380                                __attribute__((unused)) struct cmdline *cl,
7381                                __attribute__((unused)) void *data)
7382 {
7383         struct cmd_showcfg_result *res = parsed_result;
7384         if (!strcmp(res->what, "rxtx"))
7385                 rxtx_config_display();
7386         else if (!strcmp(res->what, "cores"))
7387                 fwd_lcores_config_display();
7388         else if (!strcmp(res->what, "fwd"))
7389                 pkt_fwd_config_display(&cur_fwd_config);
7390         else if (!strcmp(res->what, "txpkts"))
7391                 show_tx_pkt_segments();
7392 }
7393
7394 cmdline_parse_token_string_t cmd_showcfg_show =
7395         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7396 cmdline_parse_token_string_t cmd_showcfg_port =
7397         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7398 cmdline_parse_token_string_t cmd_showcfg_what =
7399         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7400                                  "rxtx#cores#fwd#txpkts");
7401
7402 cmdline_parse_inst_t cmd_showcfg = {
7403         .f = cmd_showcfg_parsed,
7404         .data = NULL,
7405         .help_str = "show config rxtx|cores|fwd|txpkts",
7406         .tokens = {
7407                 (void *)&cmd_showcfg_show,
7408                 (void *)&cmd_showcfg_port,
7409                 (void *)&cmd_showcfg_what,
7410                 NULL,
7411         },
7412 };
7413
7414 /* *** SHOW ALL PORT INFO *** */
7415 struct cmd_showportall_result {
7416         cmdline_fixed_string_t show;
7417         cmdline_fixed_string_t port;
7418         cmdline_fixed_string_t what;
7419         cmdline_fixed_string_t all;
7420 };
7421
7422 static void cmd_showportall_parsed(void *parsed_result,
7423                                 __attribute__((unused)) struct cmdline *cl,
7424                                 __attribute__((unused)) void *data)
7425 {
7426         portid_t i;
7427
7428         struct cmd_showportall_result *res = parsed_result;
7429         if (!strcmp(res->show, "clear")) {
7430                 if (!strcmp(res->what, "stats"))
7431                         RTE_ETH_FOREACH_DEV(i)
7432                                 nic_stats_clear(i);
7433                 else if (!strcmp(res->what, "xstats"))
7434                         RTE_ETH_FOREACH_DEV(i)
7435                                 nic_xstats_clear(i);
7436         } else if (!strcmp(res->what, "info"))
7437                 RTE_ETH_FOREACH_DEV(i)
7438                         port_infos_display(i);
7439         else if (!strcmp(res->what, "summary")) {
7440                 port_summary_header_display();
7441                 RTE_ETH_FOREACH_DEV(i)
7442                         port_summary_display(i);
7443         }
7444         else if (!strcmp(res->what, "stats"))
7445                 RTE_ETH_FOREACH_DEV(i)
7446                         nic_stats_display(i);
7447         else if (!strcmp(res->what, "xstats"))
7448                 RTE_ETH_FOREACH_DEV(i)
7449                         nic_xstats_display(i);
7450         else if (!strcmp(res->what, "fdir"))
7451                 RTE_ETH_FOREACH_DEV(i)
7452                         fdir_get_infos(i);
7453         else if (!strcmp(res->what, "stat_qmap"))
7454                 RTE_ETH_FOREACH_DEV(i)
7455                         nic_stats_mapping_display(i);
7456         else if (!strcmp(res->what, "dcb_tc"))
7457                 RTE_ETH_FOREACH_DEV(i)
7458                         port_dcb_info_display(i);
7459         else if (!strcmp(res->what, "cap"))
7460                 RTE_ETH_FOREACH_DEV(i)
7461                         port_offload_cap_display(i);
7462 }
7463
7464 cmdline_parse_token_string_t cmd_showportall_show =
7465         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7466                                  "show#clear");
7467 cmdline_parse_token_string_t cmd_showportall_port =
7468         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7469 cmdline_parse_token_string_t cmd_showportall_what =
7470         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7471                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7472 cmdline_parse_token_string_t cmd_showportall_all =
7473         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7474 cmdline_parse_inst_t cmd_showportall = {
7475         .f = cmd_showportall_parsed,
7476         .data = NULL,
7477         .help_str = "show|clear port "
7478                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7479         .tokens = {
7480                 (void *)&cmd_showportall_show,
7481                 (void *)&cmd_showportall_port,
7482                 (void *)&cmd_showportall_what,
7483                 (void *)&cmd_showportall_all,
7484                 NULL,
7485         },
7486 };
7487
7488 /* *** SHOW PORT INFO *** */
7489 struct cmd_showport_result {
7490         cmdline_fixed_string_t show;
7491         cmdline_fixed_string_t port;
7492         cmdline_fixed_string_t what;
7493         uint16_t portnum;
7494 };
7495
7496 static void cmd_showport_parsed(void *parsed_result,
7497                                 __attribute__((unused)) struct cmdline *cl,
7498                                 __attribute__((unused)) void *data)
7499 {
7500         struct cmd_showport_result *res = parsed_result;
7501         if (!strcmp(res->show, "clear")) {
7502                 if (!strcmp(res->what, "stats"))
7503                         nic_stats_clear(res->portnum);
7504                 else if (!strcmp(res->what, "xstats"))
7505                         nic_xstats_clear(res->portnum);
7506         } else if (!strcmp(res->what, "info"))
7507                 port_infos_display(res->portnum);
7508         else if (!strcmp(res->what, "summary")) {
7509                 port_summary_header_display();
7510                 port_summary_display(res->portnum);
7511         }
7512         else if (!strcmp(res->what, "stats"))
7513                 nic_stats_display(res->portnum);
7514         else if (!strcmp(res->what, "xstats"))
7515                 nic_xstats_display(res->portnum);
7516         else if (!strcmp(res->what, "fdir"))
7517                  fdir_get_infos(res->portnum);
7518         else if (!strcmp(res->what, "stat_qmap"))
7519                 nic_stats_mapping_display(res->portnum);
7520         else if (!strcmp(res->what, "dcb_tc"))
7521                 port_dcb_info_display(res->portnum);
7522         else if (!strcmp(res->what, "cap"))
7523                 port_offload_cap_display(res->portnum);
7524 }
7525
7526 cmdline_parse_token_string_t cmd_showport_show =
7527         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7528                                  "show#clear");
7529 cmdline_parse_token_string_t cmd_showport_port =
7530         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7531 cmdline_parse_token_string_t cmd_showport_what =
7532         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7533                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7534 cmdline_parse_token_num_t cmd_showport_portnum =
7535         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7536
7537 cmdline_parse_inst_t cmd_showport = {
7538         .f = cmd_showport_parsed,
7539         .data = NULL,
7540         .help_str = "show|clear port "
7541                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7542                 "<port_id>",
7543         .tokens = {
7544                 (void *)&cmd_showport_show,
7545                 (void *)&cmd_showport_port,
7546                 (void *)&cmd_showport_what,
7547                 (void *)&cmd_showport_portnum,
7548                 NULL,
7549         },
7550 };
7551
7552 /* *** SHOW DEVICE INFO *** */
7553 struct cmd_showdevice_result {
7554         cmdline_fixed_string_t show;
7555         cmdline_fixed_string_t device;
7556         cmdline_fixed_string_t what;
7557         cmdline_fixed_string_t identifier;
7558 };
7559
7560 static void cmd_showdevice_parsed(void *parsed_result,
7561                                 __attribute__((unused)) struct cmdline *cl,
7562                                 __attribute__((unused)) void *data)
7563 {
7564         struct cmd_showdevice_result *res = parsed_result;
7565         if (!strcmp(res->what, "info")) {
7566                 if (!strcmp(res->identifier, "all"))
7567                         device_infos_display(NULL);
7568                 else
7569                         device_infos_display(res->identifier);
7570         }
7571 }
7572
7573 cmdline_parse_token_string_t cmd_showdevice_show =
7574         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7575                                  "show");
7576 cmdline_parse_token_string_t cmd_showdevice_device =
7577         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7578 cmdline_parse_token_string_t cmd_showdevice_what =
7579         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7580                                  "info");
7581 cmdline_parse_token_string_t cmd_showdevice_identifier =
7582         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7583                         identifier, NULL);
7584
7585 cmdline_parse_inst_t cmd_showdevice = {
7586         .f = cmd_showdevice_parsed,
7587         .data = NULL,
7588         .help_str = "show device info <identifier>|all",
7589         .tokens = {
7590                 (void *)&cmd_showdevice_show,
7591                 (void *)&cmd_showdevice_device,
7592                 (void *)&cmd_showdevice_what,
7593                 (void *)&cmd_showdevice_identifier,
7594                 NULL,
7595         },
7596 };
7597 /* *** SHOW QUEUE INFO *** */
7598 struct cmd_showqueue_result {
7599         cmdline_fixed_string_t show;
7600         cmdline_fixed_string_t type;
7601         cmdline_fixed_string_t what;
7602         uint16_t portnum;
7603         uint16_t queuenum;
7604 };
7605
7606 static void
7607 cmd_showqueue_parsed(void *parsed_result,
7608         __attribute__((unused)) struct cmdline *cl,
7609         __attribute__((unused)) void *data)
7610 {
7611         struct cmd_showqueue_result *res = parsed_result;
7612
7613         if (!strcmp(res->type, "rxq"))
7614                 rx_queue_infos_display(res->portnum, res->queuenum);
7615         else if (!strcmp(res->type, "txq"))
7616                 tx_queue_infos_display(res->portnum, res->queuenum);
7617 }
7618
7619 cmdline_parse_token_string_t cmd_showqueue_show =
7620         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7621 cmdline_parse_token_string_t cmd_showqueue_type =
7622         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7623 cmdline_parse_token_string_t cmd_showqueue_what =
7624         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7625 cmdline_parse_token_num_t cmd_showqueue_portnum =
7626         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7627 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7628         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7629
7630 cmdline_parse_inst_t cmd_showqueue = {
7631         .f = cmd_showqueue_parsed,
7632         .data = NULL,
7633         .help_str = "show rxq|txq info <port_id> <queue_id>",
7634         .tokens = {
7635                 (void *)&cmd_showqueue_show,
7636                 (void *)&cmd_showqueue_type,
7637                 (void *)&cmd_showqueue_what,
7638                 (void *)&cmd_showqueue_portnum,
7639                 (void *)&cmd_showqueue_queuenum,
7640                 NULL,
7641         },
7642 };
7643
7644 /* show/clear fwd engine statistics */
7645 struct fwd_result {
7646         cmdline_fixed_string_t action;
7647         cmdline_fixed_string_t fwd;
7648         cmdline_fixed_string_t stats;
7649         cmdline_fixed_string_t all;
7650 };
7651
7652 cmdline_parse_token_string_t cmd_fwd_action =
7653         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7654 cmdline_parse_token_string_t cmd_fwd_fwd =
7655         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7656 cmdline_parse_token_string_t cmd_fwd_stats =
7657         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7658 cmdline_parse_token_string_t cmd_fwd_all =
7659         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7660
7661 static void
7662 cmd_showfwdall_parsed(void *parsed_result,
7663                       __rte_unused struct cmdline *cl,
7664                       __rte_unused void *data)
7665 {
7666         struct fwd_result *res = parsed_result;
7667
7668         if (!strcmp(res->action, "show"))
7669                 fwd_stats_display();
7670         else
7671                 fwd_stats_reset();
7672 }
7673
7674 static cmdline_parse_inst_t cmd_showfwdall = {
7675         .f = cmd_showfwdall_parsed,
7676         .data = NULL,
7677         .help_str = "show|clear fwd stats all",
7678         .tokens = {
7679                 (void *)&cmd_fwd_action,
7680                 (void *)&cmd_fwd_fwd,
7681                 (void *)&cmd_fwd_stats,
7682                 (void *)&cmd_fwd_all,
7683                 NULL,
7684         },
7685 };
7686
7687 /* *** READ PORT REGISTER *** */
7688 struct cmd_read_reg_result {
7689         cmdline_fixed_string_t read;
7690         cmdline_fixed_string_t reg;
7691         portid_t port_id;
7692         uint32_t reg_off;
7693 };
7694
7695 static void
7696 cmd_read_reg_parsed(void *parsed_result,
7697                     __attribute__((unused)) struct cmdline *cl,
7698                     __attribute__((unused)) void *data)
7699 {
7700         struct cmd_read_reg_result *res = parsed_result;
7701         port_reg_display(res->port_id, res->reg_off);
7702 }
7703
7704 cmdline_parse_token_string_t cmd_read_reg_read =
7705         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7706 cmdline_parse_token_string_t cmd_read_reg_reg =
7707         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7708 cmdline_parse_token_num_t cmd_read_reg_port_id =
7709         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7710 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7711         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7712
7713 cmdline_parse_inst_t cmd_read_reg = {
7714         .f = cmd_read_reg_parsed,
7715         .data = NULL,
7716         .help_str = "read reg <port_id> <reg_off>",
7717         .tokens = {
7718                 (void *)&cmd_read_reg_read,
7719                 (void *)&cmd_read_reg_reg,
7720                 (void *)&cmd_read_reg_port_id,
7721                 (void *)&cmd_read_reg_reg_off,
7722                 NULL,
7723         },
7724 };
7725
7726 /* *** READ PORT REGISTER BIT FIELD *** */
7727 struct cmd_read_reg_bit_field_result {
7728         cmdline_fixed_string_t read;
7729         cmdline_fixed_string_t regfield;
7730         portid_t port_id;
7731         uint32_t reg_off;
7732         uint8_t bit1_pos;
7733         uint8_t bit2_pos;
7734 };
7735
7736 static void
7737 cmd_read_reg_bit_field_parsed(void *parsed_result,
7738                               __attribute__((unused)) struct cmdline *cl,
7739                               __attribute__((unused)) void *data)
7740 {
7741         struct cmd_read_reg_bit_field_result *res = parsed_result;
7742         port_reg_bit_field_display(res->port_id, res->reg_off,
7743                                    res->bit1_pos, res->bit2_pos);
7744 }
7745
7746 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7747         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7748                                  "read");
7749 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7750         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7751                                  regfield, "regfield");
7752 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7753         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7754                               UINT16);
7755 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7756         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7757                               UINT32);
7758 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7759         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7760                               UINT8);
7761 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7762         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7763                               UINT8);
7764
7765 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7766         .f = cmd_read_reg_bit_field_parsed,
7767         .data = NULL,
7768         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7769         "Read register bit field between bit_x and bit_y included",
7770         .tokens = {
7771                 (void *)&cmd_read_reg_bit_field_read,
7772                 (void *)&cmd_read_reg_bit_field_regfield,
7773                 (void *)&cmd_read_reg_bit_field_port_id,
7774                 (void *)&cmd_read_reg_bit_field_reg_off,
7775                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7776                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7777                 NULL,
7778         },
7779 };
7780
7781 /* *** READ PORT REGISTER BIT *** */
7782 struct cmd_read_reg_bit_result {
7783         cmdline_fixed_string_t read;
7784         cmdline_fixed_string_t regbit;
7785         portid_t port_id;
7786         uint32_t reg_off;
7787         uint8_t bit_pos;
7788 };
7789
7790 static void
7791 cmd_read_reg_bit_parsed(void *parsed_result,
7792                         __attribute__((unused)) struct cmdline *cl,
7793                         __attribute__((unused)) void *data)
7794 {
7795         struct cmd_read_reg_bit_result *res = parsed_result;
7796         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7797 }
7798
7799 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7800         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7801 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7802         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7803                                  regbit, "regbit");
7804 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7805         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7806 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7807         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7808 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7809         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7810
7811 cmdline_parse_inst_t cmd_read_reg_bit = {
7812         .f = cmd_read_reg_bit_parsed,
7813         .data = NULL,
7814         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7815         .tokens = {
7816                 (void *)&cmd_read_reg_bit_read,
7817                 (void *)&cmd_read_reg_bit_regbit,
7818                 (void *)&cmd_read_reg_bit_port_id,
7819                 (void *)&cmd_read_reg_bit_reg_off,
7820                 (void *)&cmd_read_reg_bit_bit_pos,
7821                 NULL,
7822         },
7823 };
7824
7825 /* *** WRITE PORT REGISTER *** */
7826 struct cmd_write_reg_result {
7827         cmdline_fixed_string_t write;
7828         cmdline_fixed_string_t reg;
7829         portid_t port_id;
7830         uint32_t reg_off;
7831         uint32_t value;
7832 };
7833
7834 static void
7835 cmd_write_reg_parsed(void *parsed_result,
7836                      __attribute__((unused)) struct cmdline *cl,
7837                      __attribute__((unused)) void *data)
7838 {
7839         struct cmd_write_reg_result *res = parsed_result;
7840         port_reg_set(res->port_id, res->reg_off, res->value);
7841 }
7842
7843 cmdline_parse_token_string_t cmd_write_reg_write =
7844         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7845 cmdline_parse_token_string_t cmd_write_reg_reg =
7846         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7847 cmdline_parse_token_num_t cmd_write_reg_port_id =
7848         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7849 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7850         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7851 cmdline_parse_token_num_t cmd_write_reg_value =
7852         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7853
7854 cmdline_parse_inst_t cmd_write_reg = {
7855         .f = cmd_write_reg_parsed,
7856         .data = NULL,
7857         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7858         .tokens = {
7859                 (void *)&cmd_write_reg_write,
7860                 (void *)&cmd_write_reg_reg,
7861                 (void *)&cmd_write_reg_port_id,
7862                 (void *)&cmd_write_reg_reg_off,
7863                 (void *)&cmd_write_reg_value,
7864                 NULL,
7865         },
7866 };
7867
7868 /* *** WRITE PORT REGISTER BIT FIELD *** */
7869 struct cmd_write_reg_bit_field_result {
7870         cmdline_fixed_string_t write;
7871         cmdline_fixed_string_t regfield;
7872         portid_t port_id;
7873         uint32_t reg_off;
7874         uint8_t bit1_pos;
7875         uint8_t bit2_pos;
7876         uint32_t value;
7877 };
7878
7879 static void
7880 cmd_write_reg_bit_field_parsed(void *parsed_result,
7881                                __attribute__((unused)) struct cmdline *cl,
7882                                __attribute__((unused)) void *data)
7883 {
7884         struct cmd_write_reg_bit_field_result *res = parsed_result;
7885         port_reg_bit_field_set(res->port_id, res->reg_off,
7886                           res->bit1_pos, res->bit2_pos, res->value);
7887 }
7888
7889 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7890         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7891                                  "write");
7892 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7893         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7894                                  regfield, "regfield");
7895 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7896         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7897                               UINT16);
7898 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7899         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7900                               UINT32);
7901 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7902         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7903                               UINT8);
7904 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7905         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7906                               UINT8);
7907 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7908         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7909                               UINT32);
7910
7911 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7912         .f = cmd_write_reg_bit_field_parsed,
7913         .data = NULL,
7914         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7915                 "<reg_value>: "
7916                 "Set register bit field between bit_x and bit_y included",
7917         .tokens = {
7918                 (void *)&cmd_write_reg_bit_field_write,
7919                 (void *)&cmd_write_reg_bit_field_regfield,
7920                 (void *)&cmd_write_reg_bit_field_port_id,
7921                 (void *)&cmd_write_reg_bit_field_reg_off,
7922                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7923                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7924                 (void *)&cmd_write_reg_bit_field_value,
7925                 NULL,
7926         },
7927 };
7928
7929 /* *** WRITE PORT REGISTER BIT *** */
7930 struct cmd_write_reg_bit_result {
7931         cmdline_fixed_string_t write;
7932         cmdline_fixed_string_t regbit;
7933         portid_t port_id;
7934         uint32_t reg_off;
7935         uint8_t bit_pos;
7936         uint8_t value;
7937 };
7938
7939 static void
7940 cmd_write_reg_bit_parsed(void *parsed_result,
7941                          __attribute__((unused)) struct cmdline *cl,
7942                          __attribute__((unused)) void *data)
7943 {
7944         struct cmd_write_reg_bit_result *res = parsed_result;
7945         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7946 }
7947
7948 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7949         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7950                                  "write");
7951 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7952         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7953                                  regbit, "regbit");
7954 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7955         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7956 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7957         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7958 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7959         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7960 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7961         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7962
7963 cmdline_parse_inst_t cmd_write_reg_bit = {
7964         .f = cmd_write_reg_bit_parsed,
7965         .data = NULL,
7966         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7967                 "0 <= bit_x <= 31",
7968         .tokens = {
7969                 (void *)&cmd_write_reg_bit_write,
7970                 (void *)&cmd_write_reg_bit_regbit,
7971                 (void *)&cmd_write_reg_bit_port_id,
7972                 (void *)&cmd_write_reg_bit_reg_off,
7973                 (void *)&cmd_write_reg_bit_bit_pos,
7974                 (void *)&cmd_write_reg_bit_value,
7975                 NULL,
7976         },
7977 };
7978
7979 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7980 struct cmd_read_rxd_txd_result {
7981         cmdline_fixed_string_t read;
7982         cmdline_fixed_string_t rxd_txd;
7983         portid_t port_id;
7984         uint16_t queue_id;
7985         uint16_t desc_id;
7986 };
7987
7988 static void
7989 cmd_read_rxd_txd_parsed(void *parsed_result,
7990                         __attribute__((unused)) struct cmdline *cl,
7991                         __attribute__((unused)) void *data)
7992 {
7993         struct cmd_read_rxd_txd_result *res = parsed_result;
7994
7995         if (!strcmp(res->rxd_txd, "rxd"))
7996                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7997         else if (!strcmp(res->rxd_txd, "txd"))
7998                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7999 }
8000
8001 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8002         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8003 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8004         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8005                                  "rxd#txd");
8006 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8007         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8008 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8009         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8010 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8011         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8012
8013 cmdline_parse_inst_t cmd_read_rxd_txd = {
8014         .f = cmd_read_rxd_txd_parsed,
8015         .data = NULL,
8016         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8017         .tokens = {
8018                 (void *)&cmd_read_rxd_txd_read,
8019                 (void *)&cmd_read_rxd_txd_rxd_txd,
8020                 (void *)&cmd_read_rxd_txd_port_id,
8021                 (void *)&cmd_read_rxd_txd_queue_id,
8022                 (void *)&cmd_read_rxd_txd_desc_id,
8023                 NULL,
8024         },
8025 };
8026
8027 /* *** QUIT *** */
8028 struct cmd_quit_result {
8029         cmdline_fixed_string_t quit;
8030 };
8031
8032 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
8033                             struct cmdline *cl,
8034                             __attribute__((unused)) void *data)
8035 {
8036         cmdline_quit(cl);
8037 }
8038
8039 cmdline_parse_token_string_t cmd_quit_quit =
8040         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8041
8042 cmdline_parse_inst_t cmd_quit = {
8043         .f = cmd_quit_parsed,
8044         .data = NULL,
8045         .help_str = "quit: Exit application",
8046         .tokens = {
8047                 (void *)&cmd_quit_quit,
8048                 NULL,
8049         },
8050 };
8051
8052 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8053 struct cmd_mac_addr_result {
8054         cmdline_fixed_string_t mac_addr_cmd;
8055         cmdline_fixed_string_t what;
8056         uint16_t port_num;
8057         struct rte_ether_addr address;
8058 };
8059
8060 static void cmd_mac_addr_parsed(void *parsed_result,
8061                 __attribute__((unused)) struct cmdline *cl,
8062                 __attribute__((unused)) void *data)
8063 {
8064         struct cmd_mac_addr_result *res = parsed_result;
8065         int ret;
8066
8067         if (strcmp(res->what, "add") == 0)
8068                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8069         else if (strcmp(res->what, "set") == 0)
8070                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8071                                                        &res->address);
8072         else
8073                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8074
8075         /* check the return value and print it if is < 0 */
8076         if(ret < 0)
8077                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8078
8079 }
8080
8081 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8082         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8083                                 "mac_addr");
8084 cmdline_parse_token_string_t cmd_mac_addr_what =
8085         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8086                                 "add#remove#set");
8087 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8088                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8089                                         UINT16);
8090 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8091                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8092
8093 cmdline_parse_inst_t cmd_mac_addr = {
8094         .f = cmd_mac_addr_parsed,
8095         .data = (void *)0,
8096         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8097                         "Add/Remove/Set MAC address on port_id",
8098         .tokens = {
8099                 (void *)&cmd_mac_addr_cmd,
8100                 (void *)&cmd_mac_addr_what,
8101                 (void *)&cmd_mac_addr_portnum,
8102                 (void *)&cmd_mac_addr_addr,
8103                 NULL,
8104         },
8105 };
8106
8107 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8108 struct cmd_eth_peer_result {
8109         cmdline_fixed_string_t set;
8110         cmdline_fixed_string_t eth_peer;
8111         portid_t port_id;
8112         cmdline_fixed_string_t peer_addr;
8113 };
8114
8115 static void cmd_set_eth_peer_parsed(void *parsed_result,
8116                         __attribute__((unused)) struct cmdline *cl,
8117                         __attribute__((unused)) void *data)
8118 {
8119                 struct cmd_eth_peer_result *res = parsed_result;
8120
8121                 if (test_done == 0) {
8122                         printf("Please stop forwarding first\n");
8123                         return;
8124                 }
8125                 if (!strcmp(res->eth_peer, "eth-peer")) {
8126                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8127                         fwd_config_setup();
8128                 }
8129 }
8130 cmdline_parse_token_string_t cmd_eth_peer_set =
8131         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8132 cmdline_parse_token_string_t cmd_eth_peer =
8133         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8134 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8135         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8136 cmdline_parse_token_string_t cmd_eth_peer_addr =
8137         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8138
8139 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8140         .f = cmd_set_eth_peer_parsed,
8141         .data = NULL,
8142         .help_str = "set eth-peer <port_id> <peer_mac>",
8143         .tokens = {
8144                 (void *)&cmd_eth_peer_set,
8145                 (void *)&cmd_eth_peer,
8146                 (void *)&cmd_eth_peer_port_id,
8147                 (void *)&cmd_eth_peer_addr,
8148                 NULL,
8149         },
8150 };
8151
8152 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8153 struct cmd_set_qmap_result {
8154         cmdline_fixed_string_t set;
8155         cmdline_fixed_string_t qmap;
8156         cmdline_fixed_string_t what;
8157         portid_t port_id;
8158         uint16_t queue_id;
8159         uint8_t map_value;
8160 };
8161
8162 static void
8163 cmd_set_qmap_parsed(void *parsed_result,
8164                        __attribute__((unused)) struct cmdline *cl,
8165                        __attribute__((unused)) void *data)
8166 {
8167         struct cmd_set_qmap_result *res = parsed_result;
8168         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8169
8170         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8171 }
8172
8173 cmdline_parse_token_string_t cmd_setqmap_set =
8174         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8175                                  set, "set");
8176 cmdline_parse_token_string_t cmd_setqmap_qmap =
8177         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8178                                  qmap, "stat_qmap");
8179 cmdline_parse_token_string_t cmd_setqmap_what =
8180         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8181                                  what, "tx#rx");
8182 cmdline_parse_token_num_t cmd_setqmap_portid =
8183         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8184                               port_id, UINT16);
8185 cmdline_parse_token_num_t cmd_setqmap_queueid =
8186         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8187                               queue_id, UINT16);
8188 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8189         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8190                               map_value, UINT8);
8191
8192 cmdline_parse_inst_t cmd_set_qmap = {
8193         .f = cmd_set_qmap_parsed,
8194         .data = NULL,
8195         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8196                 "Set statistics mapping value on tx|rx queue_id of port_id",
8197         .tokens = {
8198                 (void *)&cmd_setqmap_set,
8199                 (void *)&cmd_setqmap_qmap,
8200                 (void *)&cmd_setqmap_what,
8201                 (void *)&cmd_setqmap_portid,
8202                 (void *)&cmd_setqmap_queueid,
8203                 (void *)&cmd_setqmap_mapvalue,
8204                 NULL,
8205         },
8206 };
8207
8208 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8209 struct cmd_set_xstats_hide_zero_result {
8210         cmdline_fixed_string_t keyword;
8211         cmdline_fixed_string_t name;
8212         cmdline_fixed_string_t on_off;
8213 };
8214
8215 static void
8216 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8217                         __attribute__((unused)) struct cmdline *cl,
8218                         __attribute__((unused)) void *data)
8219 {
8220         struct cmd_set_xstats_hide_zero_result *res;
8221         uint16_t on_off = 0;
8222
8223         res = parsed_result;
8224         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8225         set_xstats_hide_zero(on_off);
8226 }
8227
8228 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8229         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8230                                  keyword, "set");
8231 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8232         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8233                                  name, "xstats-hide-zero");
8234 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8235         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8236                                  on_off, "on#off");
8237
8238 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8239         .f = cmd_set_xstats_hide_zero_parsed,
8240         .data = NULL,
8241         .help_str = "set xstats-hide-zero on|off",
8242         .tokens = {
8243                 (void *)&cmd_set_xstats_hide_zero_keyword,
8244                 (void *)&cmd_set_xstats_hide_zero_name,
8245                 (void *)&cmd_set_xstats_hide_zero_on_off,
8246                 NULL,
8247         },
8248 };
8249
8250 /* *** CONFIGURE UNICAST HASH TABLE *** */
8251 struct cmd_set_uc_hash_table {
8252         cmdline_fixed_string_t set;
8253         cmdline_fixed_string_t port;
8254         portid_t port_id;
8255         cmdline_fixed_string_t what;
8256         struct rte_ether_addr address;
8257         cmdline_fixed_string_t mode;
8258 };
8259
8260 static void
8261 cmd_set_uc_hash_parsed(void *parsed_result,
8262                        __attribute__((unused)) struct cmdline *cl,
8263                        __attribute__((unused)) void *data)
8264 {
8265         int ret=0;
8266         struct cmd_set_uc_hash_table *res = parsed_result;
8267
8268         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8269
8270         if (strcmp(res->what, "uta") == 0)
8271                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8272                                                 &res->address,(uint8_t)is_on);
8273         if (ret < 0)
8274                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8275
8276 }
8277
8278 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8279         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8280                                  set, "set");
8281 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8282         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8283                                  port, "port");
8284 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8285         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8286                               port_id, UINT16);
8287 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8288         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8289                                  what, "uta");
8290 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8291         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8292                                 address);
8293 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8294         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8295                                  mode, "on#off");
8296
8297 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8298         .f = cmd_set_uc_hash_parsed,
8299         .data = NULL,
8300         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8301         .tokens = {
8302                 (void *)&cmd_set_uc_hash_set,
8303                 (void *)&cmd_set_uc_hash_port,
8304                 (void *)&cmd_set_uc_hash_portid,
8305                 (void *)&cmd_set_uc_hash_what,
8306                 (void *)&cmd_set_uc_hash_mac,
8307                 (void *)&cmd_set_uc_hash_mode,
8308                 NULL,
8309         },
8310 };
8311
8312 struct cmd_set_uc_all_hash_table {
8313         cmdline_fixed_string_t set;
8314         cmdline_fixed_string_t port;
8315         portid_t port_id;
8316         cmdline_fixed_string_t what;
8317         cmdline_fixed_string_t value;
8318         cmdline_fixed_string_t mode;
8319 };
8320
8321 static void
8322 cmd_set_uc_all_hash_parsed(void *parsed_result,
8323                        __attribute__((unused)) struct cmdline *cl,
8324                        __attribute__((unused)) void *data)
8325 {
8326         int ret=0;
8327         struct cmd_set_uc_all_hash_table *res = parsed_result;
8328
8329         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8330
8331         if ((strcmp(res->what, "uta") == 0) &&
8332                 (strcmp(res->value, "all") == 0))
8333                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8334         if (ret < 0)
8335                 printf("bad unicast hash table parameter,"
8336                         "return code = %d \n", ret);
8337 }
8338
8339 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8340         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8341                                  set, "set");
8342 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8343         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8344                                  port, "port");
8345 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8346         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8347                               port_id, UINT16);
8348 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8349         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8350                                  what, "uta");
8351 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8352         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8353                                 value,"all");
8354 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8355         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8356                                  mode, "on#off");
8357
8358 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8359         .f = cmd_set_uc_all_hash_parsed,
8360         .data = NULL,
8361         .help_str = "set port <port_id> uta all on|off",
8362         .tokens = {
8363                 (void *)&cmd_set_uc_all_hash_set,
8364                 (void *)&cmd_set_uc_all_hash_port,
8365                 (void *)&cmd_set_uc_all_hash_portid,
8366                 (void *)&cmd_set_uc_all_hash_what,
8367                 (void *)&cmd_set_uc_all_hash_value,
8368                 (void *)&cmd_set_uc_all_hash_mode,
8369                 NULL,
8370         },
8371 };
8372
8373 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8374 struct cmd_set_vf_macvlan_filter {
8375         cmdline_fixed_string_t set;
8376         cmdline_fixed_string_t port;
8377         portid_t port_id;
8378         cmdline_fixed_string_t vf;
8379         uint8_t vf_id;
8380         struct rte_ether_addr address;
8381         cmdline_fixed_string_t filter_type;
8382         cmdline_fixed_string_t mode;
8383 };
8384
8385 static void
8386 cmd_set_vf_macvlan_parsed(void *parsed_result,
8387                        __attribute__((unused)) struct cmdline *cl,
8388                        __attribute__((unused)) void *data)
8389 {
8390         int is_on, ret = 0;
8391         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8392         struct rte_eth_mac_filter filter;
8393
8394         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8395
8396         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8397
8398         /* set VF MAC filter */
8399         filter.is_vf = 1;
8400
8401         /* set VF ID */
8402         filter.dst_id = res->vf_id;
8403
8404         if (!strcmp(res->filter_type, "exact-mac"))
8405                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8406         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8407                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8408         else if (!strcmp(res->filter_type, "hashmac"))
8409                 filter.filter_type = RTE_MAC_HASH_MATCH;
8410         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8411                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8412
8413         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8414
8415         if (is_on)
8416                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8417                                         RTE_ETH_FILTER_MACVLAN,
8418                                         RTE_ETH_FILTER_ADD,
8419                                          &filter);
8420         else
8421                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8422                                         RTE_ETH_FILTER_MACVLAN,
8423                                         RTE_ETH_FILTER_DELETE,
8424                                         &filter);
8425
8426         if (ret < 0)
8427                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8428
8429 }
8430
8431 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8432         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8433                                  set, "set");
8434 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8435         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8436                                  port, "port");
8437 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8438         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8439                               port_id, UINT16);
8440 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8441         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8442                                  vf, "vf");
8443 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8444         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8445                                 vf_id, UINT8);
8446 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8447         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8448                                 address);
8449 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8450         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8451                                 filter_type, "exact-mac#exact-mac-vlan"
8452                                 "#hashmac#hashmac-vlan");
8453 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8455                                  mode, "on#off");
8456
8457 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8458         .f = cmd_set_vf_macvlan_parsed,
8459         .data = NULL,
8460         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8461                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8462                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8463                 "hash match rule: hash match of MAC and exact match of VLAN",
8464         .tokens = {
8465                 (void *)&cmd_set_vf_macvlan_set,
8466                 (void *)&cmd_set_vf_macvlan_port,
8467                 (void *)&cmd_set_vf_macvlan_portid,
8468                 (void *)&cmd_set_vf_macvlan_vf,
8469                 (void *)&cmd_set_vf_macvlan_vf_id,
8470                 (void *)&cmd_set_vf_macvlan_mac,
8471                 (void *)&cmd_set_vf_macvlan_filter_type,
8472                 (void *)&cmd_set_vf_macvlan_mode,
8473                 NULL,
8474         },
8475 };
8476
8477 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8478 struct cmd_set_vf_traffic {
8479         cmdline_fixed_string_t set;
8480         cmdline_fixed_string_t port;
8481         portid_t port_id;
8482         cmdline_fixed_string_t vf;
8483         uint8_t vf_id;
8484         cmdline_fixed_string_t what;
8485         cmdline_fixed_string_t mode;
8486 };
8487
8488 static void
8489 cmd_set_vf_traffic_parsed(void *parsed_result,
8490                        __attribute__((unused)) struct cmdline *cl,
8491                        __attribute__((unused)) void *data)
8492 {
8493         struct cmd_set_vf_traffic *res = parsed_result;
8494         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8495         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8496
8497         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8498 }
8499
8500 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8501         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8502                                  set, "set");
8503 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8504         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8505                                  port, "port");
8506 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8507         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8508                               port_id, UINT16);
8509 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8510         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8511                                  vf, "vf");
8512 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8513         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8514                               vf_id, UINT8);
8515 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8516         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8517                                  what, "tx#rx");
8518 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8519         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8520                                  mode, "on#off");
8521
8522 cmdline_parse_inst_t cmd_set_vf_traffic = {
8523         .f = cmd_set_vf_traffic_parsed,
8524         .data = NULL,
8525         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8526         .tokens = {
8527                 (void *)&cmd_setvf_traffic_set,
8528                 (void *)&cmd_setvf_traffic_port,
8529                 (void *)&cmd_setvf_traffic_portid,
8530                 (void *)&cmd_setvf_traffic_vf,
8531                 (void *)&cmd_setvf_traffic_vfid,
8532                 (void *)&cmd_setvf_traffic_what,
8533                 (void *)&cmd_setvf_traffic_mode,
8534                 NULL,
8535         },
8536 };
8537
8538 /* *** CONFIGURE VF RECEIVE MODE *** */
8539 struct cmd_set_vf_rxmode {
8540         cmdline_fixed_string_t set;
8541         cmdline_fixed_string_t port;
8542         portid_t port_id;
8543         cmdline_fixed_string_t vf;
8544         uint8_t vf_id;
8545         cmdline_fixed_string_t what;
8546         cmdline_fixed_string_t mode;
8547         cmdline_fixed_string_t on;
8548 };
8549
8550 static void
8551 cmd_set_vf_rxmode_parsed(void *parsed_result,
8552                        __attribute__((unused)) struct cmdline *cl,
8553                        __attribute__((unused)) void *data)
8554 {
8555         int ret = -ENOTSUP;
8556         uint16_t vf_rxmode = 0;
8557         struct cmd_set_vf_rxmode *res = parsed_result;
8558
8559         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8560         if (!strcmp(res->what,"rxmode")) {
8561                 if (!strcmp(res->mode, "AUPE"))
8562                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8563                 else if (!strcmp(res->mode, "ROPE"))
8564                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8565                 else if (!strcmp(res->mode, "BAM"))
8566                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8567                 else if (!strncmp(res->mode, "MPE",3))
8568                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8569         }
8570
8571         RTE_SET_USED(is_on);
8572
8573 #ifdef RTE_LIBRTE_IXGBE_PMD
8574         if (ret == -ENOTSUP)
8575                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8576                                                   vf_rxmode, (uint8_t)is_on);
8577 #endif
8578 #ifdef RTE_LIBRTE_BNXT_PMD
8579         if (ret == -ENOTSUP)
8580                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8581                                                  vf_rxmode, (uint8_t)is_on);
8582 #endif
8583         if (ret < 0)
8584                 printf("bad VF receive mode parameter, return code = %d \n",
8585                 ret);
8586 }
8587
8588 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8589         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8590                                  set, "set");
8591 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8592         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8593                                  port, "port");
8594 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8595         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8596                               port_id, UINT16);
8597 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8599                                  vf, "vf");
8600 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8601         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8602                               vf_id, UINT8);
8603 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8605                                  what, "rxmode");
8606 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8608                                  mode, "AUPE#ROPE#BAM#MPE");
8609 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8610         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8611                                  on, "on#off");
8612
8613 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8614         .f = cmd_set_vf_rxmode_parsed,
8615         .data = NULL,
8616         .help_str = "set port <port_id> vf <vf_id> rxmode "
8617                 "AUPE|ROPE|BAM|MPE on|off",
8618         .tokens = {
8619                 (void *)&cmd_set_vf_rxmode_set,
8620                 (void *)&cmd_set_vf_rxmode_port,
8621                 (void *)&cmd_set_vf_rxmode_portid,
8622                 (void *)&cmd_set_vf_rxmode_vf,
8623                 (void *)&cmd_set_vf_rxmode_vfid,
8624                 (void *)&cmd_set_vf_rxmode_what,
8625                 (void *)&cmd_set_vf_rxmode_mode,
8626                 (void *)&cmd_set_vf_rxmode_on,
8627                 NULL,
8628         },
8629 };
8630
8631 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8632 struct cmd_vf_mac_addr_result {
8633         cmdline_fixed_string_t mac_addr_cmd;
8634         cmdline_fixed_string_t what;
8635         cmdline_fixed_string_t port;
8636         uint16_t port_num;
8637         cmdline_fixed_string_t vf;
8638         uint8_t vf_num;
8639         struct rte_ether_addr address;
8640 };
8641
8642 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8643                 __attribute__((unused)) struct cmdline *cl,
8644                 __attribute__((unused)) void *data)
8645 {
8646         struct cmd_vf_mac_addr_result *res = parsed_result;
8647         int ret = -ENOTSUP;
8648
8649         if (strcmp(res->what, "add") != 0)
8650                 return;
8651
8652 #ifdef RTE_LIBRTE_I40E_PMD
8653         if (ret == -ENOTSUP)
8654                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8655                                                    &res->address);
8656 #endif
8657 #ifdef RTE_LIBRTE_BNXT_PMD
8658         if (ret == -ENOTSUP)
8659                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8660                                                 res->vf_num);
8661 #endif
8662
8663         if(ret < 0)
8664                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8665
8666 }
8667
8668 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8669         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8670                                 mac_addr_cmd,"mac_addr");
8671 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8672         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8673                                 what,"add");
8674 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8675         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8676                                 port,"port");
8677 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8678         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8679                                 port_num, UINT16);
8680 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8681         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8682                                 vf,"vf");
8683 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8684         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8685                                 vf_num, UINT8);
8686 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8687         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8688                                 address);
8689
8690 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8691         .f = cmd_vf_mac_addr_parsed,
8692         .data = (void *)0,
8693         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8694                 "Add MAC address filtering for a VF on port_id",
8695         .tokens = {
8696                 (void *)&cmd_vf_mac_addr_cmd,
8697                 (void *)&cmd_vf_mac_addr_what,
8698                 (void *)&cmd_vf_mac_addr_port,
8699                 (void *)&cmd_vf_mac_addr_portnum,
8700                 (void *)&cmd_vf_mac_addr_vf,
8701                 (void *)&cmd_vf_mac_addr_vfnum,
8702                 (void *)&cmd_vf_mac_addr_addr,
8703                 NULL,
8704         },
8705 };
8706
8707 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8708 struct cmd_vf_rx_vlan_filter {
8709         cmdline_fixed_string_t rx_vlan;
8710         cmdline_fixed_string_t what;
8711         uint16_t vlan_id;
8712         cmdline_fixed_string_t port;
8713         portid_t port_id;
8714         cmdline_fixed_string_t vf;
8715         uint64_t vf_mask;
8716 };
8717
8718 static void
8719 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8720                           __attribute__((unused)) struct cmdline *cl,
8721                           __attribute__((unused)) void *data)
8722 {
8723         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8724         int ret = -ENOTSUP;
8725
8726         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8727
8728 #ifdef RTE_LIBRTE_IXGBE_PMD
8729         if (ret == -ENOTSUP)
8730                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8731                                 res->vlan_id, res->vf_mask, is_add);
8732 #endif
8733 #ifdef RTE_LIBRTE_I40E_PMD
8734         if (ret == -ENOTSUP)
8735                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8736                                 res->vlan_id, res->vf_mask, is_add);
8737 #endif
8738 #ifdef RTE_LIBRTE_BNXT_PMD
8739         if (ret == -ENOTSUP)
8740                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8741                                 res->vlan_id, res->vf_mask, is_add);
8742 #endif
8743
8744         switch (ret) {
8745         case 0:
8746                 break;
8747         case -EINVAL:
8748                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8749                                 res->vlan_id, res->vf_mask);
8750                 break;
8751         case -ENODEV:
8752                 printf("invalid port_id %d\n", res->port_id);
8753                 break;
8754         case -ENOTSUP:
8755                 printf("function not implemented or supported\n");
8756                 break;
8757         default:
8758                 printf("programming error: (%s)\n", strerror(-ret));
8759         }
8760 }
8761
8762 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8763         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8764                                  rx_vlan, "rx_vlan");
8765 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8766         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8767                                  what, "add#rm");
8768 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8769         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8770                               vlan_id, UINT16);
8771 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8773                                  port, "port");
8774 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8775         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8776                               port_id, UINT16);
8777 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8779                                  vf, "vf");
8780 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8782                               vf_mask, UINT64);
8783
8784 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8785         .f = cmd_vf_rx_vlan_filter_parsed,
8786         .data = NULL,
8787         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8788                 "(vf_mask = hexadecimal VF mask)",
8789         .tokens = {
8790                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8791                 (void *)&cmd_vf_rx_vlan_filter_what,
8792                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8793                 (void *)&cmd_vf_rx_vlan_filter_port,
8794                 (void *)&cmd_vf_rx_vlan_filter_portid,
8795                 (void *)&cmd_vf_rx_vlan_filter_vf,
8796                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8797                 NULL,
8798         },
8799 };
8800
8801 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8802 struct cmd_queue_rate_limit_result {
8803         cmdline_fixed_string_t set;
8804         cmdline_fixed_string_t port;
8805         uint16_t port_num;
8806         cmdline_fixed_string_t queue;
8807         uint8_t queue_num;
8808         cmdline_fixed_string_t rate;
8809         uint16_t rate_num;
8810 };
8811
8812 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8813                 __attribute__((unused)) struct cmdline *cl,
8814                 __attribute__((unused)) void *data)
8815 {
8816         struct cmd_queue_rate_limit_result *res = parsed_result;
8817         int ret = 0;
8818
8819         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8820                 && (strcmp(res->queue, "queue") == 0)
8821                 && (strcmp(res->rate, "rate") == 0))
8822                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8823                                         res->rate_num);
8824         if (ret < 0)
8825                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8826
8827 }
8828
8829 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8830         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8831                                 set, "set");
8832 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8833         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8834                                 port, "port");
8835 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8836         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8837                                 port_num, UINT16);
8838 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8839         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8840                                 queue, "queue");
8841 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8842         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8843                                 queue_num, UINT8);
8844 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8845         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8846                                 rate, "rate");
8847 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8848         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8849                                 rate_num, UINT16);
8850
8851 cmdline_parse_inst_t cmd_queue_rate_limit = {
8852         .f = cmd_queue_rate_limit_parsed,
8853         .data = (void *)0,
8854         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8855                 "Set rate limit for a queue on port_id",
8856         .tokens = {
8857                 (void *)&cmd_queue_rate_limit_set,
8858                 (void *)&cmd_queue_rate_limit_port,
8859                 (void *)&cmd_queue_rate_limit_portnum,
8860                 (void *)&cmd_queue_rate_limit_queue,
8861                 (void *)&cmd_queue_rate_limit_queuenum,
8862                 (void *)&cmd_queue_rate_limit_rate,
8863                 (void *)&cmd_queue_rate_limit_ratenum,
8864                 NULL,
8865         },
8866 };
8867
8868 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8869 struct cmd_vf_rate_limit_result {
8870         cmdline_fixed_string_t set;
8871         cmdline_fixed_string_t port;
8872         uint16_t port_num;
8873         cmdline_fixed_string_t vf;
8874         uint8_t vf_num;
8875         cmdline_fixed_string_t rate;
8876         uint16_t rate_num;
8877         cmdline_fixed_string_t q_msk;
8878         uint64_t q_msk_val;
8879 };
8880
8881 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8882                 __attribute__((unused)) struct cmdline *cl,
8883                 __attribute__((unused)) void *data)
8884 {
8885         struct cmd_vf_rate_limit_result *res = parsed_result;
8886         int ret = 0;
8887
8888         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8889                 && (strcmp(res->vf, "vf") == 0)
8890                 && (strcmp(res->rate, "rate") == 0)
8891                 && (strcmp(res->q_msk, "queue_mask") == 0))
8892                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8893                                         res->rate_num, res->q_msk_val);
8894         if (ret < 0)
8895                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8896
8897 }
8898
8899 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8900         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8901                                 set, "set");
8902 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8903         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8904                                 port, "port");
8905 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8906         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8907                                 port_num, UINT16);
8908 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8909         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8910                                 vf, "vf");
8911 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8912         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8913                                 vf_num, UINT8);
8914 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8915         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8916                                 rate, "rate");
8917 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8918         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8919                                 rate_num, UINT16);
8920 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8921         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8922                                 q_msk, "queue_mask");
8923 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8924         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8925                                 q_msk_val, UINT64);
8926
8927 cmdline_parse_inst_t cmd_vf_rate_limit = {
8928         .f = cmd_vf_rate_limit_parsed,
8929         .data = (void *)0,
8930         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8931                 "queue_mask <queue_mask_value>: "
8932                 "Set rate limit for queues of VF on port_id",
8933         .tokens = {
8934                 (void *)&cmd_vf_rate_limit_set,
8935                 (void *)&cmd_vf_rate_limit_port,
8936                 (void *)&cmd_vf_rate_limit_portnum,
8937                 (void *)&cmd_vf_rate_limit_vf,
8938                 (void *)&cmd_vf_rate_limit_vfnum,
8939                 (void *)&cmd_vf_rate_limit_rate,
8940                 (void *)&cmd_vf_rate_limit_ratenum,
8941                 (void *)&cmd_vf_rate_limit_q_msk,
8942                 (void *)&cmd_vf_rate_limit_q_msk_val,
8943                 NULL,
8944         },
8945 };
8946
8947 /* *** ADD TUNNEL FILTER OF A PORT *** */
8948 struct cmd_tunnel_filter_result {
8949         cmdline_fixed_string_t cmd;
8950         cmdline_fixed_string_t what;
8951         portid_t port_id;
8952         struct rte_ether_addr outer_mac;
8953         struct rte_ether_addr inner_mac;
8954         cmdline_ipaddr_t ip_value;
8955         uint16_t inner_vlan;
8956         cmdline_fixed_string_t tunnel_type;
8957         cmdline_fixed_string_t filter_type;
8958         uint32_t tenant_id;
8959         uint16_t queue_num;
8960 };
8961
8962 static void
8963 cmd_tunnel_filter_parsed(void *parsed_result,
8964                           __attribute__((unused)) struct cmdline *cl,
8965                           __attribute__((unused)) void *data)
8966 {
8967         struct cmd_tunnel_filter_result *res = parsed_result;
8968         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8969         int ret = 0;
8970
8971         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8972
8973         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8974         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8975         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8976
8977         if (res->ip_value.family == AF_INET) {
8978                 tunnel_filter_conf.ip_addr.ipv4_addr =
8979                         res->ip_value.addr.ipv4.s_addr;
8980                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8981         } else {
8982                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8983                         &(res->ip_value.addr.ipv6),
8984                         sizeof(struct in6_addr));
8985                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8986         }
8987
8988         if (!strcmp(res->filter_type, "imac-ivlan"))
8989                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8990         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8991                 tunnel_filter_conf.filter_type =
8992                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8993         else if (!strcmp(res->filter_type, "imac-tenid"))
8994                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8995         else if (!strcmp(res->filter_type, "imac"))
8996                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8997         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
8998                 tunnel_filter_conf.filter_type =
8999                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9000         else if (!strcmp(res->filter_type, "oip"))
9001                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9002         else if (!strcmp(res->filter_type, "iip"))
9003                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9004         else {
9005                 printf("The filter type is not supported");
9006                 return;
9007         }
9008
9009         if (!strcmp(res->tunnel_type, "vxlan"))
9010                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9011         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9012                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9013         else if (!strcmp(res->tunnel_type, "nvgre"))
9014                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9015         else if (!strcmp(res->tunnel_type, "ipingre"))
9016                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9017         else {
9018                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9019                 return;
9020         }
9021
9022         tunnel_filter_conf.tenant_id = res->tenant_id;
9023         tunnel_filter_conf.queue_id = res->queue_num;
9024         if (!strcmp(res->what, "add"))
9025                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9026                                         RTE_ETH_FILTER_TUNNEL,
9027                                         RTE_ETH_FILTER_ADD,
9028                                         &tunnel_filter_conf);
9029         else
9030                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9031                                         RTE_ETH_FILTER_TUNNEL,
9032                                         RTE_ETH_FILTER_DELETE,
9033                                         &tunnel_filter_conf);
9034         if (ret < 0)
9035                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9036                                 strerror(-ret));
9037
9038 }
9039 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9040         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9041         cmd, "tunnel_filter");
9042 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9043         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9044         what, "add#rm");
9045 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9046         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9047         port_id, UINT16);
9048 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9049         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9050         outer_mac);
9051 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9052         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9053         inner_mac);
9054 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9055         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9056         inner_vlan, UINT16);
9057 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9058         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9059         ip_value);
9060 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9061         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9062         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9063
9064 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9065         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9066         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9067                 "imac#omac-imac-tenid");
9068 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9069         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9070         tenant_id, UINT32);
9071 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9072         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9073         queue_num, UINT16);
9074
9075 cmdline_parse_inst_t cmd_tunnel_filter = {
9076         .f = cmd_tunnel_filter_parsed,
9077         .data = (void *)0,
9078         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9079                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9080                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9081                 "<queue_id>: Add/Rm tunnel filter of a port",
9082         .tokens = {
9083                 (void *)&cmd_tunnel_filter_cmd,
9084                 (void *)&cmd_tunnel_filter_what,
9085                 (void *)&cmd_tunnel_filter_port_id,
9086                 (void *)&cmd_tunnel_filter_outer_mac,
9087                 (void *)&cmd_tunnel_filter_inner_mac,
9088                 (void *)&cmd_tunnel_filter_ip_value,
9089                 (void *)&cmd_tunnel_filter_innner_vlan,
9090                 (void *)&cmd_tunnel_filter_tunnel_type,
9091                 (void *)&cmd_tunnel_filter_filter_type,
9092                 (void *)&cmd_tunnel_filter_tenant_id,
9093                 (void *)&cmd_tunnel_filter_queue_num,
9094                 NULL,
9095         },
9096 };
9097
9098 /* *** CONFIGURE TUNNEL UDP PORT *** */
9099 struct cmd_tunnel_udp_config {
9100         cmdline_fixed_string_t cmd;
9101         cmdline_fixed_string_t what;
9102         uint16_t udp_port;
9103         portid_t port_id;
9104 };
9105
9106 static void
9107 cmd_tunnel_udp_config_parsed(void *parsed_result,
9108                           __attribute__((unused)) struct cmdline *cl,
9109                           __attribute__((unused)) void *data)
9110 {
9111         struct cmd_tunnel_udp_config *res = parsed_result;
9112         struct rte_eth_udp_tunnel tunnel_udp;
9113         int ret;
9114
9115         tunnel_udp.udp_port = res->udp_port;
9116
9117         if (!strcmp(res->cmd, "rx_vxlan_port"))
9118                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9119
9120         if (!strcmp(res->what, "add"))
9121                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9122                                                       &tunnel_udp);
9123         else
9124                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9125                                                          &tunnel_udp);
9126
9127         if (ret < 0)
9128                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9129 }
9130
9131 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9132         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9133                                 cmd, "rx_vxlan_port");
9134 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9135         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9136                                 what, "add#rm");
9137 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9138         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9139                                 udp_port, UINT16);
9140 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9141         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9142                                 port_id, UINT16);
9143
9144 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9145         .f = cmd_tunnel_udp_config_parsed,
9146         .data = (void *)0,
9147         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9148                 "Add/Remove a tunneling UDP port filter",
9149         .tokens = {
9150                 (void *)&cmd_tunnel_udp_config_cmd,
9151                 (void *)&cmd_tunnel_udp_config_what,
9152                 (void *)&cmd_tunnel_udp_config_udp_port,
9153                 (void *)&cmd_tunnel_udp_config_port_id,
9154                 NULL,
9155         },
9156 };
9157
9158 struct cmd_config_tunnel_udp_port {
9159         cmdline_fixed_string_t port;
9160         cmdline_fixed_string_t config;
9161         portid_t port_id;
9162         cmdline_fixed_string_t udp_tunnel_port;
9163         cmdline_fixed_string_t action;
9164         cmdline_fixed_string_t tunnel_type;
9165         uint16_t udp_port;
9166 };
9167
9168 static void
9169 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9170                                __attribute__((unused)) struct cmdline *cl,
9171                                __attribute__((unused)) void *data)
9172 {
9173         struct cmd_config_tunnel_udp_port *res = parsed_result;
9174         struct rte_eth_udp_tunnel tunnel_udp;
9175         int ret = 0;
9176
9177         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9178                 return;
9179
9180         tunnel_udp.udp_port = res->udp_port;
9181
9182         if (!strcmp(res->tunnel_type, "vxlan")) {
9183                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9184         } else if (!strcmp(res->tunnel_type, "geneve")) {
9185                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9186         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9187                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9188         } else {
9189                 printf("Invalid tunnel type\n");
9190                 return;
9191         }
9192
9193         if (!strcmp(res->action, "add"))
9194                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9195                                                       &tunnel_udp);
9196         else
9197                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9198                                                          &tunnel_udp);
9199
9200         if (ret < 0)
9201                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9202 }
9203
9204 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9205         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9206                                  "port");
9207 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9208         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9209                                  "config");
9210 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9211         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9212                               UINT16);
9213 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9214         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9215                                  udp_tunnel_port,
9216                                  "udp_tunnel_port");
9217 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9218         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9219                                  "add#rm");
9220 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9221         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9222                                  "vxlan#geneve#vxlan-gpe");
9223 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9224         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9225                               UINT16);
9226
9227 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9228         .f = cmd_cfg_tunnel_udp_port_parsed,
9229         .data = NULL,
9230         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9231         .tokens = {
9232                 (void *)&cmd_config_tunnel_udp_port_port,
9233                 (void *)&cmd_config_tunnel_udp_port_config,
9234                 (void *)&cmd_config_tunnel_udp_port_port_id,
9235                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9236                 (void *)&cmd_config_tunnel_udp_port_action,
9237                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9238                 (void *)&cmd_config_tunnel_udp_port_value,
9239                 NULL,
9240         },
9241 };
9242
9243 /* *** GLOBAL CONFIG *** */
9244 struct cmd_global_config_result {
9245         cmdline_fixed_string_t cmd;
9246         portid_t port_id;
9247         cmdline_fixed_string_t cfg_type;
9248         uint8_t len;
9249 };
9250
9251 static void
9252 cmd_global_config_parsed(void *parsed_result,
9253                          __attribute__((unused)) struct cmdline *cl,
9254                          __attribute__((unused)) void *data)
9255 {
9256         struct cmd_global_config_result *res = parsed_result;
9257         struct rte_eth_global_cfg conf;
9258         int ret;
9259
9260         memset(&conf, 0, sizeof(conf));
9261         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9262         conf.cfg.gre_key_len = res->len;
9263         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9264                                       RTE_ETH_FILTER_SET, &conf);
9265         if (ret != 0)
9266                 printf("Global config error\n");
9267 }
9268
9269 cmdline_parse_token_string_t cmd_global_config_cmd =
9270         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9271                 "global_config");
9272 cmdline_parse_token_num_t cmd_global_config_port_id =
9273         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9274                                UINT16);
9275 cmdline_parse_token_string_t cmd_global_config_type =
9276         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9277                 cfg_type, "gre-key-len");
9278 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9279         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9280                 len, UINT8);
9281
9282 cmdline_parse_inst_t cmd_global_config = {
9283         .f = cmd_global_config_parsed,
9284         .data = (void *)NULL,
9285         .help_str = "global_config <port_id> gre-key-len <key_len>",
9286         .tokens = {
9287                 (void *)&cmd_global_config_cmd,
9288                 (void *)&cmd_global_config_port_id,
9289                 (void *)&cmd_global_config_type,
9290                 (void *)&cmd_global_config_gre_key_len,
9291                 NULL,
9292         },
9293 };
9294
9295 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9296 struct cmd_set_mirror_mask_result {
9297         cmdline_fixed_string_t set;
9298         cmdline_fixed_string_t port;
9299         portid_t port_id;
9300         cmdline_fixed_string_t mirror;
9301         uint8_t rule_id;
9302         cmdline_fixed_string_t what;
9303         cmdline_fixed_string_t value;
9304         cmdline_fixed_string_t dstpool;
9305         uint8_t dstpool_id;
9306         cmdline_fixed_string_t on;
9307 };
9308
9309 cmdline_parse_token_string_t cmd_mirror_mask_set =
9310         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9311                                 set, "set");
9312 cmdline_parse_token_string_t cmd_mirror_mask_port =
9313         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9314                                 port, "port");
9315 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9316         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9317                                 port_id, UINT16);
9318 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9319         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9320                                 mirror, "mirror-rule");
9321 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9322         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9323                                 rule_id, UINT8);
9324 cmdline_parse_token_string_t cmd_mirror_mask_what =
9325         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9326                                 what, "pool-mirror-up#pool-mirror-down"
9327                                       "#vlan-mirror");
9328 cmdline_parse_token_string_t cmd_mirror_mask_value =
9329         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9330                                 value, NULL);
9331 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9333                                 dstpool, "dst-pool");
9334 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9335         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9336                                 dstpool_id, UINT8);
9337 cmdline_parse_token_string_t cmd_mirror_mask_on =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9339                                 on, "on#off");
9340
9341 static void
9342 cmd_set_mirror_mask_parsed(void *parsed_result,
9343                        __attribute__((unused)) struct cmdline *cl,
9344                        __attribute__((unused)) void *data)
9345 {
9346         int ret,nb_item,i;
9347         struct cmd_set_mirror_mask_result *res = parsed_result;
9348         struct rte_eth_mirror_conf mr_conf;
9349
9350         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9351
9352         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9353
9354         mr_conf.dst_pool = res->dstpool_id;
9355
9356         if (!strcmp(res->what, "pool-mirror-up")) {
9357                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9358                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9359         } else if (!strcmp(res->what, "pool-mirror-down")) {
9360                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9361                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9362         } else if (!strcmp(res->what, "vlan-mirror")) {
9363                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9364                 nb_item = parse_item_list(res->value, "vlan",
9365                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9366                 if (nb_item <= 0)
9367                         return;
9368
9369                 for (i = 0; i < nb_item; i++) {
9370                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9371                                 printf("Invalid vlan_id: must be < 4096\n");
9372                                 return;
9373                         }
9374
9375                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9376                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9377                 }
9378         }
9379
9380         if (!strcmp(res->on, "on"))
9381                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9382                                                 res->rule_id, 1);
9383         else
9384                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9385                                                 res->rule_id, 0);
9386         if (ret < 0)
9387                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9388 }
9389
9390 cmdline_parse_inst_t cmd_set_mirror_mask = {
9391                 .f = cmd_set_mirror_mask_parsed,
9392                 .data = NULL,
9393                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9394                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9395                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9396                 .tokens = {
9397                         (void *)&cmd_mirror_mask_set,
9398                         (void *)&cmd_mirror_mask_port,
9399                         (void *)&cmd_mirror_mask_portid,
9400                         (void *)&cmd_mirror_mask_mirror,
9401                         (void *)&cmd_mirror_mask_ruleid,
9402                         (void *)&cmd_mirror_mask_what,
9403                         (void *)&cmd_mirror_mask_value,
9404                         (void *)&cmd_mirror_mask_dstpool,
9405                         (void *)&cmd_mirror_mask_poolid,
9406                         (void *)&cmd_mirror_mask_on,
9407                         NULL,
9408                 },
9409 };
9410
9411 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9412 struct cmd_set_mirror_link_result {
9413         cmdline_fixed_string_t set;
9414         cmdline_fixed_string_t port;
9415         portid_t port_id;
9416         cmdline_fixed_string_t mirror;
9417         uint8_t rule_id;
9418         cmdline_fixed_string_t what;
9419         cmdline_fixed_string_t dstpool;
9420         uint8_t dstpool_id;
9421         cmdline_fixed_string_t on;
9422 };
9423
9424 cmdline_parse_token_string_t cmd_mirror_link_set =
9425         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9426                                  set, "set");
9427 cmdline_parse_token_string_t cmd_mirror_link_port =
9428         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9429                                 port, "port");
9430 cmdline_parse_token_num_t cmd_mirror_link_portid =
9431         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9432                                 port_id, UINT16);
9433 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9434         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9435                                 mirror, "mirror-rule");
9436 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9437         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9438                             rule_id, UINT8);
9439 cmdline_parse_token_string_t cmd_mirror_link_what =
9440         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9441                                 what, "uplink-mirror#downlink-mirror");
9442 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9443         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9444                                 dstpool, "dst-pool");
9445 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9446         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9447                                 dstpool_id, UINT8);
9448 cmdline_parse_token_string_t cmd_mirror_link_on =
9449         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9450                                 on, "on#off");
9451
9452 static void
9453 cmd_set_mirror_link_parsed(void *parsed_result,
9454                        __attribute__((unused)) struct cmdline *cl,
9455                        __attribute__((unused)) void *data)
9456 {
9457         int ret;
9458         struct cmd_set_mirror_link_result *res = parsed_result;
9459         struct rte_eth_mirror_conf mr_conf;
9460
9461         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9462         if (!strcmp(res->what, "uplink-mirror"))
9463                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9464         else
9465                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9466
9467         mr_conf.dst_pool = res->dstpool_id;
9468
9469         if (!strcmp(res->on, "on"))
9470                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9471                                                 res->rule_id, 1);
9472         else
9473                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9474                                                 res->rule_id, 0);
9475
9476         /* check the return value and print it if is < 0 */
9477         if (ret < 0)
9478                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9479
9480 }
9481
9482 cmdline_parse_inst_t cmd_set_mirror_link = {
9483                 .f = cmd_set_mirror_link_parsed,
9484                 .data = NULL,
9485                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9486                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9487                 .tokens = {
9488                         (void *)&cmd_mirror_link_set,
9489                         (void *)&cmd_mirror_link_port,
9490                         (void *)&cmd_mirror_link_portid,
9491                         (void *)&cmd_mirror_link_mirror,
9492                         (void *)&cmd_mirror_link_ruleid,
9493                         (void *)&cmd_mirror_link_what,
9494                         (void *)&cmd_mirror_link_dstpool,
9495                         (void *)&cmd_mirror_link_poolid,
9496                         (void *)&cmd_mirror_link_on,
9497                         NULL,
9498                 },
9499 };
9500
9501 /* *** RESET VM MIRROR RULE *** */
9502 struct cmd_rm_mirror_rule_result {
9503         cmdline_fixed_string_t reset;
9504         cmdline_fixed_string_t port;
9505         portid_t port_id;
9506         cmdline_fixed_string_t mirror;
9507         uint8_t rule_id;
9508 };
9509
9510 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9511         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9512                                  reset, "reset");
9513 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9514         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9515                                 port, "port");
9516 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9517         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9518                                 port_id, UINT16);
9519 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9520         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9521                                 mirror, "mirror-rule");
9522 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9523         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9524                                 rule_id, UINT8);
9525
9526 static void
9527 cmd_reset_mirror_rule_parsed(void *parsed_result,
9528                        __attribute__((unused)) struct cmdline *cl,
9529                        __attribute__((unused)) void *data)
9530 {
9531         int ret;
9532         struct cmd_set_mirror_link_result *res = parsed_result;
9533         /* check rule_id */
9534         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9535         if(ret < 0)
9536                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9537 }
9538
9539 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9540                 .f = cmd_reset_mirror_rule_parsed,
9541                 .data = NULL,
9542                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9543                 .tokens = {
9544                         (void *)&cmd_rm_mirror_rule_reset,
9545                         (void *)&cmd_rm_mirror_rule_port,
9546                         (void *)&cmd_rm_mirror_rule_portid,
9547                         (void *)&cmd_rm_mirror_rule_mirror,
9548                         (void *)&cmd_rm_mirror_rule_ruleid,
9549                         NULL,
9550                 },
9551 };
9552
9553 /* ******************************************************************************** */
9554
9555 struct cmd_dump_result {
9556         cmdline_fixed_string_t dump;
9557 };
9558
9559 static void
9560 dump_struct_sizes(void)
9561 {
9562 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9563         DUMP_SIZE(struct rte_mbuf);
9564         DUMP_SIZE(struct rte_mempool);
9565         DUMP_SIZE(struct rte_ring);
9566 #undef DUMP_SIZE
9567 }
9568
9569 static void cmd_dump_parsed(void *parsed_result,
9570                             __attribute__((unused)) struct cmdline *cl,
9571                             __attribute__((unused)) void *data)
9572 {
9573         struct cmd_dump_result *res = parsed_result;
9574
9575         if (!strcmp(res->dump, "dump_physmem"))
9576                 rte_dump_physmem_layout(stdout);
9577         else if (!strcmp(res->dump, "dump_memzone"))
9578                 rte_memzone_dump(stdout);
9579         else if (!strcmp(res->dump, "dump_struct_sizes"))
9580                 dump_struct_sizes();
9581         else if (!strcmp(res->dump, "dump_ring"))
9582                 rte_ring_list_dump(stdout);
9583         else if (!strcmp(res->dump, "dump_mempool"))
9584                 rte_mempool_list_dump(stdout);
9585         else if (!strcmp(res->dump, "dump_devargs"))
9586                 rte_devargs_dump(stdout);
9587         else if (!strcmp(res->dump, "dump_log_types"))
9588                 rte_log_dump(stdout);
9589 }
9590
9591 cmdline_parse_token_string_t cmd_dump_dump =
9592         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9593                 "dump_physmem#"
9594                 "dump_memzone#"
9595                 "dump_struct_sizes#"
9596                 "dump_ring#"
9597                 "dump_mempool#"
9598                 "dump_devargs#"
9599                 "dump_log_types");
9600
9601 cmdline_parse_inst_t cmd_dump = {
9602         .f = cmd_dump_parsed,  /* function to call */
9603         .data = NULL,      /* 2nd arg of func */
9604         .help_str = "Dump status",
9605         .tokens = {        /* token list, NULL terminated */
9606                 (void *)&cmd_dump_dump,
9607                 NULL,
9608         },
9609 };
9610
9611 /* ******************************************************************************** */
9612
9613 struct cmd_dump_one_result {
9614         cmdline_fixed_string_t dump;
9615         cmdline_fixed_string_t name;
9616 };
9617
9618 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9619                                 __attribute__((unused)) void *data)
9620 {
9621         struct cmd_dump_one_result *res = parsed_result;
9622
9623         if (!strcmp(res->dump, "dump_ring")) {
9624                 struct rte_ring *r;
9625                 r = rte_ring_lookup(res->name);
9626                 if (r == NULL) {
9627                         cmdline_printf(cl, "Cannot find ring\n");
9628                         return;
9629                 }
9630                 rte_ring_dump(stdout, r);
9631         } else if (!strcmp(res->dump, "dump_mempool")) {
9632                 struct rte_mempool *mp;
9633                 mp = rte_mempool_lookup(res->name);
9634                 if (mp == NULL) {
9635                         cmdline_printf(cl, "Cannot find mempool\n");
9636                         return;
9637                 }
9638                 rte_mempool_dump(stdout, mp);
9639         }
9640 }
9641
9642 cmdline_parse_token_string_t cmd_dump_one_dump =
9643         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9644                                  "dump_ring#dump_mempool");
9645
9646 cmdline_parse_token_string_t cmd_dump_one_name =
9647         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9648
9649 cmdline_parse_inst_t cmd_dump_one = {
9650         .f = cmd_dump_one_parsed,  /* function to call */
9651         .data = NULL,      /* 2nd arg of func */
9652         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9653         .tokens = {        /* token list, NULL terminated */
9654                 (void *)&cmd_dump_one_dump,
9655                 (void *)&cmd_dump_one_name,
9656                 NULL,
9657         },
9658 };
9659
9660 /* *** Add/Del syn filter *** */
9661 struct cmd_syn_filter_result {
9662         cmdline_fixed_string_t filter;
9663         portid_t port_id;
9664         cmdline_fixed_string_t ops;
9665         cmdline_fixed_string_t priority;
9666         cmdline_fixed_string_t high;
9667         cmdline_fixed_string_t queue;
9668         uint16_t queue_id;
9669 };
9670
9671 static void
9672 cmd_syn_filter_parsed(void *parsed_result,
9673                         __attribute__((unused)) struct cmdline *cl,
9674                         __attribute__((unused)) void *data)
9675 {
9676         struct cmd_syn_filter_result *res = parsed_result;
9677         struct rte_eth_syn_filter syn_filter;
9678         int ret = 0;
9679
9680         ret = rte_eth_dev_filter_supported(res->port_id,
9681                                         RTE_ETH_FILTER_SYN);
9682         if (ret < 0) {
9683                 printf("syn filter is not supported on port %u.\n",
9684                                 res->port_id);
9685                 return;
9686         }
9687
9688         memset(&syn_filter, 0, sizeof(syn_filter));
9689
9690         if (!strcmp(res->ops, "add")) {
9691                 if (!strcmp(res->high, "high"))
9692                         syn_filter.hig_pri = 1;
9693                 else
9694                         syn_filter.hig_pri = 0;
9695
9696                 syn_filter.queue = res->queue_id;
9697                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9698                                                 RTE_ETH_FILTER_SYN,
9699                                                 RTE_ETH_FILTER_ADD,
9700                                                 &syn_filter);
9701         } else
9702                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9703                                                 RTE_ETH_FILTER_SYN,
9704                                                 RTE_ETH_FILTER_DELETE,
9705                                                 &syn_filter);
9706
9707         if (ret < 0)
9708                 printf("syn filter programming error: (%s)\n",
9709                                 strerror(-ret));
9710 }
9711
9712 cmdline_parse_token_string_t cmd_syn_filter_filter =
9713         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9714         filter, "syn_filter");
9715 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9716         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9717         port_id, UINT16);
9718 cmdline_parse_token_string_t cmd_syn_filter_ops =
9719         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9720         ops, "add#del");
9721 cmdline_parse_token_string_t cmd_syn_filter_priority =
9722         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9723                                 priority, "priority");
9724 cmdline_parse_token_string_t cmd_syn_filter_high =
9725         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9726                                 high, "high#low");
9727 cmdline_parse_token_string_t cmd_syn_filter_queue =
9728         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9729                                 queue, "queue");
9730 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9731         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9732                                 queue_id, UINT16);
9733
9734 cmdline_parse_inst_t cmd_syn_filter = {
9735         .f = cmd_syn_filter_parsed,
9736         .data = NULL,
9737         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9738                 "<queue_id>: Add/Delete syn filter",
9739         .tokens = {
9740                 (void *)&cmd_syn_filter_filter,
9741                 (void *)&cmd_syn_filter_port_id,
9742                 (void *)&cmd_syn_filter_ops,
9743                 (void *)&cmd_syn_filter_priority,
9744                 (void *)&cmd_syn_filter_high,
9745                 (void *)&cmd_syn_filter_queue,
9746                 (void *)&cmd_syn_filter_queue_id,
9747                 NULL,
9748         },
9749 };
9750
9751 /* *** queue region set *** */
9752 struct cmd_queue_region_result {
9753         cmdline_fixed_string_t set;
9754         cmdline_fixed_string_t port;
9755         portid_t port_id;
9756         cmdline_fixed_string_t cmd;
9757         cmdline_fixed_string_t region;
9758         uint8_t  region_id;
9759         cmdline_fixed_string_t queue_start_index;
9760         uint8_t  queue_id;
9761         cmdline_fixed_string_t queue_num;
9762         uint8_t  queue_num_value;
9763 };
9764
9765 static void
9766 cmd_queue_region_parsed(void *parsed_result,
9767                         __attribute__((unused)) struct cmdline *cl,
9768                         __attribute__((unused)) void *data)
9769 {
9770         struct cmd_queue_region_result *res = parsed_result;
9771         int ret = -ENOTSUP;
9772 #ifdef RTE_LIBRTE_I40E_PMD
9773         struct rte_pmd_i40e_queue_region_conf region_conf;
9774         enum rte_pmd_i40e_queue_region_op op_type;
9775 #endif
9776
9777         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9778                 return;
9779
9780 #ifdef RTE_LIBRTE_I40E_PMD
9781         memset(&region_conf, 0, sizeof(region_conf));
9782         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9783         region_conf.region_id = res->region_id;
9784         region_conf.queue_num = res->queue_num_value;
9785         region_conf.queue_start_index = res->queue_id;
9786
9787         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9788                                 op_type, &region_conf);
9789 #endif
9790
9791         switch (ret) {
9792         case 0:
9793                 break;
9794         case -ENOTSUP:
9795                 printf("function not implemented or supported\n");
9796                 break;
9797         default:
9798                 printf("queue region config error: (%s)\n", strerror(-ret));
9799         }
9800 }
9801
9802 cmdline_parse_token_string_t cmd_queue_region_set =
9803 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9804                 set, "set");
9805 cmdline_parse_token_string_t cmd_queue_region_port =
9806         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9807 cmdline_parse_token_num_t cmd_queue_region_port_id =
9808         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9809                                 port_id, UINT16);
9810 cmdline_parse_token_string_t cmd_queue_region_cmd =
9811         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9812                                  cmd, "queue-region");
9813 cmdline_parse_token_string_t cmd_queue_region_id =
9814         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9815                                 region, "region_id");
9816 cmdline_parse_token_num_t cmd_queue_region_index =
9817         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9818                                 region_id, UINT8);
9819 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9820         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9821                                 queue_start_index, "queue_start_index");
9822 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9823         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9824                                 queue_id, UINT8);
9825 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9826         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9827                                 queue_num, "queue_num");
9828 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9829         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9830                                 queue_num_value, UINT8);
9831
9832 cmdline_parse_inst_t cmd_queue_region = {
9833         .f = cmd_queue_region_parsed,
9834         .data = NULL,
9835         .help_str = "set port <port_id> queue-region region_id <value> "
9836                 "queue_start_index <value> queue_num <value>: Set a queue region",
9837         .tokens = {
9838                 (void *)&cmd_queue_region_set,
9839                 (void *)&cmd_queue_region_port,
9840                 (void *)&cmd_queue_region_port_id,
9841                 (void *)&cmd_queue_region_cmd,
9842                 (void *)&cmd_queue_region_id,
9843                 (void *)&cmd_queue_region_index,
9844                 (void *)&cmd_queue_region_queue_start_index,
9845                 (void *)&cmd_queue_region_queue_id,
9846                 (void *)&cmd_queue_region_queue_num,
9847                 (void *)&cmd_queue_region_queue_num_value,
9848                 NULL,
9849         },
9850 };
9851
9852 /* *** queue region and flowtype set *** */
9853 struct cmd_region_flowtype_result {
9854         cmdline_fixed_string_t set;
9855         cmdline_fixed_string_t port;
9856         portid_t port_id;
9857         cmdline_fixed_string_t cmd;
9858         cmdline_fixed_string_t region;
9859         uint8_t  region_id;
9860         cmdline_fixed_string_t flowtype;
9861         uint8_t  flowtype_id;
9862 };
9863
9864 static void
9865 cmd_region_flowtype_parsed(void *parsed_result,
9866                         __attribute__((unused)) struct cmdline *cl,
9867                         __attribute__((unused)) void *data)
9868 {
9869         struct cmd_region_flowtype_result *res = parsed_result;
9870         int ret = -ENOTSUP;
9871 #ifdef RTE_LIBRTE_I40E_PMD
9872         struct rte_pmd_i40e_queue_region_conf region_conf;
9873         enum rte_pmd_i40e_queue_region_op op_type;
9874 #endif
9875
9876         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9877                 return;
9878
9879 #ifdef RTE_LIBRTE_I40E_PMD
9880         memset(&region_conf, 0, sizeof(region_conf));
9881
9882         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9883         region_conf.region_id = res->region_id;
9884         region_conf.hw_flowtype = res->flowtype_id;
9885
9886         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9887                         op_type, &region_conf);
9888 #endif
9889
9890         switch (ret) {
9891         case 0:
9892                 break;
9893         case -ENOTSUP:
9894                 printf("function not implemented or supported\n");
9895                 break;
9896         default:
9897                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9898         }
9899 }
9900
9901 cmdline_parse_token_string_t cmd_region_flowtype_set =
9902 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9903                                 set, "set");
9904 cmdline_parse_token_string_t cmd_region_flowtype_port =
9905         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9906                                 port, "port");
9907 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9908         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9909                                 port_id, UINT16);
9910 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9911         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9912                                 cmd, "queue-region");
9913 cmdline_parse_token_string_t cmd_region_flowtype_index =
9914         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9915                                 region, "region_id");
9916 cmdline_parse_token_num_t cmd_region_flowtype_id =
9917         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9918                                 region_id, UINT8);
9919 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9920         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9921                                 flowtype, "flowtype");
9922 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9923         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9924                                 flowtype_id, UINT8);
9925 cmdline_parse_inst_t cmd_region_flowtype = {
9926         .f = cmd_region_flowtype_parsed,
9927         .data = NULL,
9928         .help_str = "set port <port_id> queue-region region_id <value> "
9929                 "flowtype <value>: Set a flowtype region index",
9930         .tokens = {
9931                 (void *)&cmd_region_flowtype_set,
9932                 (void *)&cmd_region_flowtype_port,
9933                 (void *)&cmd_region_flowtype_port_index,
9934                 (void *)&cmd_region_flowtype_cmd,
9935                 (void *)&cmd_region_flowtype_index,
9936                 (void *)&cmd_region_flowtype_id,
9937                 (void *)&cmd_region_flowtype_flow_index,
9938                 (void *)&cmd_region_flowtype_flow_id,
9939                 NULL,
9940         },
9941 };
9942
9943 /* *** User Priority (UP) to queue region (region_id) set *** */
9944 struct cmd_user_priority_region_result {
9945         cmdline_fixed_string_t set;
9946         cmdline_fixed_string_t port;
9947         portid_t port_id;
9948         cmdline_fixed_string_t cmd;
9949         cmdline_fixed_string_t user_priority;
9950         uint8_t  user_priority_id;
9951         cmdline_fixed_string_t region;
9952         uint8_t  region_id;
9953 };
9954
9955 static void
9956 cmd_user_priority_region_parsed(void *parsed_result,
9957                         __attribute__((unused)) struct cmdline *cl,
9958                         __attribute__((unused)) void *data)
9959 {
9960         struct cmd_user_priority_region_result *res = parsed_result;
9961         int ret = -ENOTSUP;
9962 #ifdef RTE_LIBRTE_I40E_PMD
9963         struct rte_pmd_i40e_queue_region_conf region_conf;
9964         enum rte_pmd_i40e_queue_region_op op_type;
9965 #endif
9966
9967         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9968                 return;
9969
9970 #ifdef RTE_LIBRTE_I40E_PMD
9971         memset(&region_conf, 0, sizeof(region_conf));
9972         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
9973         region_conf.user_priority = res->user_priority_id;
9974         region_conf.region_id = res->region_id;
9975
9976         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9977                                 op_type, &region_conf);
9978 #endif
9979
9980         switch (ret) {
9981         case 0:
9982                 break;
9983         case -ENOTSUP:
9984                 printf("function not implemented or supported\n");
9985                 break;
9986         default:
9987                 printf("user_priority region config error: (%s)\n",
9988                                 strerror(-ret));
9989         }
9990 }
9991
9992 cmdline_parse_token_string_t cmd_user_priority_region_set =
9993         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9994                                 set, "set");
9995 cmdline_parse_token_string_t cmd_user_priority_region_port =
9996         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
9997                                 port, "port");
9998 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
9999         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10000                                 port_id, UINT16);
10001 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10002         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10003                                 cmd, "queue-region");
10004 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10005         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10006                                 user_priority, "UP");
10007 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10008         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10009                                 user_priority_id, UINT8);
10010 cmdline_parse_token_string_t cmd_user_priority_region_region =
10011         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10012                                 region, "region_id");
10013 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10014         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10015                                 region_id, UINT8);
10016
10017 cmdline_parse_inst_t cmd_user_priority_region = {
10018         .f = cmd_user_priority_region_parsed,
10019         .data = NULL,
10020         .help_str = "set port <port_id> queue-region UP <value> "
10021                 "region_id <value>: Set the mapping of User Priority (UP) "
10022                 "to queue region (region_id) ",
10023         .tokens = {
10024                 (void *)&cmd_user_priority_region_set,
10025                 (void *)&cmd_user_priority_region_port,
10026                 (void *)&cmd_user_priority_region_port_index,
10027                 (void *)&cmd_user_priority_region_cmd,
10028                 (void *)&cmd_user_priority_region_UP,
10029                 (void *)&cmd_user_priority_region_UP_id,
10030                 (void *)&cmd_user_priority_region_region,
10031                 (void *)&cmd_user_priority_region_region_id,
10032                 NULL,
10033         },
10034 };
10035
10036 /* *** flush all queue region related configuration *** */
10037 struct cmd_flush_queue_region_result {
10038         cmdline_fixed_string_t set;
10039         cmdline_fixed_string_t port;
10040         portid_t port_id;
10041         cmdline_fixed_string_t cmd;
10042         cmdline_fixed_string_t flush;
10043         cmdline_fixed_string_t what;
10044 };
10045
10046 static void
10047 cmd_flush_queue_region_parsed(void *parsed_result,
10048                         __attribute__((unused)) struct cmdline *cl,
10049                         __attribute__((unused)) void *data)
10050 {
10051         struct cmd_flush_queue_region_result *res = parsed_result;
10052         int ret = -ENOTSUP;
10053 #ifdef RTE_LIBRTE_I40E_PMD
10054         struct rte_pmd_i40e_queue_region_conf region_conf;
10055         enum rte_pmd_i40e_queue_region_op op_type;
10056 #endif
10057
10058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10059                 return;
10060
10061 #ifdef RTE_LIBRTE_I40E_PMD
10062         memset(&region_conf, 0, sizeof(region_conf));
10063
10064         if (strcmp(res->what, "on") == 0)
10065                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10066         else
10067                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10068
10069         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10070                                 op_type, &region_conf);
10071 #endif
10072
10073         switch (ret) {
10074         case 0:
10075                 break;
10076         case -ENOTSUP:
10077                 printf("function not implemented or supported\n");
10078                 break;
10079         default:
10080                 printf("queue region config flush error: (%s)\n",
10081                                 strerror(-ret));
10082         }
10083 }
10084
10085 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10086         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10087                                 set, "set");
10088 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10089         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10090                                 port, "port");
10091 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10092         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10093                                 port_id, UINT16);
10094 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10095         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10096                                 cmd, "queue-region");
10097 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10098         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10099                                 flush, "flush");
10100 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10101         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10102                                 what, "on#off");
10103
10104 cmdline_parse_inst_t cmd_flush_queue_region = {
10105         .f = cmd_flush_queue_region_parsed,
10106         .data = NULL,
10107         .help_str = "set port <port_id> queue-region flush on|off"
10108                 ": flush all queue region related configuration",
10109         .tokens = {
10110                 (void *)&cmd_flush_queue_region_set,
10111                 (void *)&cmd_flush_queue_region_port,
10112                 (void *)&cmd_flush_queue_region_port_index,
10113                 (void *)&cmd_flush_queue_region_cmd,
10114                 (void *)&cmd_flush_queue_region_flush,
10115                 (void *)&cmd_flush_queue_region_what,
10116                 NULL,
10117         },
10118 };
10119
10120 /* *** get all queue region related configuration info *** */
10121 struct cmd_show_queue_region_info {
10122         cmdline_fixed_string_t show;
10123         cmdline_fixed_string_t port;
10124         portid_t port_id;
10125         cmdline_fixed_string_t cmd;
10126 };
10127
10128 static void
10129 cmd_show_queue_region_info_parsed(void *parsed_result,
10130                         __attribute__((unused)) struct cmdline *cl,
10131                         __attribute__((unused)) void *data)
10132 {
10133         struct cmd_show_queue_region_info *res = parsed_result;
10134         int ret = -ENOTSUP;
10135 #ifdef RTE_LIBRTE_I40E_PMD
10136         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10137         enum rte_pmd_i40e_queue_region_op op_type;
10138 #endif
10139
10140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10141                 return;
10142
10143 #ifdef RTE_LIBRTE_I40E_PMD
10144         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10145
10146         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10147
10148         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10149                                         op_type, &rte_pmd_regions);
10150
10151         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10152 #endif
10153
10154         switch (ret) {
10155         case 0:
10156                 break;
10157         case -ENOTSUP:
10158                 printf("function not implemented or supported\n");
10159                 break;
10160         default:
10161                 printf("queue region config info show error: (%s)\n",
10162                                 strerror(-ret));
10163         }
10164 }
10165
10166 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10167 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10168                                 show, "show");
10169 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10170         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10171                                 port, "port");
10172 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10173         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10174                                 port_id, UINT16);
10175 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10176         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10177                                 cmd, "queue-region");
10178
10179 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10180         .f = cmd_show_queue_region_info_parsed,
10181         .data = NULL,
10182         .help_str = "show port <port_id> queue-region"
10183                 ": show all queue region related configuration info",
10184         .tokens = {
10185                 (void *)&cmd_show_queue_region_info_get,
10186                 (void *)&cmd_show_queue_region_info_port,
10187                 (void *)&cmd_show_queue_region_info_port_index,
10188                 (void *)&cmd_show_queue_region_info_cmd,
10189                 NULL,
10190         },
10191 };
10192
10193 /* *** ADD/REMOVE A 2tuple FILTER *** */
10194 struct cmd_2tuple_filter_result {
10195         cmdline_fixed_string_t filter;
10196         portid_t port_id;
10197         cmdline_fixed_string_t ops;
10198         cmdline_fixed_string_t dst_port;
10199         uint16_t dst_port_value;
10200         cmdline_fixed_string_t protocol;
10201         uint8_t protocol_value;
10202         cmdline_fixed_string_t mask;
10203         uint8_t  mask_value;
10204         cmdline_fixed_string_t tcp_flags;
10205         uint8_t tcp_flags_value;
10206         cmdline_fixed_string_t priority;
10207         uint8_t  priority_value;
10208         cmdline_fixed_string_t queue;
10209         uint16_t  queue_id;
10210 };
10211
10212 static void
10213 cmd_2tuple_filter_parsed(void *parsed_result,
10214                         __attribute__((unused)) struct cmdline *cl,
10215                         __attribute__((unused)) void *data)
10216 {
10217         struct rte_eth_ntuple_filter filter;
10218         struct cmd_2tuple_filter_result *res = parsed_result;
10219         int ret = 0;
10220
10221         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10222         if (ret < 0) {
10223                 printf("ntuple filter is not supported on port %u.\n",
10224                         res->port_id);
10225                 return;
10226         }
10227
10228         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10229
10230         filter.flags = RTE_2TUPLE_FLAGS;
10231         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10232         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10233         filter.proto = res->protocol_value;
10234         filter.priority = res->priority_value;
10235         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10236                 printf("nonzero tcp_flags is only meaningful"
10237                         " when protocol is TCP.\n");
10238                 return;
10239         }
10240         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10241                 printf("invalid TCP flags.\n");
10242                 return;
10243         }
10244
10245         if (res->tcp_flags_value != 0) {
10246                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10247                 filter.tcp_flags = res->tcp_flags_value;
10248         }
10249
10250         /* need convert to big endian. */
10251         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10252         filter.queue = res->queue_id;
10253
10254         if (!strcmp(res->ops, "add"))
10255                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10256                                 RTE_ETH_FILTER_NTUPLE,
10257                                 RTE_ETH_FILTER_ADD,
10258                                 &filter);
10259         else
10260                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10261                                 RTE_ETH_FILTER_NTUPLE,
10262                                 RTE_ETH_FILTER_DELETE,
10263                                 &filter);
10264         if (ret < 0)
10265                 printf("2tuple filter programming error: (%s)\n",
10266                         strerror(-ret));
10267
10268 }
10269
10270 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10271         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10272                                  filter, "2tuple_filter");
10273 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10274         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10275                                 port_id, UINT16);
10276 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10277         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10278                                  ops, "add#del");
10279 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10280         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10281                                 dst_port, "dst_port");
10282 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10283         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10284                                 dst_port_value, UINT16);
10285 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10286         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10287                                 protocol, "protocol");
10288 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10289         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10290                                 protocol_value, UINT8);
10291 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10292         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10293                                 mask, "mask");
10294 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10295         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10296                                 mask_value, INT8);
10297 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10298         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10299                                 tcp_flags, "tcp_flags");
10300 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10301         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10302                                 tcp_flags_value, UINT8);
10303 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10304         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10305                                 priority, "priority");
10306 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10307         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10308                                 priority_value, UINT8);
10309 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10310         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10311                                 queue, "queue");
10312 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10313         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10314                                 queue_id, UINT16);
10315
10316 cmdline_parse_inst_t cmd_2tuple_filter = {
10317         .f = cmd_2tuple_filter_parsed,
10318         .data = NULL,
10319         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10320                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10321                 "<queue_id>: Add a 2tuple filter",
10322         .tokens = {
10323                 (void *)&cmd_2tuple_filter_filter,
10324                 (void *)&cmd_2tuple_filter_port_id,
10325                 (void *)&cmd_2tuple_filter_ops,
10326                 (void *)&cmd_2tuple_filter_dst_port,
10327                 (void *)&cmd_2tuple_filter_dst_port_value,
10328                 (void *)&cmd_2tuple_filter_protocol,
10329                 (void *)&cmd_2tuple_filter_protocol_value,
10330                 (void *)&cmd_2tuple_filter_mask,
10331                 (void *)&cmd_2tuple_filter_mask_value,
10332                 (void *)&cmd_2tuple_filter_tcp_flags,
10333                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10334                 (void *)&cmd_2tuple_filter_priority,
10335                 (void *)&cmd_2tuple_filter_priority_value,
10336                 (void *)&cmd_2tuple_filter_queue,
10337                 (void *)&cmd_2tuple_filter_queue_id,
10338                 NULL,
10339         },
10340 };
10341
10342 /* *** ADD/REMOVE A 5tuple FILTER *** */
10343 struct cmd_5tuple_filter_result {
10344         cmdline_fixed_string_t filter;
10345         portid_t port_id;
10346         cmdline_fixed_string_t ops;
10347         cmdline_fixed_string_t dst_ip;
10348         cmdline_ipaddr_t dst_ip_value;
10349         cmdline_fixed_string_t src_ip;
10350         cmdline_ipaddr_t src_ip_value;
10351         cmdline_fixed_string_t dst_port;
10352         uint16_t dst_port_value;
10353         cmdline_fixed_string_t src_port;
10354         uint16_t src_port_value;
10355         cmdline_fixed_string_t protocol;
10356         uint8_t protocol_value;
10357         cmdline_fixed_string_t mask;
10358         uint8_t  mask_value;
10359         cmdline_fixed_string_t tcp_flags;
10360         uint8_t tcp_flags_value;
10361         cmdline_fixed_string_t priority;
10362         uint8_t  priority_value;
10363         cmdline_fixed_string_t queue;
10364         uint16_t  queue_id;
10365 };
10366
10367 static void
10368 cmd_5tuple_filter_parsed(void *parsed_result,
10369                         __attribute__((unused)) struct cmdline *cl,
10370                         __attribute__((unused)) void *data)
10371 {
10372         struct rte_eth_ntuple_filter filter;
10373         struct cmd_5tuple_filter_result *res = parsed_result;
10374         int ret = 0;
10375
10376         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10377         if (ret < 0) {
10378                 printf("ntuple filter is not supported on port %u.\n",
10379                         res->port_id);
10380                 return;
10381         }
10382
10383         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10384
10385         filter.flags = RTE_5TUPLE_FLAGS;
10386         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10387         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10388         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10389         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10390         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10391         filter.proto = res->protocol_value;
10392         filter.priority = res->priority_value;
10393         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10394                 printf("nonzero tcp_flags is only meaningful"
10395                         " when protocol is TCP.\n");
10396                 return;
10397         }
10398         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10399                 printf("invalid TCP flags.\n");
10400                 return;
10401         }
10402
10403         if (res->tcp_flags_value != 0) {
10404                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10405                 filter.tcp_flags = res->tcp_flags_value;
10406         }
10407
10408         if (res->dst_ip_value.family == AF_INET)
10409                 /* no need to convert, already big endian. */
10410                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10411         else {
10412                 if (filter.dst_ip_mask == 0) {
10413                         printf("can not support ipv6 involved compare.\n");
10414                         return;
10415                 }
10416                 filter.dst_ip = 0;
10417         }
10418
10419         if (res->src_ip_value.family == AF_INET)
10420                 /* no need to convert, already big endian. */
10421                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10422         else {
10423                 if (filter.src_ip_mask == 0) {
10424                         printf("can not support ipv6 involved compare.\n");
10425                         return;
10426                 }
10427                 filter.src_ip = 0;
10428         }
10429         /* need convert to big endian. */
10430         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10431         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10432         filter.queue = res->queue_id;
10433
10434         if (!strcmp(res->ops, "add"))
10435                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10436                                 RTE_ETH_FILTER_NTUPLE,
10437                                 RTE_ETH_FILTER_ADD,
10438                                 &filter);
10439         else
10440                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10441                                 RTE_ETH_FILTER_NTUPLE,
10442                                 RTE_ETH_FILTER_DELETE,
10443                                 &filter);
10444         if (ret < 0)
10445                 printf("5tuple filter programming error: (%s)\n",
10446                         strerror(-ret));
10447 }
10448
10449 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10450         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10451                                  filter, "5tuple_filter");
10452 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10453         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10454                                 port_id, UINT16);
10455 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10456         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10457                                  ops, "add#del");
10458 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10459         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10460                                 dst_ip, "dst_ip");
10461 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10462         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10463                                 dst_ip_value);
10464 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10465         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10466                                 src_ip, "src_ip");
10467 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10468         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10469                                 src_ip_value);
10470 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10471         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10472                                 dst_port, "dst_port");
10473 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10474         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10475                                 dst_port_value, UINT16);
10476 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10477         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10478                                 src_port, "src_port");
10479 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10480         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10481                                 src_port_value, UINT16);
10482 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10483         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10484                                 protocol, "protocol");
10485 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10486         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10487                                 protocol_value, UINT8);
10488 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10489         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10490                                 mask, "mask");
10491 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10492         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10493                                 mask_value, INT8);
10494 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10495         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10496                                 tcp_flags, "tcp_flags");
10497 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10498         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10499                                 tcp_flags_value, UINT8);
10500 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10501         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10502                                 priority, "priority");
10503 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10504         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10505                                 priority_value, UINT8);
10506 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10507         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10508                                 queue, "queue");
10509 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10510         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10511                                 queue_id, UINT16);
10512
10513 cmdline_parse_inst_t cmd_5tuple_filter = {
10514         .f = cmd_5tuple_filter_parsed,
10515         .data = NULL,
10516         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10517                 "src_ip <value> dst_port <value> src_port <value> "
10518                 "protocol <value>  mask <value> tcp_flags <value> "
10519                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10520         .tokens = {
10521                 (void *)&cmd_5tuple_filter_filter,
10522                 (void *)&cmd_5tuple_filter_port_id,
10523                 (void *)&cmd_5tuple_filter_ops,
10524                 (void *)&cmd_5tuple_filter_dst_ip,
10525                 (void *)&cmd_5tuple_filter_dst_ip_value,
10526                 (void *)&cmd_5tuple_filter_src_ip,
10527                 (void *)&cmd_5tuple_filter_src_ip_value,
10528                 (void *)&cmd_5tuple_filter_dst_port,
10529                 (void *)&cmd_5tuple_filter_dst_port_value,
10530                 (void *)&cmd_5tuple_filter_src_port,
10531                 (void *)&cmd_5tuple_filter_src_port_value,
10532                 (void *)&cmd_5tuple_filter_protocol,
10533                 (void *)&cmd_5tuple_filter_protocol_value,
10534                 (void *)&cmd_5tuple_filter_mask,
10535                 (void *)&cmd_5tuple_filter_mask_value,
10536                 (void *)&cmd_5tuple_filter_tcp_flags,
10537                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10538                 (void *)&cmd_5tuple_filter_priority,
10539                 (void *)&cmd_5tuple_filter_priority_value,
10540                 (void *)&cmd_5tuple_filter_queue,
10541                 (void *)&cmd_5tuple_filter_queue_id,
10542                 NULL,
10543         },
10544 };
10545
10546 /* *** ADD/REMOVE A flex FILTER *** */
10547 struct cmd_flex_filter_result {
10548         cmdline_fixed_string_t filter;
10549         cmdline_fixed_string_t ops;
10550         portid_t port_id;
10551         cmdline_fixed_string_t len;
10552         uint8_t len_value;
10553         cmdline_fixed_string_t bytes;
10554         cmdline_fixed_string_t bytes_value;
10555         cmdline_fixed_string_t mask;
10556         cmdline_fixed_string_t mask_value;
10557         cmdline_fixed_string_t priority;
10558         uint8_t priority_value;
10559         cmdline_fixed_string_t queue;
10560         uint16_t queue_id;
10561 };
10562
10563 static int xdigit2val(unsigned char c)
10564 {
10565         int val;
10566         if (isdigit(c))
10567                 val = c - '0';
10568         else if (isupper(c))
10569                 val = c - 'A' + 10;
10570         else
10571                 val = c - 'a' + 10;
10572         return val;
10573 }
10574
10575 static void
10576 cmd_flex_filter_parsed(void *parsed_result,
10577                           __attribute__((unused)) struct cmdline *cl,
10578                           __attribute__((unused)) void *data)
10579 {
10580         int ret = 0;
10581         struct rte_eth_flex_filter filter;
10582         struct cmd_flex_filter_result *res = parsed_result;
10583         char *bytes_ptr, *mask_ptr;
10584         uint16_t len, i, j = 0;
10585         char c;
10586         int val;
10587         uint8_t byte = 0;
10588
10589         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10590                 printf("the len exceed the max length 128\n");
10591                 return;
10592         }
10593         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10594         filter.len = res->len_value;
10595         filter.priority = res->priority_value;
10596         filter.queue = res->queue_id;
10597         bytes_ptr = res->bytes_value;
10598         mask_ptr = res->mask_value;
10599
10600          /* translate bytes string to array. */
10601         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10602                 (bytes_ptr[1] == 'X')))
10603                 bytes_ptr += 2;
10604         len = strnlen(bytes_ptr, res->len_value * 2);
10605         if (len == 0 || (len % 8 != 0)) {
10606                 printf("please check len and bytes input\n");
10607                 return;
10608         }
10609         for (i = 0; i < len; i++) {
10610                 c = bytes_ptr[i];
10611                 if (isxdigit(c) == 0) {
10612                         /* invalid characters. */
10613                         printf("invalid input\n");
10614                         return;
10615                 }
10616                 val = xdigit2val(c);
10617                 if (i % 2) {
10618                         byte |= val;
10619                         filter.bytes[j] = byte;
10620                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10621                         j++;
10622                         byte = 0;
10623                 } else
10624                         byte |= val << 4;
10625         }
10626         printf("\n");
10627          /* translate mask string to uint8_t array. */
10628         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10629                 (mask_ptr[1] == 'X')))
10630                 mask_ptr += 2;
10631         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10632         if (len == 0) {
10633                 printf("invalid input\n");
10634                 return;
10635         }
10636         j = 0;
10637         byte = 0;
10638         for (i = 0; i < len; i++) {
10639                 c = mask_ptr[i];
10640                 if (isxdigit(c) == 0) {
10641                         /* invalid characters. */
10642                         printf("invalid input\n");
10643                         return;
10644                 }
10645                 val = xdigit2val(c);
10646                 if (i % 2) {
10647                         byte |= val;
10648                         filter.mask[j] = byte;
10649                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10650                         j++;
10651                         byte = 0;
10652                 } else
10653                         byte |= val << 4;
10654         }
10655         printf("\n");
10656
10657         if (!strcmp(res->ops, "add"))
10658                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10659                                 RTE_ETH_FILTER_FLEXIBLE,
10660                                 RTE_ETH_FILTER_ADD,
10661                                 &filter);
10662         else
10663                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10664                                 RTE_ETH_FILTER_FLEXIBLE,
10665                                 RTE_ETH_FILTER_DELETE,
10666                                 &filter);
10667
10668         if (ret < 0)
10669                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10670 }
10671
10672 cmdline_parse_token_string_t cmd_flex_filter_filter =
10673         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10674                                 filter, "flex_filter");
10675 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10676         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10677                                 port_id, UINT16);
10678 cmdline_parse_token_string_t cmd_flex_filter_ops =
10679         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10680                                 ops, "add#del");
10681 cmdline_parse_token_string_t cmd_flex_filter_len =
10682         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10683                                 len, "len");
10684 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10685         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10686                                 len_value, UINT8);
10687 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10688         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10689                                 bytes, "bytes");
10690 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10691         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10692                                 bytes_value, NULL);
10693 cmdline_parse_token_string_t cmd_flex_filter_mask =
10694         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10695                                 mask, "mask");
10696 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10697         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10698                                 mask_value, NULL);
10699 cmdline_parse_token_string_t cmd_flex_filter_priority =
10700         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10701                                 priority, "priority");
10702 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10703         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10704                                 priority_value, UINT8);
10705 cmdline_parse_token_string_t cmd_flex_filter_queue =
10706         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10707                                 queue, "queue");
10708 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10709         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10710                                 queue_id, UINT16);
10711 cmdline_parse_inst_t cmd_flex_filter = {
10712         .f = cmd_flex_filter_parsed,
10713         .data = NULL,
10714         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10715                 "<value> mask <value> priority <value> queue <queue_id>: "
10716                 "Add/Del a flex filter",
10717         .tokens = {
10718                 (void *)&cmd_flex_filter_filter,
10719                 (void *)&cmd_flex_filter_port_id,
10720                 (void *)&cmd_flex_filter_ops,
10721                 (void *)&cmd_flex_filter_len,
10722                 (void *)&cmd_flex_filter_len_value,
10723                 (void *)&cmd_flex_filter_bytes,
10724                 (void *)&cmd_flex_filter_bytes_value,
10725                 (void *)&cmd_flex_filter_mask,
10726                 (void *)&cmd_flex_filter_mask_value,
10727                 (void *)&cmd_flex_filter_priority,
10728                 (void *)&cmd_flex_filter_priority_value,
10729                 (void *)&cmd_flex_filter_queue,
10730                 (void *)&cmd_flex_filter_queue_id,
10731                 NULL,
10732         },
10733 };
10734
10735 /* *** Filters Control *** */
10736
10737 /* *** deal with ethertype filter *** */
10738 struct cmd_ethertype_filter_result {
10739         cmdline_fixed_string_t filter;
10740         portid_t port_id;
10741         cmdline_fixed_string_t ops;
10742         cmdline_fixed_string_t mac;
10743         struct rte_ether_addr mac_addr;
10744         cmdline_fixed_string_t ethertype;
10745         uint16_t ethertype_value;
10746         cmdline_fixed_string_t drop;
10747         cmdline_fixed_string_t queue;
10748         uint16_t  queue_id;
10749 };
10750
10751 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10752         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10753                                  filter, "ethertype_filter");
10754 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10755         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10756                               port_id, UINT16);
10757 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10758         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10759                                  ops, "add#del");
10760 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10761         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10762                                  mac, "mac_addr#mac_ignr");
10763 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10764         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10765                                      mac_addr);
10766 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10767         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10768                                  ethertype, "ethertype");
10769 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10770         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10771                               ethertype_value, UINT16);
10772 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10773         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10774                                  drop, "drop#fwd");
10775 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10776         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10777                                  queue, "queue");
10778 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10779         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10780                               queue_id, UINT16);
10781
10782 static void
10783 cmd_ethertype_filter_parsed(void *parsed_result,
10784                           __attribute__((unused)) struct cmdline *cl,
10785                           __attribute__((unused)) void *data)
10786 {
10787         struct cmd_ethertype_filter_result *res = parsed_result;
10788         struct rte_eth_ethertype_filter filter;
10789         int ret = 0;
10790
10791         ret = rte_eth_dev_filter_supported(res->port_id,
10792                         RTE_ETH_FILTER_ETHERTYPE);
10793         if (ret < 0) {
10794                 printf("ethertype filter is not supported on port %u.\n",
10795                         res->port_id);
10796                 return;
10797         }
10798
10799         memset(&filter, 0, sizeof(filter));
10800         if (!strcmp(res->mac, "mac_addr")) {
10801                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10802                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10803                         sizeof(struct rte_ether_addr));
10804         }
10805         if (!strcmp(res->drop, "drop"))
10806                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10807         filter.ether_type = res->ethertype_value;
10808         filter.queue = res->queue_id;
10809
10810         if (!strcmp(res->ops, "add"))
10811                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10812                                 RTE_ETH_FILTER_ETHERTYPE,
10813                                 RTE_ETH_FILTER_ADD,
10814                                 &filter);
10815         else
10816                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10817                                 RTE_ETH_FILTER_ETHERTYPE,
10818                                 RTE_ETH_FILTER_DELETE,
10819                                 &filter);
10820         if (ret < 0)
10821                 printf("ethertype filter programming error: (%s)\n",
10822                         strerror(-ret));
10823 }
10824
10825 cmdline_parse_inst_t cmd_ethertype_filter = {
10826         .f = cmd_ethertype_filter_parsed,
10827         .data = NULL,
10828         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10829                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10830                 "Add or delete an ethertype filter entry",
10831         .tokens = {
10832                 (void *)&cmd_ethertype_filter_filter,
10833                 (void *)&cmd_ethertype_filter_port_id,
10834                 (void *)&cmd_ethertype_filter_ops,
10835                 (void *)&cmd_ethertype_filter_mac,
10836                 (void *)&cmd_ethertype_filter_mac_addr,
10837                 (void *)&cmd_ethertype_filter_ethertype,
10838                 (void *)&cmd_ethertype_filter_ethertype_value,
10839                 (void *)&cmd_ethertype_filter_drop,
10840                 (void *)&cmd_ethertype_filter_queue,
10841                 (void *)&cmd_ethertype_filter_queue_id,
10842                 NULL,
10843         },
10844 };
10845
10846 /* *** deal with flow director filter *** */
10847 struct cmd_flow_director_result {
10848         cmdline_fixed_string_t flow_director_filter;
10849         portid_t port_id;
10850         cmdline_fixed_string_t mode;
10851         cmdline_fixed_string_t mode_value;
10852         cmdline_fixed_string_t ops;
10853         cmdline_fixed_string_t flow;
10854         cmdline_fixed_string_t flow_type;
10855         cmdline_fixed_string_t ether;
10856         uint16_t ether_type;
10857         cmdline_fixed_string_t src;
10858         cmdline_ipaddr_t ip_src;
10859         uint16_t port_src;
10860         cmdline_fixed_string_t dst;
10861         cmdline_ipaddr_t ip_dst;
10862         uint16_t port_dst;
10863         cmdline_fixed_string_t verify_tag;
10864         uint32_t verify_tag_value;
10865         cmdline_fixed_string_t tos;
10866         uint8_t tos_value;
10867         cmdline_fixed_string_t proto;
10868         uint8_t proto_value;
10869         cmdline_fixed_string_t ttl;
10870         uint8_t ttl_value;
10871         cmdline_fixed_string_t vlan;
10872         uint16_t vlan_value;
10873         cmdline_fixed_string_t flexbytes;
10874         cmdline_fixed_string_t flexbytes_value;
10875         cmdline_fixed_string_t pf_vf;
10876         cmdline_fixed_string_t drop;
10877         cmdline_fixed_string_t queue;
10878         uint16_t  queue_id;
10879         cmdline_fixed_string_t fd_id;
10880         uint32_t  fd_id_value;
10881         cmdline_fixed_string_t mac;
10882         struct rte_ether_addr mac_addr;
10883         cmdline_fixed_string_t tunnel;
10884         cmdline_fixed_string_t tunnel_type;
10885         cmdline_fixed_string_t tunnel_id;
10886         uint32_t tunnel_id_value;
10887         cmdline_fixed_string_t packet;
10888         char filepath[];
10889 };
10890
10891 static inline int
10892 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10893 {
10894         char s[256];
10895         const char *p, *p0 = q_arg;
10896         char *end;
10897         unsigned long int_fld;
10898         char *str_fld[max_num];
10899         int i;
10900         unsigned size;
10901         int ret = -1;
10902
10903         p = strchr(p0, '(');
10904         if (p == NULL)
10905                 return -1;
10906         ++p;
10907         p0 = strchr(p, ')');
10908         if (p0 == NULL)
10909                 return -1;
10910
10911         size = p0 - p;
10912         if (size >= sizeof(s))
10913                 return -1;
10914
10915         snprintf(s, sizeof(s), "%.*s", size, p);
10916         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10917         if (ret < 0 || ret > max_num)
10918                 return -1;
10919         for (i = 0; i < ret; i++) {
10920                 errno = 0;
10921                 int_fld = strtoul(str_fld[i], &end, 0);
10922                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10923                         return -1;
10924                 flexbytes[i] = (uint8_t)int_fld;
10925         }
10926         return ret;
10927 }
10928
10929 static uint16_t
10930 str2flowtype(char *string)
10931 {
10932         uint8_t i = 0;
10933         static const struct {
10934                 char str[32];
10935                 uint16_t type;
10936         } flowtype_str[] = {
10937                 {"raw", RTE_ETH_FLOW_RAW},
10938                 {"ipv4", RTE_ETH_FLOW_IPV4},
10939                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10940                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10941                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10942                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10943                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10944                 {"ipv6", RTE_ETH_FLOW_IPV6},
10945                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10946                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10947                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10948                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10949                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10950                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10951         };
10952
10953         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10954                 if (!strcmp(flowtype_str[i].str, string))
10955                         return flowtype_str[i].type;
10956         }
10957
10958         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10959                 return (uint16_t)atoi(string);
10960
10961         return RTE_ETH_FLOW_UNKNOWN;
10962 }
10963
10964 static enum rte_eth_fdir_tunnel_type
10965 str2fdir_tunneltype(char *string)
10966 {
10967         uint8_t i = 0;
10968
10969         static const struct {
10970                 char str[32];
10971                 enum rte_eth_fdir_tunnel_type type;
10972         } tunneltype_str[] = {
10973                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10974                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10975         };
10976
10977         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10978                 if (!strcmp(tunneltype_str[i].str, string))
10979                         return tunneltype_str[i].type;
10980         }
10981         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10982 }
10983
10984 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10985 do { \
10986         if ((ip_addr).family == AF_INET) \
10987                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10988         else { \
10989                 printf("invalid parameter.\n"); \
10990                 return; \
10991         } \
10992 } while (0)
10993
10994 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10995 do { \
10996         if ((ip_addr).family == AF_INET6) \
10997                 rte_memcpy(&(ip), \
10998                                  &((ip_addr).addr.ipv6), \
10999                                  sizeof(struct in6_addr)); \
11000         else { \
11001                 printf("invalid parameter.\n"); \
11002                 return; \
11003         } \
11004 } while (0)
11005
11006 static void
11007 cmd_flow_director_filter_parsed(void *parsed_result,
11008                           __attribute__((unused)) struct cmdline *cl,
11009                           __attribute__((unused)) void *data)
11010 {
11011         struct cmd_flow_director_result *res = parsed_result;
11012         struct rte_eth_fdir_filter entry;
11013         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11014         char *end;
11015         unsigned long vf_id;
11016         int ret = 0;
11017
11018         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11019         if (ret < 0) {
11020                 printf("flow director is not supported on port %u.\n",
11021                         res->port_id);
11022                 return;
11023         }
11024         memset(flexbytes, 0, sizeof(flexbytes));
11025         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11026
11027         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11028                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11029                         printf("Please set mode to MAC-VLAN.\n");
11030                         return;
11031                 }
11032         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11033                 if (strcmp(res->mode_value, "Tunnel")) {
11034                         printf("Please set mode to Tunnel.\n");
11035                         return;
11036                 }
11037         } else {
11038                 if (!strcmp(res->mode_value, "raw")) {
11039 #ifdef RTE_LIBRTE_I40E_PMD
11040                         struct rte_pmd_i40e_flow_type_mapping
11041                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11042                         struct rte_pmd_i40e_pkt_template_conf conf;
11043                         uint16_t flow_type = str2flowtype(res->flow_type);
11044                         uint16_t i, port = res->port_id;
11045                         uint8_t add;
11046
11047                         memset(&conf, 0, sizeof(conf));
11048
11049                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11050                                 printf("Invalid flow type specified.\n");
11051                                 return;
11052                         }
11053                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11054                                                                  mapping);
11055                         if (ret)
11056                                 return;
11057                         if (mapping[flow_type].pctype == 0ULL) {
11058                                 printf("Invalid flow type specified.\n");
11059                                 return;
11060                         }
11061                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11062                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11063                                         conf.input.pctype = i;
11064                                         break;
11065                                 }
11066                         }
11067
11068                         conf.input.packet = open_file(res->filepath,
11069                                                 &conf.input.length);
11070                         if (!conf.input.packet)
11071                                 return;
11072                         if (!strcmp(res->drop, "drop"))
11073                                 conf.action.behavior =
11074                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11075                         else
11076                                 conf.action.behavior =
11077                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11078                         conf.action.report_status =
11079                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11080                         conf.action.rx_queue = res->queue_id;
11081                         conf.soft_id = res->fd_id_value;
11082                         add  = strcmp(res->ops, "del") ? 1 : 0;
11083                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11084                                                                         &conf,
11085                                                                         add);
11086                         if (ret < 0)
11087                                 printf("flow director config error: (%s)\n",
11088                                        strerror(-ret));
11089                         close_file(conf.input.packet);
11090 #endif
11091                         return;
11092                 } else if (strcmp(res->mode_value, "IP")) {
11093                         printf("Please set mode to IP or raw.\n");
11094                         return;
11095                 }
11096                 entry.input.flow_type = str2flowtype(res->flow_type);
11097         }
11098
11099         ret = parse_flexbytes(res->flexbytes_value,
11100                                         flexbytes,
11101                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11102         if (ret < 0) {
11103                 printf("error: Cannot parse flexbytes input.\n");
11104                 return;
11105         }
11106
11107         switch (entry.input.flow_type) {
11108         case RTE_ETH_FLOW_FRAG_IPV4:
11109         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11110                 entry.input.flow.ip4_flow.proto = res->proto_value;
11111                 /* fall-through */
11112         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11113         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11114                 IPV4_ADDR_TO_UINT(res->ip_dst,
11115                         entry.input.flow.ip4_flow.dst_ip);
11116                 IPV4_ADDR_TO_UINT(res->ip_src,
11117                         entry.input.flow.ip4_flow.src_ip);
11118                 entry.input.flow.ip4_flow.tos = res->tos_value;
11119                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11120                 /* need convert to big endian. */
11121                 entry.input.flow.udp4_flow.dst_port =
11122                                 rte_cpu_to_be_16(res->port_dst);
11123                 entry.input.flow.udp4_flow.src_port =
11124                                 rte_cpu_to_be_16(res->port_src);
11125                 break;
11126         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11127                 IPV4_ADDR_TO_UINT(res->ip_dst,
11128                         entry.input.flow.sctp4_flow.ip.dst_ip);
11129                 IPV4_ADDR_TO_UINT(res->ip_src,
11130                         entry.input.flow.sctp4_flow.ip.src_ip);
11131                 entry.input.flow.ip4_flow.tos = res->tos_value;
11132                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11133                 /* need convert to big endian. */
11134                 entry.input.flow.sctp4_flow.dst_port =
11135                                 rte_cpu_to_be_16(res->port_dst);
11136                 entry.input.flow.sctp4_flow.src_port =
11137                                 rte_cpu_to_be_16(res->port_src);
11138                 entry.input.flow.sctp4_flow.verify_tag =
11139                                 rte_cpu_to_be_32(res->verify_tag_value);
11140                 break;
11141         case RTE_ETH_FLOW_FRAG_IPV6:
11142         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11143                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11144                 /* fall-through */
11145         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11146         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11147                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11148                         entry.input.flow.ipv6_flow.dst_ip);
11149                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11150                         entry.input.flow.ipv6_flow.src_ip);
11151                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11152                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11153                 /* need convert to big endian. */
11154                 entry.input.flow.udp6_flow.dst_port =
11155                                 rte_cpu_to_be_16(res->port_dst);
11156                 entry.input.flow.udp6_flow.src_port =
11157                                 rte_cpu_to_be_16(res->port_src);
11158                 break;
11159         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11160                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11161                         entry.input.flow.sctp6_flow.ip.dst_ip);
11162                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11163                         entry.input.flow.sctp6_flow.ip.src_ip);
11164                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11165                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11166                 /* need convert to big endian. */
11167                 entry.input.flow.sctp6_flow.dst_port =
11168                                 rte_cpu_to_be_16(res->port_dst);
11169                 entry.input.flow.sctp6_flow.src_port =
11170                                 rte_cpu_to_be_16(res->port_src);
11171                 entry.input.flow.sctp6_flow.verify_tag =
11172                                 rte_cpu_to_be_32(res->verify_tag_value);
11173                 break;
11174         case RTE_ETH_FLOW_L2_PAYLOAD:
11175                 entry.input.flow.l2_flow.ether_type =
11176                         rte_cpu_to_be_16(res->ether_type);
11177                 break;
11178         default:
11179                 break;
11180         }
11181
11182         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11183                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11184                                  &res->mac_addr,
11185                                  sizeof(struct rte_ether_addr));
11186
11187         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11188                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11189                                  &res->mac_addr,
11190                                  sizeof(struct rte_ether_addr));
11191                 entry.input.flow.tunnel_flow.tunnel_type =
11192                         str2fdir_tunneltype(res->tunnel_type);
11193                 entry.input.flow.tunnel_flow.tunnel_id =
11194                         rte_cpu_to_be_32(res->tunnel_id_value);
11195         }
11196
11197         rte_memcpy(entry.input.flow_ext.flexbytes,
11198                    flexbytes,
11199                    RTE_ETH_FDIR_MAX_FLEXLEN);
11200
11201         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11202
11203         entry.action.flex_off = 0;  /*use 0 by default */
11204         if (!strcmp(res->drop, "drop"))
11205                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11206         else
11207                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11208
11209         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11210             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11211                 if (!strcmp(res->pf_vf, "pf"))
11212                         entry.input.flow_ext.is_vf = 0;
11213                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11214                         struct rte_eth_dev_info dev_info;
11215
11216                         ret = eth_dev_info_get_print_err(res->port_id,
11217                                                 &dev_info);
11218                         if (ret != 0)
11219                                 return;
11220
11221                         errno = 0;
11222                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11223                         if (errno != 0 || *end != '\0' ||
11224                             vf_id >= dev_info.max_vfs) {
11225                                 printf("invalid parameter %s.\n", res->pf_vf);
11226                                 return;
11227                         }
11228                         entry.input.flow_ext.is_vf = 1;
11229                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11230                 } else {
11231                         printf("invalid parameter %s.\n", res->pf_vf);
11232                         return;
11233                 }
11234         }
11235
11236         /* set to report FD ID by default */
11237         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11238         entry.action.rx_queue = res->queue_id;
11239         entry.soft_id = res->fd_id_value;
11240         if (!strcmp(res->ops, "add"))
11241                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11242                                              RTE_ETH_FILTER_ADD, &entry);
11243         else if (!strcmp(res->ops, "del"))
11244                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11245                                              RTE_ETH_FILTER_DELETE, &entry);
11246         else
11247                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11248                                              RTE_ETH_FILTER_UPDATE, &entry);
11249         if (ret < 0)
11250                 printf("flow director programming error: (%s)\n",
11251                         strerror(-ret));
11252 }
11253
11254 cmdline_parse_token_string_t cmd_flow_director_filter =
11255         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11256                                  flow_director_filter, "flow_director_filter");
11257 cmdline_parse_token_num_t cmd_flow_director_port_id =
11258         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11259                               port_id, UINT16);
11260 cmdline_parse_token_string_t cmd_flow_director_ops =
11261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11262                                  ops, "add#del#update");
11263 cmdline_parse_token_string_t cmd_flow_director_flow =
11264         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11265                                  flow, "flow");
11266 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11267         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11268                 flow_type, NULL);
11269 cmdline_parse_token_string_t cmd_flow_director_ether =
11270         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11271                                  ether, "ether");
11272 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11273         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11274                               ether_type, UINT16);
11275 cmdline_parse_token_string_t cmd_flow_director_src =
11276         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11277                                  src, "src");
11278 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11279         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11280                                  ip_src);
11281 cmdline_parse_token_num_t cmd_flow_director_port_src =
11282         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11283                               port_src, UINT16);
11284 cmdline_parse_token_string_t cmd_flow_director_dst =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11286                                  dst, "dst");
11287 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11288         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11289                                  ip_dst);
11290 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11291         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11292                               port_dst, UINT16);
11293 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11295                                   verify_tag, "verify_tag");
11296 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11297         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11298                               verify_tag_value, UINT32);
11299 cmdline_parse_token_string_t cmd_flow_director_tos =
11300         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11301                                  tos, "tos");
11302 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11303         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11304                               tos_value, UINT8);
11305 cmdline_parse_token_string_t cmd_flow_director_proto =
11306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11307                                  proto, "proto");
11308 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11309         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11310                               proto_value, UINT8);
11311 cmdline_parse_token_string_t cmd_flow_director_ttl =
11312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11313                                  ttl, "ttl");
11314 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11315         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11316                               ttl_value, UINT8);
11317 cmdline_parse_token_string_t cmd_flow_director_vlan =
11318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11319                                  vlan, "vlan");
11320 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11321         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11322                               vlan_value, UINT16);
11323 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11324         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11325                                  flexbytes, "flexbytes");
11326 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11328                               flexbytes_value, NULL);
11329 cmdline_parse_token_string_t cmd_flow_director_drop =
11330         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11331                                  drop, "drop#fwd");
11332 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11334                               pf_vf, NULL);
11335 cmdline_parse_token_string_t cmd_flow_director_queue =
11336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11337                                  queue, "queue");
11338 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11339         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11340                               queue_id, UINT16);
11341 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11343                                  fd_id, "fd_id");
11344 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11345         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11346                               fd_id_value, UINT32);
11347
11348 cmdline_parse_token_string_t cmd_flow_director_mode =
11349         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11350                                  mode, "mode");
11351 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11352         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11353                                  mode_value, "IP");
11354 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11355         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11356                                  mode_value, "MAC-VLAN");
11357 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11358         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11359                                  mode_value, "Tunnel");
11360 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11361         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11362                                  mode_value, "raw");
11363 cmdline_parse_token_string_t cmd_flow_director_mac =
11364         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11365                                  mac, "mac");
11366 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11367         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11368                                     mac_addr);
11369 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11370         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11371                                  tunnel, "tunnel");
11372 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11373         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11374                                  tunnel_type, "NVGRE#VxLAN");
11375 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11377                                  tunnel_id, "tunnel-id");
11378 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11379         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11380                               tunnel_id_value, UINT32);
11381 cmdline_parse_token_string_t cmd_flow_director_packet =
11382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11383                                  packet, "packet");
11384 cmdline_parse_token_string_t cmd_flow_director_filepath =
11385         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11386                                  filepath, NULL);
11387
11388 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11389         .f = cmd_flow_director_filter_parsed,
11390         .data = NULL,
11391         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11392                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11393                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11394                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11395                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11396                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11397                 "fd_id <fd_id_value>: "
11398                 "Add or delete an ip flow director entry on NIC",
11399         .tokens = {
11400                 (void *)&cmd_flow_director_filter,
11401                 (void *)&cmd_flow_director_port_id,
11402                 (void *)&cmd_flow_director_mode,
11403                 (void *)&cmd_flow_director_mode_ip,
11404                 (void *)&cmd_flow_director_ops,
11405                 (void *)&cmd_flow_director_flow,
11406                 (void *)&cmd_flow_director_flow_type,
11407                 (void *)&cmd_flow_director_src,
11408                 (void *)&cmd_flow_director_ip_src,
11409                 (void *)&cmd_flow_director_dst,
11410                 (void *)&cmd_flow_director_ip_dst,
11411                 (void *)&cmd_flow_director_tos,
11412                 (void *)&cmd_flow_director_tos_value,
11413                 (void *)&cmd_flow_director_proto,
11414                 (void *)&cmd_flow_director_proto_value,
11415                 (void *)&cmd_flow_director_ttl,
11416                 (void *)&cmd_flow_director_ttl_value,
11417                 (void *)&cmd_flow_director_vlan,
11418                 (void *)&cmd_flow_director_vlan_value,
11419                 (void *)&cmd_flow_director_flexbytes,
11420                 (void *)&cmd_flow_director_flexbytes_value,
11421                 (void *)&cmd_flow_director_drop,
11422                 (void *)&cmd_flow_director_pf_vf,
11423                 (void *)&cmd_flow_director_queue,
11424                 (void *)&cmd_flow_director_queue_id,
11425                 (void *)&cmd_flow_director_fd_id,
11426                 (void *)&cmd_flow_director_fd_id_value,
11427                 NULL,
11428         },
11429 };
11430
11431 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11432         .f = cmd_flow_director_filter_parsed,
11433         .data = NULL,
11434         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11435                 "director entry on NIC",
11436         .tokens = {
11437                 (void *)&cmd_flow_director_filter,
11438                 (void *)&cmd_flow_director_port_id,
11439                 (void *)&cmd_flow_director_mode,
11440                 (void *)&cmd_flow_director_mode_ip,
11441                 (void *)&cmd_flow_director_ops,
11442                 (void *)&cmd_flow_director_flow,
11443                 (void *)&cmd_flow_director_flow_type,
11444                 (void *)&cmd_flow_director_src,
11445                 (void *)&cmd_flow_director_ip_src,
11446                 (void *)&cmd_flow_director_port_src,
11447                 (void *)&cmd_flow_director_dst,
11448                 (void *)&cmd_flow_director_ip_dst,
11449                 (void *)&cmd_flow_director_port_dst,
11450                 (void *)&cmd_flow_director_tos,
11451                 (void *)&cmd_flow_director_tos_value,
11452                 (void *)&cmd_flow_director_ttl,
11453                 (void *)&cmd_flow_director_ttl_value,
11454                 (void *)&cmd_flow_director_vlan,
11455                 (void *)&cmd_flow_director_vlan_value,
11456                 (void *)&cmd_flow_director_flexbytes,
11457                 (void *)&cmd_flow_director_flexbytes_value,
11458                 (void *)&cmd_flow_director_drop,
11459                 (void *)&cmd_flow_director_pf_vf,
11460                 (void *)&cmd_flow_director_queue,
11461                 (void *)&cmd_flow_director_queue_id,
11462                 (void *)&cmd_flow_director_fd_id,
11463                 (void *)&cmd_flow_director_fd_id_value,
11464                 NULL,
11465         },
11466 };
11467
11468 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11469         .f = cmd_flow_director_filter_parsed,
11470         .data = NULL,
11471         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11472                 "director entry on NIC",
11473         .tokens = {
11474                 (void *)&cmd_flow_director_filter,
11475                 (void *)&cmd_flow_director_port_id,
11476                 (void *)&cmd_flow_director_mode,
11477                 (void *)&cmd_flow_director_mode_ip,
11478                 (void *)&cmd_flow_director_ops,
11479                 (void *)&cmd_flow_director_flow,
11480                 (void *)&cmd_flow_director_flow_type,
11481                 (void *)&cmd_flow_director_src,
11482                 (void *)&cmd_flow_director_ip_src,
11483                 (void *)&cmd_flow_director_port_src,
11484                 (void *)&cmd_flow_director_dst,
11485                 (void *)&cmd_flow_director_ip_dst,
11486                 (void *)&cmd_flow_director_port_dst,
11487                 (void *)&cmd_flow_director_verify_tag,
11488                 (void *)&cmd_flow_director_verify_tag_value,
11489                 (void *)&cmd_flow_director_tos,
11490                 (void *)&cmd_flow_director_tos_value,
11491                 (void *)&cmd_flow_director_ttl,
11492                 (void *)&cmd_flow_director_ttl_value,
11493                 (void *)&cmd_flow_director_vlan,
11494                 (void *)&cmd_flow_director_vlan_value,
11495                 (void *)&cmd_flow_director_flexbytes,
11496                 (void *)&cmd_flow_director_flexbytes_value,
11497                 (void *)&cmd_flow_director_drop,
11498                 (void *)&cmd_flow_director_pf_vf,
11499                 (void *)&cmd_flow_director_queue,
11500                 (void *)&cmd_flow_director_queue_id,
11501                 (void *)&cmd_flow_director_fd_id,
11502                 (void *)&cmd_flow_director_fd_id_value,
11503                 NULL,
11504         },
11505 };
11506
11507 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11508         .f = cmd_flow_director_filter_parsed,
11509         .data = NULL,
11510         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11511                 "director entry on NIC",
11512         .tokens = {
11513                 (void *)&cmd_flow_director_filter,
11514                 (void *)&cmd_flow_director_port_id,
11515                 (void *)&cmd_flow_director_mode,
11516                 (void *)&cmd_flow_director_mode_ip,
11517                 (void *)&cmd_flow_director_ops,
11518                 (void *)&cmd_flow_director_flow,
11519                 (void *)&cmd_flow_director_flow_type,
11520                 (void *)&cmd_flow_director_ether,
11521                 (void *)&cmd_flow_director_ether_type,
11522                 (void *)&cmd_flow_director_flexbytes,
11523                 (void *)&cmd_flow_director_flexbytes_value,
11524                 (void *)&cmd_flow_director_drop,
11525                 (void *)&cmd_flow_director_pf_vf,
11526                 (void *)&cmd_flow_director_queue,
11527                 (void *)&cmd_flow_director_queue_id,
11528                 (void *)&cmd_flow_director_fd_id,
11529                 (void *)&cmd_flow_director_fd_id_value,
11530                 NULL,
11531         },
11532 };
11533
11534 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11535         .f = cmd_flow_director_filter_parsed,
11536         .data = NULL,
11537         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11538                 "director entry on NIC",
11539         .tokens = {
11540                 (void *)&cmd_flow_director_filter,
11541                 (void *)&cmd_flow_director_port_id,
11542                 (void *)&cmd_flow_director_mode,
11543                 (void *)&cmd_flow_director_mode_mac_vlan,
11544                 (void *)&cmd_flow_director_ops,
11545                 (void *)&cmd_flow_director_mac,
11546                 (void *)&cmd_flow_director_mac_addr,
11547                 (void *)&cmd_flow_director_vlan,
11548                 (void *)&cmd_flow_director_vlan_value,
11549                 (void *)&cmd_flow_director_flexbytes,
11550                 (void *)&cmd_flow_director_flexbytes_value,
11551                 (void *)&cmd_flow_director_drop,
11552                 (void *)&cmd_flow_director_queue,
11553                 (void *)&cmd_flow_director_queue_id,
11554                 (void *)&cmd_flow_director_fd_id,
11555                 (void *)&cmd_flow_director_fd_id_value,
11556                 NULL,
11557         },
11558 };
11559
11560 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11561         .f = cmd_flow_director_filter_parsed,
11562         .data = NULL,
11563         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11564                 "director entry on NIC",
11565         .tokens = {
11566                 (void *)&cmd_flow_director_filter,
11567                 (void *)&cmd_flow_director_port_id,
11568                 (void *)&cmd_flow_director_mode,
11569                 (void *)&cmd_flow_director_mode_tunnel,
11570                 (void *)&cmd_flow_director_ops,
11571                 (void *)&cmd_flow_director_mac,
11572                 (void *)&cmd_flow_director_mac_addr,
11573                 (void *)&cmd_flow_director_vlan,
11574                 (void *)&cmd_flow_director_vlan_value,
11575                 (void *)&cmd_flow_director_tunnel,
11576                 (void *)&cmd_flow_director_tunnel_type,
11577                 (void *)&cmd_flow_director_tunnel_id,
11578                 (void *)&cmd_flow_director_tunnel_id_value,
11579                 (void *)&cmd_flow_director_flexbytes,
11580                 (void *)&cmd_flow_director_flexbytes_value,
11581                 (void *)&cmd_flow_director_drop,
11582                 (void *)&cmd_flow_director_queue,
11583                 (void *)&cmd_flow_director_queue_id,
11584                 (void *)&cmd_flow_director_fd_id,
11585                 (void *)&cmd_flow_director_fd_id_value,
11586                 NULL,
11587         },
11588 };
11589
11590 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11591         .f = cmd_flow_director_filter_parsed,
11592         .data = NULL,
11593         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11594                 "director entry on NIC",
11595         .tokens = {
11596                 (void *)&cmd_flow_director_filter,
11597                 (void *)&cmd_flow_director_port_id,
11598                 (void *)&cmd_flow_director_mode,
11599                 (void *)&cmd_flow_director_mode_raw,
11600                 (void *)&cmd_flow_director_ops,
11601                 (void *)&cmd_flow_director_flow,
11602                 (void *)&cmd_flow_director_flow_type,
11603                 (void *)&cmd_flow_director_drop,
11604                 (void *)&cmd_flow_director_queue,
11605                 (void *)&cmd_flow_director_queue_id,
11606                 (void *)&cmd_flow_director_fd_id,
11607                 (void *)&cmd_flow_director_fd_id_value,
11608                 (void *)&cmd_flow_director_packet,
11609                 (void *)&cmd_flow_director_filepath,
11610                 NULL,
11611         },
11612 };
11613
11614 struct cmd_flush_flow_director_result {
11615         cmdline_fixed_string_t flush_flow_director;
11616         portid_t port_id;
11617 };
11618
11619 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11620         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11621                                  flush_flow_director, "flush_flow_director");
11622 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11623         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11624                               port_id, UINT16);
11625
11626 static void
11627 cmd_flush_flow_director_parsed(void *parsed_result,
11628                           __attribute__((unused)) struct cmdline *cl,
11629                           __attribute__((unused)) void *data)
11630 {
11631         struct cmd_flow_director_result *res = parsed_result;
11632         int ret = 0;
11633
11634         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11635         if (ret < 0) {
11636                 printf("flow director is not supported on port %u.\n",
11637                         res->port_id);
11638                 return;
11639         }
11640
11641         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11642                         RTE_ETH_FILTER_FLUSH, NULL);
11643         if (ret < 0)
11644                 printf("flow director table flushing error: (%s)\n",
11645                         strerror(-ret));
11646 }
11647
11648 cmdline_parse_inst_t cmd_flush_flow_director = {
11649         .f = cmd_flush_flow_director_parsed,
11650         .data = NULL,
11651         .help_str = "flush_flow_director <port_id>: "
11652                 "Flush all flow director entries of a device on NIC",
11653         .tokens = {
11654                 (void *)&cmd_flush_flow_director_flush,
11655                 (void *)&cmd_flush_flow_director_port_id,
11656                 NULL,
11657         },
11658 };
11659
11660 /* *** deal with flow director mask *** */
11661 struct cmd_flow_director_mask_result {
11662         cmdline_fixed_string_t flow_director_mask;
11663         portid_t port_id;
11664         cmdline_fixed_string_t mode;
11665         cmdline_fixed_string_t mode_value;
11666         cmdline_fixed_string_t vlan;
11667         uint16_t vlan_mask;
11668         cmdline_fixed_string_t src_mask;
11669         cmdline_ipaddr_t ipv4_src;
11670         cmdline_ipaddr_t ipv6_src;
11671         uint16_t port_src;
11672         cmdline_fixed_string_t dst_mask;
11673         cmdline_ipaddr_t ipv4_dst;
11674         cmdline_ipaddr_t ipv6_dst;
11675         uint16_t port_dst;
11676         cmdline_fixed_string_t mac;
11677         uint8_t mac_addr_byte_mask;
11678         cmdline_fixed_string_t tunnel_id;
11679         uint32_t tunnel_id_mask;
11680         cmdline_fixed_string_t tunnel_type;
11681         uint8_t tunnel_type_mask;
11682 };
11683
11684 static void
11685 cmd_flow_director_mask_parsed(void *parsed_result,
11686                           __attribute__((unused)) struct cmdline *cl,
11687                           __attribute__((unused)) void *data)
11688 {
11689         struct cmd_flow_director_mask_result *res = parsed_result;
11690         struct rte_eth_fdir_masks *mask;
11691         struct rte_port *port;
11692
11693         port = &ports[res->port_id];
11694         /** Check if the port is not started **/
11695         if (port->port_status != RTE_PORT_STOPPED) {
11696                 printf("Please stop port %d first\n", res->port_id);
11697                 return;
11698         }
11699
11700         mask = &port->dev_conf.fdir_conf.mask;
11701
11702         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11703                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11704                         printf("Please set mode to MAC-VLAN.\n");
11705                         return;
11706                 }
11707
11708                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11709         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11710                 if (strcmp(res->mode_value, "Tunnel")) {
11711                         printf("Please set mode to Tunnel.\n");
11712                         return;
11713                 }
11714
11715                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11716                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11717                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11718                 mask->tunnel_type_mask = res->tunnel_type_mask;
11719         } else {
11720                 if (strcmp(res->mode_value, "IP")) {
11721                         printf("Please set mode to IP.\n");
11722                         return;
11723                 }
11724
11725                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11726                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11727                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11728                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11729                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11730                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11731                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11732         }
11733
11734         cmd_reconfig_device_queue(res->port_id, 1, 1);
11735 }
11736
11737 cmdline_parse_token_string_t cmd_flow_director_mask =
11738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11739                                  flow_director_mask, "flow_director_mask");
11740 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11741         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11742                               port_id, UINT16);
11743 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11744         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11745                                  vlan, "vlan");
11746 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11747         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11748                               vlan_mask, UINT16);
11749 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11751                                  src_mask, "src_mask");
11752 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11753         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11754                                  ipv4_src);
11755 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11756         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11757                                  ipv6_src);
11758 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11759         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11760                               port_src, UINT16);
11761 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11763                                  dst_mask, "dst_mask");
11764 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11765         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11766                                  ipv4_dst);
11767 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11768         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11769                                  ipv6_dst);
11770 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11771         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11772                               port_dst, UINT16);
11773
11774 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11776                                  mode, "mode");
11777 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11779                                  mode_value, "IP");
11780 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11781         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11782                                  mode_value, "MAC-VLAN");
11783 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11784         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11785                                  mode_value, "Tunnel");
11786 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11787         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11788                                  mac, "mac");
11789 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11790         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11791                               mac_addr_byte_mask, UINT8);
11792 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11794                                  tunnel_type, "tunnel-type");
11795 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11796         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11797                               tunnel_type_mask, UINT8);
11798 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11800                                  tunnel_id, "tunnel-id");
11801 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11802         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11803                               tunnel_id_mask, UINT32);
11804
11805 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11806         .f = cmd_flow_director_mask_parsed,
11807         .data = NULL,
11808         .help_str = "flow_director_mask ... : "
11809                 "Set IP mode flow director's mask on NIC",
11810         .tokens = {
11811                 (void *)&cmd_flow_director_mask,
11812                 (void *)&cmd_flow_director_mask_port_id,
11813                 (void *)&cmd_flow_director_mask_mode,
11814                 (void *)&cmd_flow_director_mask_mode_ip,
11815                 (void *)&cmd_flow_director_mask_vlan,
11816                 (void *)&cmd_flow_director_mask_vlan_value,
11817                 (void *)&cmd_flow_director_mask_src,
11818                 (void *)&cmd_flow_director_mask_ipv4_src,
11819                 (void *)&cmd_flow_director_mask_ipv6_src,
11820                 (void *)&cmd_flow_director_mask_port_src,
11821                 (void *)&cmd_flow_director_mask_dst,
11822                 (void *)&cmd_flow_director_mask_ipv4_dst,
11823                 (void *)&cmd_flow_director_mask_ipv6_dst,
11824                 (void *)&cmd_flow_director_mask_port_dst,
11825                 NULL,
11826         },
11827 };
11828
11829 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11830         .f = cmd_flow_director_mask_parsed,
11831         .data = NULL,
11832         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11833                 "flow director's mask on NIC",
11834         .tokens = {
11835                 (void *)&cmd_flow_director_mask,
11836                 (void *)&cmd_flow_director_mask_port_id,
11837                 (void *)&cmd_flow_director_mask_mode,
11838                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11839                 (void *)&cmd_flow_director_mask_vlan,
11840                 (void *)&cmd_flow_director_mask_vlan_value,
11841                 NULL,
11842         },
11843 };
11844
11845 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11846         .f = cmd_flow_director_mask_parsed,
11847         .data = NULL,
11848         .help_str = "flow_director_mask ... : Set tunnel mode "
11849                 "flow director's mask on NIC",
11850         .tokens = {
11851                 (void *)&cmd_flow_director_mask,
11852                 (void *)&cmd_flow_director_mask_port_id,
11853                 (void *)&cmd_flow_director_mask_mode,
11854                 (void *)&cmd_flow_director_mask_mode_tunnel,
11855                 (void *)&cmd_flow_director_mask_vlan,
11856                 (void *)&cmd_flow_director_mask_vlan_value,
11857                 (void *)&cmd_flow_director_mask_mac,
11858                 (void *)&cmd_flow_director_mask_mac_value,
11859                 (void *)&cmd_flow_director_mask_tunnel_type,
11860                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11861                 (void *)&cmd_flow_director_mask_tunnel_id,
11862                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11863                 NULL,
11864         },
11865 };
11866
11867 /* *** deal with flow director mask on flexible payload *** */
11868 struct cmd_flow_director_flex_mask_result {
11869         cmdline_fixed_string_t flow_director_flexmask;
11870         portid_t port_id;
11871         cmdline_fixed_string_t flow;
11872         cmdline_fixed_string_t flow_type;
11873         cmdline_fixed_string_t mask;
11874 };
11875
11876 static void
11877 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11878                           __attribute__((unused)) struct cmdline *cl,
11879                           __attribute__((unused)) void *data)
11880 {
11881         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11882         struct rte_eth_fdir_info fdir_info;
11883         struct rte_eth_fdir_flex_mask flex_mask;
11884         struct rte_port *port;
11885         uint64_t flow_type_mask;
11886         uint16_t i;
11887         int ret;
11888
11889         port = &ports[res->port_id];
11890         /** Check if the port is not started **/
11891         if (port->port_status != RTE_PORT_STOPPED) {
11892                 printf("Please stop port %d first\n", res->port_id);
11893                 return;
11894         }
11895
11896         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11897         ret = parse_flexbytes(res->mask,
11898                         flex_mask.mask,
11899                         RTE_ETH_FDIR_MAX_FLEXLEN);
11900         if (ret < 0) {
11901                 printf("error: Cannot parse mask input.\n");
11902                 return;
11903         }
11904
11905         memset(&fdir_info, 0, sizeof(fdir_info));
11906         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11907                                 RTE_ETH_FILTER_INFO, &fdir_info);
11908         if (ret < 0) {
11909                 printf("Cannot get FDir filter info\n");
11910                 return;
11911         }
11912
11913         if (!strcmp(res->flow_type, "none")) {
11914                 /* means don't specify the flow type */
11915                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11916                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11917                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11918                                0, sizeof(struct rte_eth_fdir_flex_mask));
11919                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11920                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11921                                  &flex_mask,
11922                                  sizeof(struct rte_eth_fdir_flex_mask));
11923                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11924                 return;
11925         }
11926         flow_type_mask = fdir_info.flow_types_mask[0];
11927         if (!strcmp(res->flow_type, "all")) {
11928                 if (!flow_type_mask) {
11929                         printf("No flow type supported\n");
11930                         return;
11931                 }
11932                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11933                         if (flow_type_mask & (1ULL << i)) {
11934                                 flex_mask.flow_type = i;
11935                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11936                         }
11937                 }
11938                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11939                 return;
11940         }
11941         flex_mask.flow_type = str2flowtype(res->flow_type);
11942         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11943                 printf("Flow type %s not supported on port %d\n",
11944                                 res->flow_type, res->port_id);
11945                 return;
11946         }
11947         fdir_set_flex_mask(res->port_id, &flex_mask);
11948         cmd_reconfig_device_queue(res->port_id, 1, 1);
11949 }
11950
11951 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11952         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11953                                  flow_director_flexmask,
11954                                  "flow_director_flex_mask");
11955 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11956         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11957                               port_id, UINT16);
11958 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11960                                  flow, "flow");
11961 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11962         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11963                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11964                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11965 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11966         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11967                                  mask, NULL);
11968
11969 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11970         .f = cmd_flow_director_flex_mask_parsed,
11971         .data = NULL,
11972         .help_str = "flow_director_flex_mask ... : "
11973                 "Set flow director's flex mask on NIC",
11974         .tokens = {
11975                 (void *)&cmd_flow_director_flexmask,
11976                 (void *)&cmd_flow_director_flexmask_port_id,
11977                 (void *)&cmd_flow_director_flexmask_flow,
11978                 (void *)&cmd_flow_director_flexmask_flow_type,
11979                 (void *)&cmd_flow_director_flexmask_mask,
11980                 NULL,
11981         },
11982 };
11983
11984 /* *** deal with flow director flexible payload configuration *** */
11985 struct cmd_flow_director_flexpayload_result {
11986         cmdline_fixed_string_t flow_director_flexpayload;
11987         portid_t port_id;
11988         cmdline_fixed_string_t payload_layer;
11989         cmdline_fixed_string_t payload_cfg;
11990 };
11991
11992 static inline int
11993 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11994 {
11995         char s[256];
11996         const char *p, *p0 = q_arg;
11997         char *end;
11998         unsigned long int_fld;
11999         char *str_fld[max_num];
12000         int i;
12001         unsigned size;
12002         int ret = -1;
12003
12004         p = strchr(p0, '(');
12005         if (p == NULL)
12006                 return -1;
12007         ++p;
12008         p0 = strchr(p, ')');
12009         if (p0 == NULL)
12010                 return -1;
12011
12012         size = p0 - p;
12013         if (size >= sizeof(s))
12014                 return -1;
12015
12016         snprintf(s, sizeof(s), "%.*s", size, p);
12017         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12018         if (ret < 0 || ret > max_num)
12019                 return -1;
12020         for (i = 0; i < ret; i++) {
12021                 errno = 0;
12022                 int_fld = strtoul(str_fld[i], &end, 0);
12023                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12024                         return -1;
12025                 offsets[i] = (uint16_t)int_fld;
12026         }
12027         return ret;
12028 }
12029
12030 static void
12031 cmd_flow_director_flxpld_parsed(void *parsed_result,
12032                           __attribute__((unused)) struct cmdline *cl,
12033                           __attribute__((unused)) void *data)
12034 {
12035         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12036         struct rte_eth_flex_payload_cfg flex_cfg;
12037         struct rte_port *port;
12038         int ret = 0;
12039
12040         port = &ports[res->port_id];
12041         /** Check if the port is not started **/
12042         if (port->port_status != RTE_PORT_STOPPED) {
12043                 printf("Please stop port %d first\n", res->port_id);
12044                 return;
12045         }
12046
12047         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12048
12049         if (!strcmp(res->payload_layer, "raw"))
12050                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12051         else if (!strcmp(res->payload_layer, "l2"))
12052                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12053         else if (!strcmp(res->payload_layer, "l3"))
12054                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12055         else if (!strcmp(res->payload_layer, "l4"))
12056                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12057
12058         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12059                             RTE_ETH_FDIR_MAX_FLEXLEN);
12060         if (ret < 0) {
12061                 printf("error: Cannot parse flex payload input.\n");
12062                 return;
12063         }
12064
12065         fdir_set_flex_payload(res->port_id, &flex_cfg);
12066         cmd_reconfig_device_queue(res->port_id, 1, 1);
12067 }
12068
12069 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12070         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12071                                  flow_director_flexpayload,
12072                                  "flow_director_flex_payload");
12073 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12074         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12075                               port_id, UINT16);
12076 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12077         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12078                                  payload_layer, "raw#l2#l3#l4");
12079 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12081                                  payload_cfg, NULL);
12082
12083 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12084         .f = cmd_flow_director_flxpld_parsed,
12085         .data = NULL,
12086         .help_str = "flow_director_flexpayload ... : "
12087                 "Set flow director's flex payload on NIC",
12088         .tokens = {
12089                 (void *)&cmd_flow_director_flexpayload,
12090                 (void *)&cmd_flow_director_flexpayload_port_id,
12091                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12092                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12093                 NULL,
12094         },
12095 };
12096
12097 /* Generic flow interface command. */
12098 extern cmdline_parse_inst_t cmd_flow;
12099
12100 /* *** Classification Filters Control *** */
12101 /* *** Get symmetric hash enable per port *** */
12102 struct cmd_get_sym_hash_ena_per_port_result {
12103         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12104         portid_t port_id;
12105 };
12106
12107 static void
12108 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12109                                  __rte_unused struct cmdline *cl,
12110                                  __rte_unused void *data)
12111 {
12112         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12113         struct rte_eth_hash_filter_info info;
12114         int ret;
12115
12116         if (rte_eth_dev_filter_supported(res->port_id,
12117                                 RTE_ETH_FILTER_HASH) < 0) {
12118                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12119                                                         res->port_id);
12120                 return;
12121         }
12122
12123         memset(&info, 0, sizeof(info));
12124         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12125         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12126                                                 RTE_ETH_FILTER_GET, &info);
12127
12128         if (ret < 0) {
12129                 printf("Cannot get symmetric hash enable per port "
12130                                         "on port %u\n", res->port_id);
12131                 return;
12132         }
12133
12134         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12135                                 "enabled" : "disabled", res->port_id);
12136 }
12137
12138 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12139         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12140                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12141 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12142         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12143                 port_id, UINT16);
12144
12145 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12146         .f = cmd_get_sym_hash_per_port_parsed,
12147         .data = NULL,
12148         .help_str = "get_sym_hash_ena_per_port <port_id>",
12149         .tokens = {
12150                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12151                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12152                 NULL,
12153         },
12154 };
12155
12156 /* *** Set symmetric hash enable per port *** */
12157 struct cmd_set_sym_hash_ena_per_port_result {
12158         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12159         cmdline_fixed_string_t enable;
12160         portid_t port_id;
12161 };
12162
12163 static void
12164 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12165                                  __rte_unused struct cmdline *cl,
12166                                  __rte_unused void *data)
12167 {
12168         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12169         struct rte_eth_hash_filter_info info;
12170         int ret;
12171
12172         if (rte_eth_dev_filter_supported(res->port_id,
12173                                 RTE_ETH_FILTER_HASH) < 0) {
12174                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12175                                                         res->port_id);
12176                 return;
12177         }
12178
12179         memset(&info, 0, sizeof(info));
12180         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12181         if (!strcmp(res->enable, "enable"))
12182                 info.info.enable = 1;
12183         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12184                                         RTE_ETH_FILTER_SET, &info);
12185         if (ret < 0) {
12186                 printf("Cannot set symmetric hash enable per port on "
12187                                         "port %u\n", res->port_id);
12188                 return;
12189         }
12190         printf("Symmetric hash has been set to %s on port %u\n",
12191                                         res->enable, res->port_id);
12192 }
12193
12194 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12195         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12196                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12197 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12198         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12199                 port_id, UINT16);
12200 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12201         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12202                 enable, "enable#disable");
12203
12204 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12205         .f = cmd_set_sym_hash_per_port_parsed,
12206         .data = NULL,
12207         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12208         .tokens = {
12209                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12210                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12211                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12212                 NULL,
12213         },
12214 };
12215
12216 /* Get global config of hash function */
12217 struct cmd_get_hash_global_config_result {
12218         cmdline_fixed_string_t get_hash_global_config;
12219         portid_t port_id;
12220 };
12221
12222 static char *
12223 flowtype_to_str(uint16_t ftype)
12224 {
12225         uint16_t i;
12226         static struct {
12227                 char str[16];
12228                 uint16_t ftype;
12229         } ftype_table[] = {
12230                 {"ipv4", RTE_ETH_FLOW_IPV4},
12231                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12232                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12233                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12234                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12235                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12236                 {"ipv6", RTE_ETH_FLOW_IPV6},
12237                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12238                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12239                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12240                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12241                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12242                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12243                 {"port", RTE_ETH_FLOW_PORT},
12244                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12245                 {"geneve", RTE_ETH_FLOW_GENEVE},
12246                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12247                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12248         };
12249
12250         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12251                 if (ftype_table[i].ftype == ftype)
12252                         return ftype_table[i].str;
12253         }
12254
12255         return NULL;
12256 }
12257
12258 static void
12259 cmd_get_hash_global_config_parsed(void *parsed_result,
12260                                   __rte_unused struct cmdline *cl,
12261                                   __rte_unused void *data)
12262 {
12263         struct cmd_get_hash_global_config_result *res = parsed_result;
12264         struct rte_eth_hash_filter_info info;
12265         uint32_t idx, offset;
12266         uint16_t i;
12267         char *str;
12268         int ret;
12269
12270         if (rte_eth_dev_filter_supported(res->port_id,
12271                         RTE_ETH_FILTER_HASH) < 0) {
12272                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12273                                                         res->port_id);
12274                 return;
12275         }
12276
12277         memset(&info, 0, sizeof(info));
12278         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12279         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12280                                         RTE_ETH_FILTER_GET, &info);
12281         if (ret < 0) {
12282                 printf("Cannot get hash global configurations by port %d\n",
12283                                                         res->port_id);
12284                 return;
12285         }
12286
12287         switch (info.info.global_conf.hash_func) {
12288         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12289                 printf("Hash function is Toeplitz\n");
12290                 break;
12291         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12292                 printf("Hash function is Simple XOR\n");
12293                 break;
12294         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12295                 printf("Hash function is Symmetric Toeplitz\n");
12296                 break;
12297         default:
12298                 printf("Unknown hash function\n");
12299                 break;
12300         }
12301
12302         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12303                 idx = i / UINT64_BIT;
12304                 offset = i % UINT64_BIT;
12305                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12306                                                 (1ULL << offset)))
12307                         continue;
12308                 str = flowtype_to_str(i);
12309                 if (!str)
12310                         continue;
12311                 printf("Symmetric hash is %s globally for flow type %s "
12312                                                         "by port %d\n",
12313                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12314                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12315                                                         res->port_id);
12316         }
12317 }
12318
12319 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12320         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12321                 get_hash_global_config, "get_hash_global_config");
12322 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12323         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12324                 port_id, UINT16);
12325
12326 cmdline_parse_inst_t cmd_get_hash_global_config = {
12327         .f = cmd_get_hash_global_config_parsed,
12328         .data = NULL,
12329         .help_str = "get_hash_global_config <port_id>",
12330         .tokens = {
12331                 (void *)&cmd_get_hash_global_config_all,
12332                 (void *)&cmd_get_hash_global_config_port_id,
12333                 NULL,
12334         },
12335 };
12336
12337 /* Set global config of hash function */
12338 struct cmd_set_hash_global_config_result {
12339         cmdline_fixed_string_t set_hash_global_config;
12340         portid_t port_id;
12341         cmdline_fixed_string_t hash_func;
12342         cmdline_fixed_string_t flow_type;
12343         cmdline_fixed_string_t enable;
12344 };
12345
12346 static void
12347 cmd_set_hash_global_config_parsed(void *parsed_result,
12348                                   __rte_unused struct cmdline *cl,
12349                                   __rte_unused void *data)
12350 {
12351         struct cmd_set_hash_global_config_result *res = parsed_result;
12352         struct rte_eth_hash_filter_info info;
12353         uint32_t ftype, idx, offset;
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         memset(&info, 0, sizeof(info));
12363         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12364         if (!strcmp(res->hash_func, "toeplitz"))
12365                 info.info.global_conf.hash_func =
12366                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12367         else if (!strcmp(res->hash_func, "simple_xor"))
12368                 info.info.global_conf.hash_func =
12369                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12370         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12371                 info.info.global_conf.hash_func =
12372                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12373         else if (!strcmp(res->hash_func, "default"))
12374                 info.info.global_conf.hash_func =
12375                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12376
12377         ftype = str2flowtype(res->flow_type);
12378         idx = ftype / UINT64_BIT;
12379         offset = ftype % UINT64_BIT;
12380         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12381         if (!strcmp(res->enable, "enable"))
12382                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12383                                                 (1ULL << offset);
12384         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12385                                         RTE_ETH_FILTER_SET, &info);
12386         if (ret < 0)
12387                 printf("Cannot set global hash configurations by port %d\n",
12388                                                         res->port_id);
12389         else
12390                 printf("Global hash configurations have been set "
12391                         "successfully by port %d\n", res->port_id);
12392 }
12393
12394 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12395         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12396                 set_hash_global_config, "set_hash_global_config");
12397 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12398         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12399                 port_id, UINT16);
12400 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12401         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12402                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12403 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12404         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12405                 flow_type,
12406                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12407                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12408 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12409         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12410                 enable, "enable#disable");
12411
12412 cmdline_parse_inst_t cmd_set_hash_global_config = {
12413         .f = cmd_set_hash_global_config_parsed,
12414         .data = NULL,
12415         .help_str = "set_hash_global_config <port_id> "
12416                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12417                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12418                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12419                 "l2_payload enable|disable",
12420         .tokens = {
12421                 (void *)&cmd_set_hash_global_config_all,
12422                 (void *)&cmd_set_hash_global_config_port_id,
12423                 (void *)&cmd_set_hash_global_config_hash_func,
12424                 (void *)&cmd_set_hash_global_config_flow_type,
12425                 (void *)&cmd_set_hash_global_config_enable,
12426                 NULL,
12427         },
12428 };
12429
12430 /* Set hash input set */
12431 struct cmd_set_hash_input_set_result {
12432         cmdline_fixed_string_t set_hash_input_set;
12433         portid_t port_id;
12434         cmdline_fixed_string_t flow_type;
12435         cmdline_fixed_string_t inset_field;
12436         cmdline_fixed_string_t select;
12437 };
12438
12439 static enum rte_eth_input_set_field
12440 str2inset(char *string)
12441 {
12442         uint16_t i;
12443
12444         static const struct {
12445                 char str[32];
12446                 enum rte_eth_input_set_field inset;
12447         } inset_table[] = {
12448                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12449                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12450                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12451                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12452                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12453                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12454                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12455                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12456                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12457                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12458                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12459                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12460                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12461                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12462                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12463                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12464                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12465                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12466                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12467                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12468                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12469                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12470                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12471                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12472                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12473                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12474                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12475                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12476                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12477                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12478                 {"none", RTE_ETH_INPUT_SET_NONE},
12479         };
12480
12481         for (i = 0; i < RTE_DIM(inset_table); i++) {
12482                 if (!strcmp(string, inset_table[i].str))
12483                         return inset_table[i].inset;
12484         }
12485
12486         return RTE_ETH_INPUT_SET_UNKNOWN;
12487 }
12488
12489 static void
12490 cmd_set_hash_input_set_parsed(void *parsed_result,
12491                               __rte_unused struct cmdline *cl,
12492                               __rte_unused void *data)
12493 {
12494         struct cmd_set_hash_input_set_result *res = parsed_result;
12495         struct rte_eth_hash_filter_info info;
12496
12497         memset(&info, 0, sizeof(info));
12498         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12499         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12500         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12501         info.info.input_set_conf.inset_size = 1;
12502         if (!strcmp(res->select, "select"))
12503                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12504         else if (!strcmp(res->select, "add"))
12505                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12506         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12507                                 RTE_ETH_FILTER_SET, &info);
12508 }
12509
12510 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12511         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12512                 set_hash_input_set, "set_hash_input_set");
12513 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12514         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12515                 port_id, UINT16);
12516 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12517         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12518                 flow_type, NULL);
12519 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12520         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12521                 inset_field,
12522                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12523                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12524                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12525                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12526                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12527                 "fld-8th#none");
12528 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12529         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12530                 select, "select#add");
12531
12532 cmdline_parse_inst_t cmd_set_hash_input_set = {
12533         .f = cmd_set_hash_input_set_parsed,
12534         .data = NULL,
12535         .help_str = "set_hash_input_set <port_id> "
12536         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12537         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12538         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12539         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12540         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12541         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12542         "fld-7th|fld-8th|none select|add",
12543         .tokens = {
12544                 (void *)&cmd_set_hash_input_set_cmd,
12545                 (void *)&cmd_set_hash_input_set_port_id,
12546                 (void *)&cmd_set_hash_input_set_flow_type,
12547                 (void *)&cmd_set_hash_input_set_field,
12548                 (void *)&cmd_set_hash_input_set_select,
12549                 NULL,
12550         },
12551 };
12552
12553 /* Set flow director input set */
12554 struct cmd_set_fdir_input_set_result {
12555         cmdline_fixed_string_t set_fdir_input_set;
12556         portid_t port_id;
12557         cmdline_fixed_string_t flow_type;
12558         cmdline_fixed_string_t inset_field;
12559         cmdline_fixed_string_t select;
12560 };
12561
12562 static void
12563 cmd_set_fdir_input_set_parsed(void *parsed_result,
12564         __rte_unused struct cmdline *cl,
12565         __rte_unused void *data)
12566 {
12567         struct cmd_set_fdir_input_set_result *res = parsed_result;
12568         struct rte_eth_fdir_filter_info info;
12569
12570         memset(&info, 0, sizeof(info));
12571         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12572         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12573         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12574         info.info.input_set_conf.inset_size = 1;
12575         if (!strcmp(res->select, "select"))
12576                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12577         else if (!strcmp(res->select, "add"))
12578                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12579         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12580                 RTE_ETH_FILTER_SET, &info);
12581 }
12582
12583 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12584         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12585         set_fdir_input_set, "set_fdir_input_set");
12586 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12587         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12588         port_id, UINT16);
12589 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12590         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12591         flow_type,
12592         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12593         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12594 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12595         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12596         inset_field,
12597         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12598         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12599         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12600         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12601         "sctp-veri-tag#none");
12602 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12603         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12604         select, "select#add");
12605
12606 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12607         .f = cmd_set_fdir_input_set_parsed,
12608         .data = NULL,
12609         .help_str = "set_fdir_input_set <port_id> "
12610         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12611         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12612         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12613         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12614         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12615         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12616         "sctp-veri-tag|none select|add",
12617         .tokens = {
12618                 (void *)&cmd_set_fdir_input_set_cmd,
12619                 (void *)&cmd_set_fdir_input_set_port_id,
12620                 (void *)&cmd_set_fdir_input_set_flow_type,
12621                 (void *)&cmd_set_fdir_input_set_field,
12622                 (void *)&cmd_set_fdir_input_set_select,
12623                 NULL,
12624         },
12625 };
12626
12627 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12628 struct cmd_mcast_addr_result {
12629         cmdline_fixed_string_t mcast_addr_cmd;
12630         cmdline_fixed_string_t what;
12631         uint16_t port_num;
12632         struct rte_ether_addr mc_addr;
12633 };
12634
12635 static void cmd_mcast_addr_parsed(void *parsed_result,
12636                 __attribute__((unused)) struct cmdline *cl,
12637                 __attribute__((unused)) void *data)
12638 {
12639         struct cmd_mcast_addr_result *res = parsed_result;
12640
12641         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12642                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12643                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12644                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12645                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12646                 return;
12647         }
12648         if (strcmp(res->what, "add") == 0)
12649                 mcast_addr_add(res->port_num, &res->mc_addr);
12650         else
12651                 mcast_addr_remove(res->port_num, &res->mc_addr);
12652 }
12653
12654 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12655         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12656                                  mcast_addr_cmd, "mcast_addr");
12657 cmdline_parse_token_string_t cmd_mcast_addr_what =
12658         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12659                                  "add#remove");
12660 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12661         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12662 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12664
12665 cmdline_parse_inst_t cmd_mcast_addr = {
12666         .f = cmd_mcast_addr_parsed,
12667         .data = (void *)0,
12668         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12669                 "Add/Remove multicast MAC address on port_id",
12670         .tokens = {
12671                 (void *)&cmd_mcast_addr_cmd,
12672                 (void *)&cmd_mcast_addr_what,
12673                 (void *)&cmd_mcast_addr_portnum,
12674                 (void *)&cmd_mcast_addr_addr,
12675                 NULL,
12676         },
12677 };
12678
12679 /* l2 tunnel config
12680  * only support E-tag now.
12681  */
12682
12683 /* Ether type config */
12684 struct cmd_config_l2_tunnel_eth_type_result {
12685         cmdline_fixed_string_t port;
12686         cmdline_fixed_string_t config;
12687         cmdline_fixed_string_t all;
12688         portid_t id;
12689         cmdline_fixed_string_t l2_tunnel;
12690         cmdline_fixed_string_t l2_tunnel_type;
12691         cmdline_fixed_string_t eth_type;
12692         uint16_t eth_type_val;
12693 };
12694
12695 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12696         TOKEN_STRING_INITIALIZER
12697                 (struct cmd_config_l2_tunnel_eth_type_result,
12698                  port, "port");
12699 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12700         TOKEN_STRING_INITIALIZER
12701                 (struct cmd_config_l2_tunnel_eth_type_result,
12702                  config, "config");
12703 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12704         TOKEN_STRING_INITIALIZER
12705                 (struct cmd_config_l2_tunnel_eth_type_result,
12706                  all, "all");
12707 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12708         TOKEN_NUM_INITIALIZER
12709                 (struct cmd_config_l2_tunnel_eth_type_result,
12710                  id, UINT16);
12711 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12712         TOKEN_STRING_INITIALIZER
12713                 (struct cmd_config_l2_tunnel_eth_type_result,
12714                  l2_tunnel, "l2-tunnel");
12715 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12716         TOKEN_STRING_INITIALIZER
12717                 (struct cmd_config_l2_tunnel_eth_type_result,
12718                  l2_tunnel_type, "E-tag");
12719 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12720         TOKEN_STRING_INITIALIZER
12721                 (struct cmd_config_l2_tunnel_eth_type_result,
12722                  eth_type, "ether-type");
12723 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12724         TOKEN_NUM_INITIALIZER
12725                 (struct cmd_config_l2_tunnel_eth_type_result,
12726                  eth_type_val, UINT16);
12727
12728 static enum rte_eth_tunnel_type
12729 str2fdir_l2_tunnel_type(char *string)
12730 {
12731         uint32_t i = 0;
12732
12733         static const struct {
12734                 char str[32];
12735                 enum rte_eth_tunnel_type type;
12736         } l2_tunnel_type_str[] = {
12737                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12738         };
12739
12740         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12741                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12742                         return l2_tunnel_type_str[i].type;
12743         }
12744         return RTE_TUNNEL_TYPE_NONE;
12745 }
12746
12747 /* ether type config for all ports */
12748 static void
12749 cmd_config_l2_tunnel_eth_type_all_parsed
12750         (void *parsed_result,
12751          __attribute__((unused)) struct cmdline *cl,
12752          __attribute__((unused)) void *data)
12753 {
12754         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12755         struct rte_eth_l2_tunnel_conf entry;
12756         portid_t pid;
12757
12758         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12759         entry.ether_type = res->eth_type_val;
12760
12761         RTE_ETH_FOREACH_DEV(pid) {
12762                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12763         }
12764 }
12765
12766 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12767         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12768         .data = NULL,
12769         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12770         .tokens = {
12771                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12772                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12773                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12774                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12775                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12776                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12777                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12778                 NULL,
12779         },
12780 };
12781
12782 /* ether type config for a specific port */
12783 static void
12784 cmd_config_l2_tunnel_eth_type_specific_parsed(
12785         void *parsed_result,
12786         __attribute__((unused)) struct cmdline *cl,
12787         __attribute__((unused)) void *data)
12788 {
12789         struct cmd_config_l2_tunnel_eth_type_result *res =
12790                  parsed_result;
12791         struct rte_eth_l2_tunnel_conf entry;
12792
12793         if (port_id_is_invalid(res->id, ENABLED_WARN))
12794                 return;
12795
12796         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12797         entry.ether_type = res->eth_type_val;
12798
12799         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12800 }
12801
12802 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12803         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12804         .data = NULL,
12805         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12806         .tokens = {
12807                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12808                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12809                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12810                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12811                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12812                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12813                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12814                 NULL,
12815         },
12816 };
12817
12818 /* Enable/disable l2 tunnel */
12819 struct cmd_config_l2_tunnel_en_dis_result {
12820         cmdline_fixed_string_t port;
12821         cmdline_fixed_string_t config;
12822         cmdline_fixed_string_t all;
12823         portid_t id;
12824         cmdline_fixed_string_t l2_tunnel;
12825         cmdline_fixed_string_t l2_tunnel_type;
12826         cmdline_fixed_string_t en_dis;
12827 };
12828
12829 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12830         TOKEN_STRING_INITIALIZER
12831                 (struct cmd_config_l2_tunnel_en_dis_result,
12832                  port, "port");
12833 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12834         TOKEN_STRING_INITIALIZER
12835                 (struct cmd_config_l2_tunnel_en_dis_result,
12836                  config, "config");
12837 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12838         TOKEN_STRING_INITIALIZER
12839                 (struct cmd_config_l2_tunnel_en_dis_result,
12840                  all, "all");
12841 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12842         TOKEN_NUM_INITIALIZER
12843                 (struct cmd_config_l2_tunnel_en_dis_result,
12844                  id, UINT16);
12845 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12846         TOKEN_STRING_INITIALIZER
12847                 (struct cmd_config_l2_tunnel_en_dis_result,
12848                  l2_tunnel, "l2-tunnel");
12849 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12850         TOKEN_STRING_INITIALIZER
12851                 (struct cmd_config_l2_tunnel_en_dis_result,
12852                  l2_tunnel_type, "E-tag");
12853 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12854         TOKEN_STRING_INITIALIZER
12855                 (struct cmd_config_l2_tunnel_en_dis_result,
12856                  en_dis, "enable#disable");
12857
12858 /* enable/disable l2 tunnel for all ports */
12859 static void
12860 cmd_config_l2_tunnel_en_dis_all_parsed(
12861         void *parsed_result,
12862         __attribute__((unused)) struct cmdline *cl,
12863         __attribute__((unused)) void *data)
12864 {
12865         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12866         struct rte_eth_l2_tunnel_conf entry;
12867         portid_t pid;
12868         uint8_t en;
12869
12870         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12871
12872         if (!strcmp("enable", res->en_dis))
12873                 en = 1;
12874         else
12875                 en = 0;
12876
12877         RTE_ETH_FOREACH_DEV(pid) {
12878                 rte_eth_dev_l2_tunnel_offload_set(pid,
12879                                                   &entry,
12880                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12881                                                   en);
12882         }
12883 }
12884
12885 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12886         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12887         .data = NULL,
12888         .help_str = "port config all l2-tunnel E-tag enable|disable",
12889         .tokens = {
12890                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12891                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12892                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12893                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12894                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12895                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12896                 NULL,
12897         },
12898 };
12899
12900 /* enable/disable l2 tunnel for a port */
12901 static void
12902 cmd_config_l2_tunnel_en_dis_specific_parsed(
12903         void *parsed_result,
12904         __attribute__((unused)) struct cmdline *cl,
12905         __attribute__((unused)) void *data)
12906 {
12907         struct cmd_config_l2_tunnel_en_dis_result *res =
12908                 parsed_result;
12909         struct rte_eth_l2_tunnel_conf entry;
12910
12911         if (port_id_is_invalid(res->id, ENABLED_WARN))
12912                 return;
12913
12914         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12915
12916         if (!strcmp("enable", res->en_dis))
12917                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12918                                                   &entry,
12919                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12920                                                   1);
12921         else
12922                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12923                                                   &entry,
12924                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12925                                                   0);
12926 }
12927
12928 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12929         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12930         .data = NULL,
12931         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12932         .tokens = {
12933                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12934                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12935                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12936                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12937                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12938                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12939                 NULL,
12940         },
12941 };
12942
12943 /* E-tag configuration */
12944
12945 /* Common result structure for all E-tag configuration */
12946 struct cmd_config_e_tag_result {
12947         cmdline_fixed_string_t e_tag;
12948         cmdline_fixed_string_t set;
12949         cmdline_fixed_string_t insertion;
12950         cmdline_fixed_string_t stripping;
12951         cmdline_fixed_string_t forwarding;
12952         cmdline_fixed_string_t filter;
12953         cmdline_fixed_string_t add;
12954         cmdline_fixed_string_t del;
12955         cmdline_fixed_string_t on;
12956         cmdline_fixed_string_t off;
12957         cmdline_fixed_string_t on_off;
12958         cmdline_fixed_string_t port_tag_id;
12959         uint32_t port_tag_id_val;
12960         cmdline_fixed_string_t e_tag_id;
12961         uint16_t e_tag_id_val;
12962         cmdline_fixed_string_t dst_pool;
12963         uint8_t dst_pool_val;
12964         cmdline_fixed_string_t port;
12965         portid_t port_id;
12966         cmdline_fixed_string_t vf;
12967         uint8_t vf_id;
12968 };
12969
12970 /* Common CLI fields for all E-tag configuration */
12971 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_config_e_tag_result,
12974                  e_tag, "E-tag");
12975 cmdline_parse_token_string_t cmd_config_e_tag_set =
12976         TOKEN_STRING_INITIALIZER
12977                 (struct cmd_config_e_tag_result,
12978                  set, "set");
12979 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12980         TOKEN_STRING_INITIALIZER
12981                 (struct cmd_config_e_tag_result,
12982                  insertion, "insertion");
12983 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_config_e_tag_result,
12986                  stripping, "stripping");
12987 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_config_e_tag_result,
12990                  forwarding, "forwarding");
12991 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_config_e_tag_result,
12994                  filter, "filter");
12995 cmdline_parse_token_string_t cmd_config_e_tag_add =
12996         TOKEN_STRING_INITIALIZER
12997                 (struct cmd_config_e_tag_result,
12998                  add, "add");
12999 cmdline_parse_token_string_t cmd_config_e_tag_del =
13000         TOKEN_STRING_INITIALIZER
13001                 (struct cmd_config_e_tag_result,
13002                  del, "del");
13003 cmdline_parse_token_string_t cmd_config_e_tag_on =
13004         TOKEN_STRING_INITIALIZER
13005                 (struct cmd_config_e_tag_result,
13006                  on, "on");
13007 cmdline_parse_token_string_t cmd_config_e_tag_off =
13008         TOKEN_STRING_INITIALIZER
13009                 (struct cmd_config_e_tag_result,
13010                  off, "off");
13011 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13012         TOKEN_STRING_INITIALIZER
13013                 (struct cmd_config_e_tag_result,
13014                  on_off, "on#off");
13015 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13016         TOKEN_STRING_INITIALIZER
13017                 (struct cmd_config_e_tag_result,
13018                  port_tag_id, "port-tag-id");
13019 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13020         TOKEN_NUM_INITIALIZER
13021                 (struct cmd_config_e_tag_result,
13022                  port_tag_id_val, UINT32);
13023 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13024         TOKEN_STRING_INITIALIZER
13025                 (struct cmd_config_e_tag_result,
13026                  e_tag_id, "e-tag-id");
13027 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13028         TOKEN_NUM_INITIALIZER
13029                 (struct cmd_config_e_tag_result,
13030                  e_tag_id_val, UINT16);
13031 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13032         TOKEN_STRING_INITIALIZER
13033                 (struct cmd_config_e_tag_result,
13034                  dst_pool, "dst-pool");
13035 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13036         TOKEN_NUM_INITIALIZER
13037                 (struct cmd_config_e_tag_result,
13038                  dst_pool_val, UINT8);
13039 cmdline_parse_token_string_t cmd_config_e_tag_port =
13040         TOKEN_STRING_INITIALIZER
13041                 (struct cmd_config_e_tag_result,
13042                  port, "port");
13043 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13044         TOKEN_NUM_INITIALIZER
13045                 (struct cmd_config_e_tag_result,
13046                  port_id, UINT16);
13047 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13048         TOKEN_STRING_INITIALIZER
13049                 (struct cmd_config_e_tag_result,
13050                  vf, "vf");
13051 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13052         TOKEN_NUM_INITIALIZER
13053                 (struct cmd_config_e_tag_result,
13054                  vf_id, UINT8);
13055
13056 /* E-tag insertion configuration */
13057 static void
13058 cmd_config_e_tag_insertion_en_parsed(
13059         void *parsed_result,
13060         __attribute__((unused)) struct cmdline *cl,
13061         __attribute__((unused)) void *data)
13062 {
13063         struct cmd_config_e_tag_result *res =
13064                 parsed_result;
13065         struct rte_eth_l2_tunnel_conf entry;
13066
13067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13068                 return;
13069
13070         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13071         entry.tunnel_id = res->port_tag_id_val;
13072         entry.vf_id = res->vf_id;
13073         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13074                                           &entry,
13075                                           ETH_L2_TUNNEL_INSERTION_MASK,
13076                                           1);
13077 }
13078
13079 static void
13080 cmd_config_e_tag_insertion_dis_parsed(
13081         void *parsed_result,
13082         __attribute__((unused)) struct cmdline *cl,
13083         __attribute__((unused)) void *data)
13084 {
13085         struct cmd_config_e_tag_result *res =
13086                 parsed_result;
13087         struct rte_eth_l2_tunnel_conf entry;
13088
13089         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13090                 return;
13091
13092         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13093         entry.vf_id = res->vf_id;
13094
13095         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13096                                           &entry,
13097                                           ETH_L2_TUNNEL_INSERTION_MASK,
13098                                           0);
13099 }
13100
13101 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13102         .f = cmd_config_e_tag_insertion_en_parsed,
13103         .data = NULL,
13104         .help_str = "E-tag ... : E-tag insertion enable",
13105         .tokens = {
13106                 (void *)&cmd_config_e_tag_e_tag,
13107                 (void *)&cmd_config_e_tag_set,
13108                 (void *)&cmd_config_e_tag_insertion,
13109                 (void *)&cmd_config_e_tag_on,
13110                 (void *)&cmd_config_e_tag_port_tag_id,
13111                 (void *)&cmd_config_e_tag_port_tag_id_val,
13112                 (void *)&cmd_config_e_tag_port,
13113                 (void *)&cmd_config_e_tag_port_id,
13114                 (void *)&cmd_config_e_tag_vf,
13115                 (void *)&cmd_config_e_tag_vf_id,
13116                 NULL,
13117         },
13118 };
13119
13120 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13121         .f = cmd_config_e_tag_insertion_dis_parsed,
13122         .data = NULL,
13123         .help_str = "E-tag ... : E-tag insertion disable",
13124         .tokens = {
13125                 (void *)&cmd_config_e_tag_e_tag,
13126                 (void *)&cmd_config_e_tag_set,
13127                 (void *)&cmd_config_e_tag_insertion,
13128                 (void *)&cmd_config_e_tag_off,
13129                 (void *)&cmd_config_e_tag_port,
13130                 (void *)&cmd_config_e_tag_port_id,
13131                 (void *)&cmd_config_e_tag_vf,
13132                 (void *)&cmd_config_e_tag_vf_id,
13133                 NULL,
13134         },
13135 };
13136
13137 /* E-tag stripping configuration */
13138 static void
13139 cmd_config_e_tag_stripping_parsed(
13140         void *parsed_result,
13141         __attribute__((unused)) struct cmdline *cl,
13142         __attribute__((unused)) void *data)
13143 {
13144         struct cmd_config_e_tag_result *res =
13145                 parsed_result;
13146         struct rte_eth_l2_tunnel_conf entry;
13147
13148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13149                 return;
13150
13151         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13152
13153         if (!strcmp(res->on_off, "on"))
13154                 rte_eth_dev_l2_tunnel_offload_set
13155                         (res->port_id,
13156                          &entry,
13157                          ETH_L2_TUNNEL_STRIPPING_MASK,
13158                          1);
13159         else
13160                 rte_eth_dev_l2_tunnel_offload_set
13161                         (res->port_id,
13162                          &entry,
13163                          ETH_L2_TUNNEL_STRIPPING_MASK,
13164                          0);
13165 }
13166
13167 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13168         .f = cmd_config_e_tag_stripping_parsed,
13169         .data = NULL,
13170         .help_str = "E-tag ... : E-tag stripping enable/disable",
13171         .tokens = {
13172                 (void *)&cmd_config_e_tag_e_tag,
13173                 (void *)&cmd_config_e_tag_set,
13174                 (void *)&cmd_config_e_tag_stripping,
13175                 (void *)&cmd_config_e_tag_on_off,
13176                 (void *)&cmd_config_e_tag_port,
13177                 (void *)&cmd_config_e_tag_port_id,
13178                 NULL,
13179         },
13180 };
13181
13182 /* E-tag forwarding configuration */
13183 static void
13184 cmd_config_e_tag_forwarding_parsed(
13185         void *parsed_result,
13186         __attribute__((unused)) struct cmdline *cl,
13187         __attribute__((unused)) void *data)
13188 {
13189         struct cmd_config_e_tag_result *res = parsed_result;
13190         struct rte_eth_l2_tunnel_conf entry;
13191
13192         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13193                 return;
13194
13195         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13196
13197         if (!strcmp(res->on_off, "on"))
13198                 rte_eth_dev_l2_tunnel_offload_set
13199                         (res->port_id,
13200                          &entry,
13201                          ETH_L2_TUNNEL_FORWARDING_MASK,
13202                          1);
13203         else
13204                 rte_eth_dev_l2_tunnel_offload_set
13205                         (res->port_id,
13206                          &entry,
13207                          ETH_L2_TUNNEL_FORWARDING_MASK,
13208                          0);
13209 }
13210
13211 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13212         .f = cmd_config_e_tag_forwarding_parsed,
13213         .data = NULL,
13214         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13215         .tokens = {
13216                 (void *)&cmd_config_e_tag_e_tag,
13217                 (void *)&cmd_config_e_tag_set,
13218                 (void *)&cmd_config_e_tag_forwarding,
13219                 (void *)&cmd_config_e_tag_on_off,
13220                 (void *)&cmd_config_e_tag_port,
13221                 (void *)&cmd_config_e_tag_port_id,
13222                 NULL,
13223         },
13224 };
13225
13226 /* E-tag filter configuration */
13227 static void
13228 cmd_config_e_tag_filter_add_parsed(
13229         void *parsed_result,
13230         __attribute__((unused)) struct cmdline *cl,
13231         __attribute__((unused)) void *data)
13232 {
13233         struct cmd_config_e_tag_result *res = parsed_result;
13234         struct rte_eth_l2_tunnel_conf entry;
13235         int ret = 0;
13236
13237         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13238                 return;
13239
13240         if (res->e_tag_id_val > 0x3fff) {
13241                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13242                 return;
13243         }
13244
13245         ret = rte_eth_dev_filter_supported(res->port_id,
13246                                            RTE_ETH_FILTER_L2_TUNNEL);
13247         if (ret < 0) {
13248                 printf("E-tag filter is not supported on port %u.\n",
13249                        res->port_id);
13250                 return;
13251         }
13252
13253         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13254         entry.tunnel_id = res->e_tag_id_val;
13255         entry.pool = res->dst_pool_val;
13256
13257         ret = rte_eth_dev_filter_ctrl(res->port_id,
13258                                       RTE_ETH_FILTER_L2_TUNNEL,
13259                                       RTE_ETH_FILTER_ADD,
13260                                       &entry);
13261         if (ret < 0)
13262                 printf("E-tag filter programming error: (%s)\n",
13263                        strerror(-ret));
13264 }
13265
13266 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13267         .f = cmd_config_e_tag_filter_add_parsed,
13268         .data = NULL,
13269         .help_str = "E-tag ... : E-tag filter add",
13270         .tokens = {
13271                 (void *)&cmd_config_e_tag_e_tag,
13272                 (void *)&cmd_config_e_tag_set,
13273                 (void *)&cmd_config_e_tag_filter,
13274                 (void *)&cmd_config_e_tag_add,
13275                 (void *)&cmd_config_e_tag_e_tag_id,
13276                 (void *)&cmd_config_e_tag_e_tag_id_val,
13277                 (void *)&cmd_config_e_tag_dst_pool,
13278                 (void *)&cmd_config_e_tag_dst_pool_val,
13279                 (void *)&cmd_config_e_tag_port,
13280                 (void *)&cmd_config_e_tag_port_id,
13281                 NULL,
13282         },
13283 };
13284
13285 static void
13286 cmd_config_e_tag_filter_del_parsed(
13287         void *parsed_result,
13288         __attribute__((unused)) struct cmdline *cl,
13289         __attribute__((unused)) void *data)
13290 {
13291         struct cmd_config_e_tag_result *res = parsed_result;
13292         struct rte_eth_l2_tunnel_conf entry;
13293         int ret = 0;
13294
13295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13296                 return;
13297
13298         if (res->e_tag_id_val > 0x3fff) {
13299                 printf("e-tag-id must be less than 0x3fff.\n");
13300                 return;
13301         }
13302
13303         ret = rte_eth_dev_filter_supported(res->port_id,
13304                                            RTE_ETH_FILTER_L2_TUNNEL);
13305         if (ret < 0) {
13306                 printf("E-tag filter is not supported on port %u.\n",
13307                        res->port_id);
13308                 return;
13309         }
13310
13311         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13312         entry.tunnel_id = res->e_tag_id_val;
13313
13314         ret = rte_eth_dev_filter_ctrl(res->port_id,
13315                                       RTE_ETH_FILTER_L2_TUNNEL,
13316                                       RTE_ETH_FILTER_DELETE,
13317                                       &entry);
13318         if (ret < 0)
13319                 printf("E-tag filter programming error: (%s)\n",
13320                        strerror(-ret));
13321 }
13322
13323 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13324         .f = cmd_config_e_tag_filter_del_parsed,
13325         .data = NULL,
13326         .help_str = "E-tag ... : E-tag filter delete",
13327         .tokens = {
13328                 (void *)&cmd_config_e_tag_e_tag,
13329                 (void *)&cmd_config_e_tag_set,
13330                 (void *)&cmd_config_e_tag_filter,
13331                 (void *)&cmd_config_e_tag_del,
13332                 (void *)&cmd_config_e_tag_e_tag_id,
13333                 (void *)&cmd_config_e_tag_e_tag_id_val,
13334                 (void *)&cmd_config_e_tag_port,
13335                 (void *)&cmd_config_e_tag_port_id,
13336                 NULL,
13337         },
13338 };
13339
13340 /* vf vlan anti spoof configuration */
13341
13342 /* Common result structure for vf vlan anti spoof */
13343 struct cmd_vf_vlan_anti_spoof_result {
13344         cmdline_fixed_string_t set;
13345         cmdline_fixed_string_t vf;
13346         cmdline_fixed_string_t vlan;
13347         cmdline_fixed_string_t antispoof;
13348         portid_t port_id;
13349         uint32_t vf_id;
13350         cmdline_fixed_string_t on_off;
13351 };
13352
13353 /* Common CLI fields for vf vlan anti spoof enable disable */
13354 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13355         TOKEN_STRING_INITIALIZER
13356                 (struct cmd_vf_vlan_anti_spoof_result,
13357                  set, "set");
13358 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13359         TOKEN_STRING_INITIALIZER
13360                 (struct cmd_vf_vlan_anti_spoof_result,
13361                  vf, "vf");
13362 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13363         TOKEN_STRING_INITIALIZER
13364                 (struct cmd_vf_vlan_anti_spoof_result,
13365                  vlan, "vlan");
13366 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13367         TOKEN_STRING_INITIALIZER
13368                 (struct cmd_vf_vlan_anti_spoof_result,
13369                  antispoof, "antispoof");
13370 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13371         TOKEN_NUM_INITIALIZER
13372                 (struct cmd_vf_vlan_anti_spoof_result,
13373                  port_id, UINT16);
13374 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13375         TOKEN_NUM_INITIALIZER
13376                 (struct cmd_vf_vlan_anti_spoof_result,
13377                  vf_id, UINT32);
13378 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13379         TOKEN_STRING_INITIALIZER
13380                 (struct cmd_vf_vlan_anti_spoof_result,
13381                  on_off, "on#off");
13382
13383 static void
13384 cmd_set_vf_vlan_anti_spoof_parsed(
13385         void *parsed_result,
13386         __attribute__((unused)) struct cmdline *cl,
13387         __attribute__((unused)) void *data)
13388 {
13389         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13390         int ret = -ENOTSUP;
13391
13392         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13393
13394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13395                 return;
13396
13397 #ifdef RTE_LIBRTE_IXGBE_PMD
13398         if (ret == -ENOTSUP)
13399                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13400                                 res->vf_id, is_on);
13401 #endif
13402 #ifdef RTE_LIBRTE_I40E_PMD
13403         if (ret == -ENOTSUP)
13404                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13405                                 res->vf_id, is_on);
13406 #endif
13407 #ifdef RTE_LIBRTE_BNXT_PMD
13408         if (ret == -ENOTSUP)
13409                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13410                                 res->vf_id, is_on);
13411 #endif
13412
13413         switch (ret) {
13414         case 0:
13415                 break;
13416         case -EINVAL:
13417                 printf("invalid vf_id %d\n", res->vf_id);
13418                 break;
13419         case -ENODEV:
13420                 printf("invalid port_id %d\n", res->port_id);
13421                 break;
13422         case -ENOTSUP:
13423                 printf("function not implemented\n");
13424                 break;
13425         default:
13426                 printf("programming error: (%s)\n", strerror(-ret));
13427         }
13428 }
13429
13430 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13431         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13432         .data = NULL,
13433         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13434         .tokens = {
13435                 (void *)&cmd_vf_vlan_anti_spoof_set,
13436                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13437                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13438                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13439                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13440                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13441                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13442                 NULL,
13443         },
13444 };
13445
13446 /* vf mac anti spoof configuration */
13447
13448 /* Common result structure for vf mac anti spoof */
13449 struct cmd_vf_mac_anti_spoof_result {
13450         cmdline_fixed_string_t set;
13451         cmdline_fixed_string_t vf;
13452         cmdline_fixed_string_t mac;
13453         cmdline_fixed_string_t antispoof;
13454         portid_t port_id;
13455         uint32_t vf_id;
13456         cmdline_fixed_string_t on_off;
13457 };
13458
13459 /* Common CLI fields for vf mac anti spoof enable disable */
13460 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_vf_mac_anti_spoof_result,
13463                  set, "set");
13464 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_vf_mac_anti_spoof_result,
13467                  vf, "vf");
13468 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13469         TOKEN_STRING_INITIALIZER
13470                 (struct cmd_vf_mac_anti_spoof_result,
13471                  mac, "mac");
13472 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13473         TOKEN_STRING_INITIALIZER
13474                 (struct cmd_vf_mac_anti_spoof_result,
13475                  antispoof, "antispoof");
13476 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13477         TOKEN_NUM_INITIALIZER
13478                 (struct cmd_vf_mac_anti_spoof_result,
13479                  port_id, UINT16);
13480 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13481         TOKEN_NUM_INITIALIZER
13482                 (struct cmd_vf_mac_anti_spoof_result,
13483                  vf_id, UINT32);
13484 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13485         TOKEN_STRING_INITIALIZER
13486                 (struct cmd_vf_mac_anti_spoof_result,
13487                  on_off, "on#off");
13488
13489 static void
13490 cmd_set_vf_mac_anti_spoof_parsed(
13491         void *parsed_result,
13492         __attribute__((unused)) struct cmdline *cl,
13493         __attribute__((unused)) void *data)
13494 {
13495         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13496         int ret = -ENOTSUP;
13497
13498         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13499
13500         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13501                 return;
13502
13503 #ifdef RTE_LIBRTE_IXGBE_PMD
13504         if (ret == -ENOTSUP)
13505                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13506                         res->vf_id, is_on);
13507 #endif
13508 #ifdef RTE_LIBRTE_I40E_PMD
13509         if (ret == -ENOTSUP)
13510                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13511                         res->vf_id, is_on);
13512 #endif
13513 #ifdef RTE_LIBRTE_BNXT_PMD
13514         if (ret == -ENOTSUP)
13515                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13516                         res->vf_id, is_on);
13517 #endif
13518
13519         switch (ret) {
13520         case 0:
13521                 break;
13522         case -EINVAL:
13523                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13524                 break;
13525         case -ENODEV:
13526                 printf("invalid port_id %d\n", res->port_id);
13527                 break;
13528         case -ENOTSUP:
13529                 printf("function not implemented\n");
13530                 break;
13531         default:
13532                 printf("programming error: (%s)\n", strerror(-ret));
13533         }
13534 }
13535
13536 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13537         .f = cmd_set_vf_mac_anti_spoof_parsed,
13538         .data = NULL,
13539         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13540         .tokens = {
13541                 (void *)&cmd_vf_mac_anti_spoof_set,
13542                 (void *)&cmd_vf_mac_anti_spoof_vf,
13543                 (void *)&cmd_vf_mac_anti_spoof_mac,
13544                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13545                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13546                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13547                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13548                 NULL,
13549         },
13550 };
13551
13552 /* vf vlan strip queue configuration */
13553
13554 /* Common result structure for vf mac anti spoof */
13555 struct cmd_vf_vlan_stripq_result {
13556         cmdline_fixed_string_t set;
13557         cmdline_fixed_string_t vf;
13558         cmdline_fixed_string_t vlan;
13559         cmdline_fixed_string_t stripq;
13560         portid_t port_id;
13561         uint16_t vf_id;
13562         cmdline_fixed_string_t on_off;
13563 };
13564
13565 /* Common CLI fields for vf vlan strip enable disable */
13566 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_vf_vlan_stripq_result,
13569                  set, "set");
13570 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_vf_vlan_stripq_result,
13573                  vf, "vf");
13574 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13575         TOKEN_STRING_INITIALIZER
13576                 (struct cmd_vf_vlan_stripq_result,
13577                  vlan, "vlan");
13578 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13579         TOKEN_STRING_INITIALIZER
13580                 (struct cmd_vf_vlan_stripq_result,
13581                  stripq, "stripq");
13582 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13583         TOKEN_NUM_INITIALIZER
13584                 (struct cmd_vf_vlan_stripq_result,
13585                  port_id, UINT16);
13586 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13587         TOKEN_NUM_INITIALIZER
13588                 (struct cmd_vf_vlan_stripq_result,
13589                  vf_id, UINT16);
13590 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13591         TOKEN_STRING_INITIALIZER
13592                 (struct cmd_vf_vlan_stripq_result,
13593                  on_off, "on#off");
13594
13595 static void
13596 cmd_set_vf_vlan_stripq_parsed(
13597         void *parsed_result,
13598         __attribute__((unused)) struct cmdline *cl,
13599         __attribute__((unused)) void *data)
13600 {
13601         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13602         int ret = -ENOTSUP;
13603
13604         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13605
13606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13607                 return;
13608
13609 #ifdef RTE_LIBRTE_IXGBE_PMD
13610         if (ret == -ENOTSUP)
13611                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13612                         res->vf_id, is_on);
13613 #endif
13614 #ifdef RTE_LIBRTE_I40E_PMD
13615         if (ret == -ENOTSUP)
13616                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13617                         res->vf_id, is_on);
13618 #endif
13619 #ifdef RTE_LIBRTE_BNXT_PMD
13620         if (ret == -ENOTSUP)
13621                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13622                         res->vf_id, is_on);
13623 #endif
13624
13625         switch (ret) {
13626         case 0:
13627                 break;
13628         case -EINVAL:
13629                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13630                 break;
13631         case -ENODEV:
13632                 printf("invalid port_id %d\n", res->port_id);
13633                 break;
13634         case -ENOTSUP:
13635                 printf("function not implemented\n");
13636                 break;
13637         default:
13638                 printf("programming error: (%s)\n", strerror(-ret));
13639         }
13640 }
13641
13642 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13643         .f = cmd_set_vf_vlan_stripq_parsed,
13644         .data = NULL,
13645         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13646         .tokens = {
13647                 (void *)&cmd_vf_vlan_stripq_set,
13648                 (void *)&cmd_vf_vlan_stripq_vf,
13649                 (void *)&cmd_vf_vlan_stripq_vlan,
13650                 (void *)&cmd_vf_vlan_stripq_stripq,
13651                 (void *)&cmd_vf_vlan_stripq_port_id,
13652                 (void *)&cmd_vf_vlan_stripq_vf_id,
13653                 (void *)&cmd_vf_vlan_stripq_on_off,
13654                 NULL,
13655         },
13656 };
13657
13658 /* vf vlan insert configuration */
13659
13660 /* Common result structure for vf vlan insert */
13661 struct cmd_vf_vlan_insert_result {
13662         cmdline_fixed_string_t set;
13663         cmdline_fixed_string_t vf;
13664         cmdline_fixed_string_t vlan;
13665         cmdline_fixed_string_t insert;
13666         portid_t port_id;
13667         uint16_t vf_id;
13668         uint16_t vlan_id;
13669 };
13670
13671 /* Common CLI fields for vf vlan insert enable disable */
13672 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_vf_vlan_insert_result,
13675                  set, "set");
13676 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_vf_vlan_insert_result,
13679                  vf, "vf");
13680 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13681         TOKEN_STRING_INITIALIZER
13682                 (struct cmd_vf_vlan_insert_result,
13683                  vlan, "vlan");
13684 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13685         TOKEN_STRING_INITIALIZER
13686                 (struct cmd_vf_vlan_insert_result,
13687                  insert, "insert");
13688 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13689         TOKEN_NUM_INITIALIZER
13690                 (struct cmd_vf_vlan_insert_result,
13691                  port_id, UINT16);
13692 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13693         TOKEN_NUM_INITIALIZER
13694                 (struct cmd_vf_vlan_insert_result,
13695                  vf_id, UINT16);
13696 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13697         TOKEN_NUM_INITIALIZER
13698                 (struct cmd_vf_vlan_insert_result,
13699                  vlan_id, UINT16);
13700
13701 static void
13702 cmd_set_vf_vlan_insert_parsed(
13703         void *parsed_result,
13704         __attribute__((unused)) struct cmdline *cl,
13705         __attribute__((unused)) void *data)
13706 {
13707         struct cmd_vf_vlan_insert_result *res = parsed_result;
13708         int ret = -ENOTSUP;
13709
13710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13711                 return;
13712
13713 #ifdef RTE_LIBRTE_IXGBE_PMD
13714         if (ret == -ENOTSUP)
13715                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13716                         res->vlan_id);
13717 #endif
13718 #ifdef RTE_LIBRTE_I40E_PMD
13719         if (ret == -ENOTSUP)
13720                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13721                         res->vlan_id);
13722 #endif
13723 #ifdef RTE_LIBRTE_BNXT_PMD
13724         if (ret == -ENOTSUP)
13725                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13726                         res->vlan_id);
13727 #endif
13728
13729         switch (ret) {
13730         case 0:
13731                 break;
13732         case -EINVAL:
13733                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13734                 break;
13735         case -ENODEV:
13736                 printf("invalid port_id %d\n", res->port_id);
13737                 break;
13738         case -ENOTSUP:
13739                 printf("function not implemented\n");
13740                 break;
13741         default:
13742                 printf("programming error: (%s)\n", strerror(-ret));
13743         }
13744 }
13745
13746 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13747         .f = cmd_set_vf_vlan_insert_parsed,
13748         .data = NULL,
13749         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13750         .tokens = {
13751                 (void *)&cmd_vf_vlan_insert_set,
13752                 (void *)&cmd_vf_vlan_insert_vf,
13753                 (void *)&cmd_vf_vlan_insert_vlan,
13754                 (void *)&cmd_vf_vlan_insert_insert,
13755                 (void *)&cmd_vf_vlan_insert_port_id,
13756                 (void *)&cmd_vf_vlan_insert_vf_id,
13757                 (void *)&cmd_vf_vlan_insert_vlan_id,
13758                 NULL,
13759         },
13760 };
13761
13762 /* tx loopback configuration */
13763
13764 /* Common result structure for tx loopback */
13765 struct cmd_tx_loopback_result {
13766         cmdline_fixed_string_t set;
13767         cmdline_fixed_string_t tx;
13768         cmdline_fixed_string_t loopback;
13769         portid_t port_id;
13770         cmdline_fixed_string_t on_off;
13771 };
13772
13773 /* Common CLI fields for tx loopback enable disable */
13774 cmdline_parse_token_string_t cmd_tx_loopback_set =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_tx_loopback_result,
13777                  set, "set");
13778 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_tx_loopback_result,
13781                  tx, "tx");
13782 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13783         TOKEN_STRING_INITIALIZER
13784                 (struct cmd_tx_loopback_result,
13785                  loopback, "loopback");
13786 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13787         TOKEN_NUM_INITIALIZER
13788                 (struct cmd_tx_loopback_result,
13789                  port_id, UINT16);
13790 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13791         TOKEN_STRING_INITIALIZER
13792                 (struct cmd_tx_loopback_result,
13793                  on_off, "on#off");
13794
13795 static void
13796 cmd_set_tx_loopback_parsed(
13797         void *parsed_result,
13798         __attribute__((unused)) struct cmdline *cl,
13799         __attribute__((unused)) void *data)
13800 {
13801         struct cmd_tx_loopback_result *res = parsed_result;
13802         int ret = -ENOTSUP;
13803
13804         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13805
13806         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13807                 return;
13808
13809 #ifdef RTE_LIBRTE_IXGBE_PMD
13810         if (ret == -ENOTSUP)
13811                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13812 #endif
13813 #ifdef RTE_LIBRTE_I40E_PMD
13814         if (ret == -ENOTSUP)
13815                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13816 #endif
13817 #ifdef RTE_LIBRTE_BNXT_PMD
13818         if (ret == -ENOTSUP)
13819                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13820 #endif
13821 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13822         if (ret == -ENOTSUP)
13823                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13824 #endif
13825
13826         switch (ret) {
13827         case 0:
13828                 break;
13829         case -EINVAL:
13830                 printf("invalid is_on %d\n", is_on);
13831                 break;
13832         case -ENODEV:
13833                 printf("invalid port_id %d\n", res->port_id);
13834                 break;
13835         case -ENOTSUP:
13836                 printf("function not implemented\n");
13837                 break;
13838         default:
13839                 printf("programming error: (%s)\n", strerror(-ret));
13840         }
13841 }
13842
13843 cmdline_parse_inst_t cmd_set_tx_loopback = {
13844         .f = cmd_set_tx_loopback_parsed,
13845         .data = NULL,
13846         .help_str = "set tx loopback <port_id> on|off",
13847         .tokens = {
13848                 (void *)&cmd_tx_loopback_set,
13849                 (void *)&cmd_tx_loopback_tx,
13850                 (void *)&cmd_tx_loopback_loopback,
13851                 (void *)&cmd_tx_loopback_port_id,
13852                 (void *)&cmd_tx_loopback_on_off,
13853                 NULL,
13854         },
13855 };
13856
13857 /* all queues drop enable configuration */
13858
13859 /* Common result structure for all queues drop enable */
13860 struct cmd_all_queues_drop_en_result {
13861         cmdline_fixed_string_t set;
13862         cmdline_fixed_string_t all;
13863         cmdline_fixed_string_t queues;
13864         cmdline_fixed_string_t drop;
13865         portid_t port_id;
13866         cmdline_fixed_string_t on_off;
13867 };
13868
13869 /* Common CLI fields for tx loopback enable disable */
13870 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13871         TOKEN_STRING_INITIALIZER
13872                 (struct cmd_all_queues_drop_en_result,
13873                  set, "set");
13874 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13875         TOKEN_STRING_INITIALIZER
13876                 (struct cmd_all_queues_drop_en_result,
13877                  all, "all");
13878 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13879         TOKEN_STRING_INITIALIZER
13880                 (struct cmd_all_queues_drop_en_result,
13881                  queues, "queues");
13882 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13883         TOKEN_STRING_INITIALIZER
13884                 (struct cmd_all_queues_drop_en_result,
13885                  drop, "drop");
13886 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13887         TOKEN_NUM_INITIALIZER
13888                 (struct cmd_all_queues_drop_en_result,
13889                  port_id, UINT16);
13890 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13891         TOKEN_STRING_INITIALIZER
13892                 (struct cmd_all_queues_drop_en_result,
13893                  on_off, "on#off");
13894
13895 static void
13896 cmd_set_all_queues_drop_en_parsed(
13897         void *parsed_result,
13898         __attribute__((unused)) struct cmdline *cl,
13899         __attribute__((unused)) void *data)
13900 {
13901         struct cmd_all_queues_drop_en_result *res = parsed_result;
13902         int ret = -ENOTSUP;
13903         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13904
13905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13906                 return;
13907
13908 #ifdef RTE_LIBRTE_IXGBE_PMD
13909         if (ret == -ENOTSUP)
13910                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13911 #endif
13912 #ifdef RTE_LIBRTE_BNXT_PMD
13913         if (ret == -ENOTSUP)
13914                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13915 #endif
13916         switch (ret) {
13917         case 0:
13918                 break;
13919         case -EINVAL:
13920                 printf("invalid is_on %d\n", is_on);
13921                 break;
13922         case -ENODEV:
13923                 printf("invalid port_id %d\n", res->port_id);
13924                 break;
13925         case -ENOTSUP:
13926                 printf("function not implemented\n");
13927                 break;
13928         default:
13929                 printf("programming error: (%s)\n", strerror(-ret));
13930         }
13931 }
13932
13933 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13934         .f = cmd_set_all_queues_drop_en_parsed,
13935         .data = NULL,
13936         .help_str = "set all queues drop <port_id> on|off",
13937         .tokens = {
13938                 (void *)&cmd_all_queues_drop_en_set,
13939                 (void *)&cmd_all_queues_drop_en_all,
13940                 (void *)&cmd_all_queues_drop_en_queues,
13941                 (void *)&cmd_all_queues_drop_en_drop,
13942                 (void *)&cmd_all_queues_drop_en_port_id,
13943                 (void *)&cmd_all_queues_drop_en_on_off,
13944                 NULL,
13945         },
13946 };
13947
13948 /* vf split drop enable configuration */
13949
13950 /* Common result structure for vf split drop enable */
13951 struct cmd_vf_split_drop_en_result {
13952         cmdline_fixed_string_t set;
13953         cmdline_fixed_string_t vf;
13954         cmdline_fixed_string_t split;
13955         cmdline_fixed_string_t drop;
13956         portid_t port_id;
13957         uint16_t vf_id;
13958         cmdline_fixed_string_t on_off;
13959 };
13960
13961 /* Common CLI fields for vf split drop enable disable */
13962 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13963         TOKEN_STRING_INITIALIZER
13964                 (struct cmd_vf_split_drop_en_result,
13965                  set, "set");
13966 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13967         TOKEN_STRING_INITIALIZER
13968                 (struct cmd_vf_split_drop_en_result,
13969                  vf, "vf");
13970 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_vf_split_drop_en_result,
13973                  split, "split");
13974 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13975         TOKEN_STRING_INITIALIZER
13976                 (struct cmd_vf_split_drop_en_result,
13977                  drop, "drop");
13978 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13979         TOKEN_NUM_INITIALIZER
13980                 (struct cmd_vf_split_drop_en_result,
13981                  port_id, UINT16);
13982 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13983         TOKEN_NUM_INITIALIZER
13984                 (struct cmd_vf_split_drop_en_result,
13985                  vf_id, UINT16);
13986 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13987         TOKEN_STRING_INITIALIZER
13988                 (struct cmd_vf_split_drop_en_result,
13989                  on_off, "on#off");
13990
13991 static void
13992 cmd_set_vf_split_drop_en_parsed(
13993         void *parsed_result,
13994         __attribute__((unused)) struct cmdline *cl,
13995         __attribute__((unused)) void *data)
13996 {
13997         struct cmd_vf_split_drop_en_result *res = parsed_result;
13998         int ret = -ENOTSUP;
13999         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14000
14001         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14002                 return;
14003
14004 #ifdef RTE_LIBRTE_IXGBE_PMD
14005         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14006                         is_on);
14007 #endif
14008         switch (ret) {
14009         case 0:
14010                 break;
14011         case -EINVAL:
14012                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14013                 break;
14014         case -ENODEV:
14015                 printf("invalid port_id %d\n", res->port_id);
14016                 break;
14017         case -ENOTSUP:
14018                 printf("not supported on port %d\n", res->port_id);
14019                 break;
14020         default:
14021                 printf("programming error: (%s)\n", strerror(-ret));
14022         }
14023 }
14024
14025 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14026         .f = cmd_set_vf_split_drop_en_parsed,
14027         .data = NULL,
14028         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14029         .tokens = {
14030                 (void *)&cmd_vf_split_drop_en_set,
14031                 (void *)&cmd_vf_split_drop_en_vf,
14032                 (void *)&cmd_vf_split_drop_en_split,
14033                 (void *)&cmd_vf_split_drop_en_drop,
14034                 (void *)&cmd_vf_split_drop_en_port_id,
14035                 (void *)&cmd_vf_split_drop_en_vf_id,
14036                 (void *)&cmd_vf_split_drop_en_on_off,
14037                 NULL,
14038         },
14039 };
14040
14041 /* vf mac address configuration */
14042
14043 /* Common result structure for vf mac address */
14044 struct cmd_set_vf_mac_addr_result {
14045         cmdline_fixed_string_t set;
14046         cmdline_fixed_string_t vf;
14047         cmdline_fixed_string_t mac;
14048         cmdline_fixed_string_t addr;
14049         portid_t port_id;
14050         uint16_t vf_id;
14051         struct rte_ether_addr mac_addr;
14052
14053 };
14054
14055 /* Common CLI fields for vf split drop enable disable */
14056 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14057         TOKEN_STRING_INITIALIZER
14058                 (struct cmd_set_vf_mac_addr_result,
14059                  set, "set");
14060 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_set_vf_mac_addr_result,
14063                  vf, "vf");
14064 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_set_vf_mac_addr_result,
14067                  mac, "mac");
14068 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14069         TOKEN_STRING_INITIALIZER
14070                 (struct cmd_set_vf_mac_addr_result,
14071                  addr, "addr");
14072 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14073         TOKEN_NUM_INITIALIZER
14074                 (struct cmd_set_vf_mac_addr_result,
14075                  port_id, UINT16);
14076 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14077         TOKEN_NUM_INITIALIZER
14078                 (struct cmd_set_vf_mac_addr_result,
14079                  vf_id, UINT16);
14080 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14081         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14082                  mac_addr);
14083
14084 static void
14085 cmd_set_vf_mac_addr_parsed(
14086         void *parsed_result,
14087         __attribute__((unused)) struct cmdline *cl,
14088         __attribute__((unused)) void *data)
14089 {
14090         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14091         int ret = -ENOTSUP;
14092
14093         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14094                 return;
14095
14096 #ifdef RTE_LIBRTE_IXGBE_PMD
14097         if (ret == -ENOTSUP)
14098                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14099                                 &res->mac_addr);
14100 #endif
14101 #ifdef RTE_LIBRTE_I40E_PMD
14102         if (ret == -ENOTSUP)
14103                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14104                                 &res->mac_addr);
14105 #endif
14106 #ifdef RTE_LIBRTE_BNXT_PMD
14107         if (ret == -ENOTSUP)
14108                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14109                                 &res->mac_addr);
14110 #endif
14111
14112         switch (ret) {
14113         case 0:
14114                 break;
14115         case -EINVAL:
14116                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14117                 break;
14118         case -ENODEV:
14119                 printf("invalid port_id %d\n", res->port_id);
14120                 break;
14121         case -ENOTSUP:
14122                 printf("function not implemented\n");
14123                 break;
14124         default:
14125                 printf("programming error: (%s)\n", strerror(-ret));
14126         }
14127 }
14128
14129 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14130         .f = cmd_set_vf_mac_addr_parsed,
14131         .data = NULL,
14132         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14133         .tokens = {
14134                 (void *)&cmd_set_vf_mac_addr_set,
14135                 (void *)&cmd_set_vf_mac_addr_vf,
14136                 (void *)&cmd_set_vf_mac_addr_mac,
14137                 (void *)&cmd_set_vf_mac_addr_addr,
14138                 (void *)&cmd_set_vf_mac_addr_port_id,
14139                 (void *)&cmd_set_vf_mac_addr_vf_id,
14140                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14141                 NULL,
14142         },
14143 };
14144
14145 /* MACsec configuration */
14146
14147 /* Common result structure for MACsec offload enable */
14148 struct cmd_macsec_offload_on_result {
14149         cmdline_fixed_string_t set;
14150         cmdline_fixed_string_t macsec;
14151         cmdline_fixed_string_t offload;
14152         portid_t port_id;
14153         cmdline_fixed_string_t on;
14154         cmdline_fixed_string_t encrypt;
14155         cmdline_fixed_string_t en_on_off;
14156         cmdline_fixed_string_t replay_protect;
14157         cmdline_fixed_string_t rp_on_off;
14158 };
14159
14160 /* Common CLI fields for MACsec offload disable */
14161 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14162         TOKEN_STRING_INITIALIZER
14163                 (struct cmd_macsec_offload_on_result,
14164                  set, "set");
14165 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14166         TOKEN_STRING_INITIALIZER
14167                 (struct cmd_macsec_offload_on_result,
14168                  macsec, "macsec");
14169 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14170         TOKEN_STRING_INITIALIZER
14171                 (struct cmd_macsec_offload_on_result,
14172                  offload, "offload");
14173 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14174         TOKEN_NUM_INITIALIZER
14175                 (struct cmd_macsec_offload_on_result,
14176                  port_id, UINT16);
14177 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14178         TOKEN_STRING_INITIALIZER
14179                 (struct cmd_macsec_offload_on_result,
14180                  on, "on");
14181 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14182         TOKEN_STRING_INITIALIZER
14183                 (struct cmd_macsec_offload_on_result,
14184                  encrypt, "encrypt");
14185 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14186         TOKEN_STRING_INITIALIZER
14187                 (struct cmd_macsec_offload_on_result,
14188                  en_on_off, "on#off");
14189 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14190         TOKEN_STRING_INITIALIZER
14191                 (struct cmd_macsec_offload_on_result,
14192                  replay_protect, "replay-protect");
14193 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14194         TOKEN_STRING_INITIALIZER
14195                 (struct cmd_macsec_offload_on_result,
14196                  rp_on_off, "on#off");
14197
14198 static void
14199 cmd_set_macsec_offload_on_parsed(
14200         void *parsed_result,
14201         __attribute__((unused)) struct cmdline *cl,
14202         __attribute__((unused)) void *data)
14203 {
14204         struct cmd_macsec_offload_on_result *res = parsed_result;
14205         int ret = -ENOTSUP;
14206         portid_t port_id = res->port_id;
14207         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14208         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14209         struct rte_eth_dev_info dev_info;
14210
14211         if (port_id_is_invalid(port_id, ENABLED_WARN))
14212                 return;
14213         if (!port_is_stopped(port_id)) {
14214                 printf("Please stop port %d first\n", port_id);
14215                 return;
14216         }
14217
14218         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14219         if (ret != 0)
14220                 return;
14221
14222         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14223 #ifdef RTE_LIBRTE_IXGBE_PMD
14224                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14225 #endif
14226         }
14227         RTE_SET_USED(en);
14228         RTE_SET_USED(rp);
14229
14230         switch (ret) {
14231         case 0:
14232                 ports[port_id].dev_conf.txmode.offloads |=
14233                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14234                 cmd_reconfig_device_queue(port_id, 1, 1);
14235                 break;
14236         case -ENODEV:
14237                 printf("invalid port_id %d\n", port_id);
14238                 break;
14239         case -ENOTSUP:
14240                 printf("not supported on port %d\n", port_id);
14241                 break;
14242         default:
14243                 printf("programming error: (%s)\n", strerror(-ret));
14244         }
14245 }
14246
14247 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14248         .f = cmd_set_macsec_offload_on_parsed,
14249         .data = NULL,
14250         .help_str = "set macsec offload <port_id> on "
14251                 "encrypt on|off replay-protect on|off",
14252         .tokens = {
14253                 (void *)&cmd_macsec_offload_on_set,
14254                 (void *)&cmd_macsec_offload_on_macsec,
14255                 (void *)&cmd_macsec_offload_on_offload,
14256                 (void *)&cmd_macsec_offload_on_port_id,
14257                 (void *)&cmd_macsec_offload_on_on,
14258                 (void *)&cmd_macsec_offload_on_encrypt,
14259                 (void *)&cmd_macsec_offload_on_en_on_off,
14260                 (void *)&cmd_macsec_offload_on_replay_protect,
14261                 (void *)&cmd_macsec_offload_on_rp_on_off,
14262                 NULL,
14263         },
14264 };
14265
14266 /* Common result structure for MACsec offload disable */
14267 struct cmd_macsec_offload_off_result {
14268         cmdline_fixed_string_t set;
14269         cmdline_fixed_string_t macsec;
14270         cmdline_fixed_string_t offload;
14271         portid_t port_id;
14272         cmdline_fixed_string_t off;
14273 };
14274
14275 /* Common CLI fields for MACsec offload disable */
14276 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14277         TOKEN_STRING_INITIALIZER
14278                 (struct cmd_macsec_offload_off_result,
14279                  set, "set");
14280 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14281         TOKEN_STRING_INITIALIZER
14282                 (struct cmd_macsec_offload_off_result,
14283                  macsec, "macsec");
14284 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14285         TOKEN_STRING_INITIALIZER
14286                 (struct cmd_macsec_offload_off_result,
14287                  offload, "offload");
14288 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14289         TOKEN_NUM_INITIALIZER
14290                 (struct cmd_macsec_offload_off_result,
14291                  port_id, UINT16);
14292 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14293         TOKEN_STRING_INITIALIZER
14294                 (struct cmd_macsec_offload_off_result,
14295                  off, "off");
14296
14297 static void
14298 cmd_set_macsec_offload_off_parsed(
14299         void *parsed_result,
14300         __attribute__((unused)) struct cmdline *cl,
14301         __attribute__((unused)) void *data)
14302 {
14303         struct cmd_macsec_offload_off_result *res = parsed_result;
14304         int ret = -ENOTSUP;
14305         struct rte_eth_dev_info dev_info;
14306         portid_t port_id = res->port_id;
14307
14308         if (port_id_is_invalid(port_id, ENABLED_WARN))
14309                 return;
14310         if (!port_is_stopped(port_id)) {
14311                 printf("Please stop port %d first\n", port_id);
14312                 return;
14313         }
14314
14315         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14316         if (ret != 0)
14317                 return;
14318
14319         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14320 #ifdef RTE_LIBRTE_IXGBE_PMD
14321                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14322 #endif
14323         }
14324         switch (ret) {
14325         case 0:
14326                 ports[port_id].dev_conf.txmode.offloads &=
14327                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14328                 cmd_reconfig_device_queue(port_id, 1, 1);
14329                 break;
14330         case -ENODEV:
14331                 printf("invalid port_id %d\n", port_id);
14332                 break;
14333         case -ENOTSUP:
14334                 printf("not supported on port %d\n", port_id);
14335                 break;
14336         default:
14337                 printf("programming error: (%s)\n", strerror(-ret));
14338         }
14339 }
14340
14341 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14342         .f = cmd_set_macsec_offload_off_parsed,
14343         .data = NULL,
14344         .help_str = "set macsec offload <port_id> off",
14345         .tokens = {
14346                 (void *)&cmd_macsec_offload_off_set,
14347                 (void *)&cmd_macsec_offload_off_macsec,
14348                 (void *)&cmd_macsec_offload_off_offload,
14349                 (void *)&cmd_macsec_offload_off_port_id,
14350                 (void *)&cmd_macsec_offload_off_off,
14351                 NULL,
14352         },
14353 };
14354
14355 /* Common result structure for MACsec secure connection configure */
14356 struct cmd_macsec_sc_result {
14357         cmdline_fixed_string_t set;
14358         cmdline_fixed_string_t macsec;
14359         cmdline_fixed_string_t sc;
14360         cmdline_fixed_string_t tx_rx;
14361         portid_t port_id;
14362         struct rte_ether_addr mac;
14363         uint16_t pi;
14364 };
14365
14366 /* Common CLI fields for MACsec secure connection configure */
14367 cmdline_parse_token_string_t cmd_macsec_sc_set =
14368         TOKEN_STRING_INITIALIZER
14369                 (struct cmd_macsec_sc_result,
14370                  set, "set");
14371 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14372         TOKEN_STRING_INITIALIZER
14373                 (struct cmd_macsec_sc_result,
14374                  macsec, "macsec");
14375 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14376         TOKEN_STRING_INITIALIZER
14377                 (struct cmd_macsec_sc_result,
14378                  sc, "sc");
14379 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14380         TOKEN_STRING_INITIALIZER
14381                 (struct cmd_macsec_sc_result,
14382                  tx_rx, "tx#rx");
14383 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14384         TOKEN_NUM_INITIALIZER
14385                 (struct cmd_macsec_sc_result,
14386                  port_id, UINT16);
14387 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14388         TOKEN_ETHERADDR_INITIALIZER
14389                 (struct cmd_macsec_sc_result,
14390                  mac);
14391 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14392         TOKEN_NUM_INITIALIZER
14393                 (struct cmd_macsec_sc_result,
14394                  pi, UINT16);
14395
14396 static void
14397 cmd_set_macsec_sc_parsed(
14398         void *parsed_result,
14399         __attribute__((unused)) struct cmdline *cl,
14400         __attribute__((unused)) void *data)
14401 {
14402         struct cmd_macsec_sc_result *res = parsed_result;
14403         int ret = -ENOTSUP;
14404         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14405
14406 #ifdef RTE_LIBRTE_IXGBE_PMD
14407         ret = is_tx ?
14408                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14409                                 res->mac.addr_bytes) :
14410                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14411                                 res->mac.addr_bytes, res->pi);
14412 #endif
14413         RTE_SET_USED(is_tx);
14414
14415         switch (ret) {
14416         case 0:
14417                 break;
14418         case -ENODEV:
14419                 printf("invalid port_id %d\n", res->port_id);
14420                 break;
14421         case -ENOTSUP:
14422                 printf("not supported on port %d\n", res->port_id);
14423                 break;
14424         default:
14425                 printf("programming error: (%s)\n", strerror(-ret));
14426         }
14427 }
14428
14429 cmdline_parse_inst_t cmd_set_macsec_sc = {
14430         .f = cmd_set_macsec_sc_parsed,
14431         .data = NULL,
14432         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14433         .tokens = {
14434                 (void *)&cmd_macsec_sc_set,
14435                 (void *)&cmd_macsec_sc_macsec,
14436                 (void *)&cmd_macsec_sc_sc,
14437                 (void *)&cmd_macsec_sc_tx_rx,
14438                 (void *)&cmd_macsec_sc_port_id,
14439                 (void *)&cmd_macsec_sc_mac,
14440                 (void *)&cmd_macsec_sc_pi,
14441                 NULL,
14442         },
14443 };
14444
14445 /* Common result structure for MACsec secure connection configure */
14446 struct cmd_macsec_sa_result {
14447         cmdline_fixed_string_t set;
14448         cmdline_fixed_string_t macsec;
14449         cmdline_fixed_string_t sa;
14450         cmdline_fixed_string_t tx_rx;
14451         portid_t port_id;
14452         uint8_t idx;
14453         uint8_t an;
14454         uint32_t pn;
14455         cmdline_fixed_string_t key;
14456 };
14457
14458 /* Common CLI fields for MACsec secure connection configure */
14459 cmdline_parse_token_string_t cmd_macsec_sa_set =
14460         TOKEN_STRING_INITIALIZER
14461                 (struct cmd_macsec_sa_result,
14462                  set, "set");
14463 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14464         TOKEN_STRING_INITIALIZER
14465                 (struct cmd_macsec_sa_result,
14466                  macsec, "macsec");
14467 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14468         TOKEN_STRING_INITIALIZER
14469                 (struct cmd_macsec_sa_result,
14470                  sa, "sa");
14471 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14472         TOKEN_STRING_INITIALIZER
14473                 (struct cmd_macsec_sa_result,
14474                  tx_rx, "tx#rx");
14475 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14476         TOKEN_NUM_INITIALIZER
14477                 (struct cmd_macsec_sa_result,
14478                  port_id, UINT16);
14479 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14480         TOKEN_NUM_INITIALIZER
14481                 (struct cmd_macsec_sa_result,
14482                  idx, UINT8);
14483 cmdline_parse_token_num_t cmd_macsec_sa_an =
14484         TOKEN_NUM_INITIALIZER
14485                 (struct cmd_macsec_sa_result,
14486                  an, UINT8);
14487 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14488         TOKEN_NUM_INITIALIZER
14489                 (struct cmd_macsec_sa_result,
14490                  pn, UINT32);
14491 cmdline_parse_token_string_t cmd_macsec_sa_key =
14492         TOKEN_STRING_INITIALIZER
14493                 (struct cmd_macsec_sa_result,
14494                  key, NULL);
14495
14496 static void
14497 cmd_set_macsec_sa_parsed(
14498         void *parsed_result,
14499         __attribute__((unused)) struct cmdline *cl,
14500         __attribute__((unused)) void *data)
14501 {
14502         struct cmd_macsec_sa_result *res = parsed_result;
14503         int ret = -ENOTSUP;
14504         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14505         uint8_t key[16] = { 0 };
14506         uint8_t xdgt0;
14507         uint8_t xdgt1;
14508         int key_len;
14509         int i;
14510
14511         key_len = strlen(res->key) / 2;
14512         if (key_len > 16)
14513                 key_len = 16;
14514
14515         for (i = 0; i < key_len; i++) {
14516                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14517                 if (xdgt0 == 0xFF)
14518                         return;
14519                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14520                 if (xdgt1 == 0xFF)
14521                         return;
14522                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14523         }
14524
14525 #ifdef RTE_LIBRTE_IXGBE_PMD
14526         ret = is_tx ?
14527                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14528                         res->idx, res->an, res->pn, key) :
14529                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14530                         res->idx, res->an, res->pn, key);
14531 #endif
14532         RTE_SET_USED(is_tx);
14533         RTE_SET_USED(key);
14534
14535         switch (ret) {
14536         case 0:
14537                 break;
14538         case -EINVAL:
14539                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14540                 break;
14541         case -ENODEV:
14542                 printf("invalid port_id %d\n", res->port_id);
14543                 break;
14544         case -ENOTSUP:
14545                 printf("not supported on port %d\n", res->port_id);
14546                 break;
14547         default:
14548                 printf("programming error: (%s)\n", strerror(-ret));
14549         }
14550 }
14551
14552 cmdline_parse_inst_t cmd_set_macsec_sa = {
14553         .f = cmd_set_macsec_sa_parsed,
14554         .data = NULL,
14555         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14556         .tokens = {
14557                 (void *)&cmd_macsec_sa_set,
14558                 (void *)&cmd_macsec_sa_macsec,
14559                 (void *)&cmd_macsec_sa_sa,
14560                 (void *)&cmd_macsec_sa_tx_rx,
14561                 (void *)&cmd_macsec_sa_port_id,
14562                 (void *)&cmd_macsec_sa_idx,
14563                 (void *)&cmd_macsec_sa_an,
14564                 (void *)&cmd_macsec_sa_pn,
14565                 (void *)&cmd_macsec_sa_key,
14566                 NULL,
14567         },
14568 };
14569
14570 /* VF unicast promiscuous mode configuration */
14571
14572 /* Common result structure for VF unicast promiscuous mode */
14573 struct cmd_vf_promisc_result {
14574         cmdline_fixed_string_t set;
14575         cmdline_fixed_string_t vf;
14576         cmdline_fixed_string_t promisc;
14577         portid_t port_id;
14578         uint32_t vf_id;
14579         cmdline_fixed_string_t on_off;
14580 };
14581
14582 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14583 cmdline_parse_token_string_t cmd_vf_promisc_set =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_vf_promisc_result,
14586                  set, "set");
14587 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14588         TOKEN_STRING_INITIALIZER
14589                 (struct cmd_vf_promisc_result,
14590                  vf, "vf");
14591 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14592         TOKEN_STRING_INITIALIZER
14593                 (struct cmd_vf_promisc_result,
14594                  promisc, "promisc");
14595 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14596         TOKEN_NUM_INITIALIZER
14597                 (struct cmd_vf_promisc_result,
14598                  port_id, UINT16);
14599 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14600         TOKEN_NUM_INITIALIZER
14601                 (struct cmd_vf_promisc_result,
14602                  vf_id, UINT32);
14603 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14604         TOKEN_STRING_INITIALIZER
14605                 (struct cmd_vf_promisc_result,
14606                  on_off, "on#off");
14607
14608 static void
14609 cmd_set_vf_promisc_parsed(
14610         void *parsed_result,
14611         __attribute__((unused)) struct cmdline *cl,
14612         __attribute__((unused)) void *data)
14613 {
14614         struct cmd_vf_promisc_result *res = parsed_result;
14615         int ret = -ENOTSUP;
14616
14617         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14618
14619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14620                 return;
14621
14622 #ifdef RTE_LIBRTE_I40E_PMD
14623         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14624                                                   res->vf_id, is_on);
14625 #endif
14626
14627         switch (ret) {
14628         case 0:
14629                 break;
14630         case -EINVAL:
14631                 printf("invalid vf_id %d\n", res->vf_id);
14632                 break;
14633         case -ENODEV:
14634                 printf("invalid port_id %d\n", res->port_id);
14635                 break;
14636         case -ENOTSUP:
14637                 printf("function not implemented\n");
14638                 break;
14639         default:
14640                 printf("programming error: (%s)\n", strerror(-ret));
14641         }
14642 }
14643
14644 cmdline_parse_inst_t cmd_set_vf_promisc = {
14645         .f = cmd_set_vf_promisc_parsed,
14646         .data = NULL,
14647         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14648                 "Set unicast promiscuous mode for a VF from the PF",
14649         .tokens = {
14650                 (void *)&cmd_vf_promisc_set,
14651                 (void *)&cmd_vf_promisc_vf,
14652                 (void *)&cmd_vf_promisc_promisc,
14653                 (void *)&cmd_vf_promisc_port_id,
14654                 (void *)&cmd_vf_promisc_vf_id,
14655                 (void *)&cmd_vf_promisc_on_off,
14656                 NULL,
14657         },
14658 };
14659
14660 /* VF multicast promiscuous mode configuration */
14661
14662 /* Common result structure for VF multicast promiscuous mode */
14663 struct cmd_vf_allmulti_result {
14664         cmdline_fixed_string_t set;
14665         cmdline_fixed_string_t vf;
14666         cmdline_fixed_string_t allmulti;
14667         portid_t port_id;
14668         uint32_t vf_id;
14669         cmdline_fixed_string_t on_off;
14670 };
14671
14672 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14673 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14674         TOKEN_STRING_INITIALIZER
14675                 (struct cmd_vf_allmulti_result,
14676                  set, "set");
14677 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14678         TOKEN_STRING_INITIALIZER
14679                 (struct cmd_vf_allmulti_result,
14680                  vf, "vf");
14681 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14682         TOKEN_STRING_INITIALIZER
14683                 (struct cmd_vf_allmulti_result,
14684                  allmulti, "allmulti");
14685 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14686         TOKEN_NUM_INITIALIZER
14687                 (struct cmd_vf_allmulti_result,
14688                  port_id, UINT16);
14689 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14690         TOKEN_NUM_INITIALIZER
14691                 (struct cmd_vf_allmulti_result,
14692                  vf_id, UINT32);
14693 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14694         TOKEN_STRING_INITIALIZER
14695                 (struct cmd_vf_allmulti_result,
14696                  on_off, "on#off");
14697
14698 static void
14699 cmd_set_vf_allmulti_parsed(
14700         void *parsed_result,
14701         __attribute__((unused)) struct cmdline *cl,
14702         __attribute__((unused)) void *data)
14703 {
14704         struct cmd_vf_allmulti_result *res = parsed_result;
14705         int ret = -ENOTSUP;
14706
14707         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14708
14709         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14710                 return;
14711
14712 #ifdef RTE_LIBRTE_I40E_PMD
14713         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14714                                                     res->vf_id, is_on);
14715 #endif
14716
14717         switch (ret) {
14718         case 0:
14719                 break;
14720         case -EINVAL:
14721                 printf("invalid vf_id %d\n", res->vf_id);
14722                 break;
14723         case -ENODEV:
14724                 printf("invalid port_id %d\n", res->port_id);
14725                 break;
14726         case -ENOTSUP:
14727                 printf("function not implemented\n");
14728                 break;
14729         default:
14730                 printf("programming error: (%s)\n", strerror(-ret));
14731         }
14732 }
14733
14734 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14735         .f = cmd_set_vf_allmulti_parsed,
14736         .data = NULL,
14737         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14738                 "Set multicast promiscuous mode for a VF from the PF",
14739         .tokens = {
14740                 (void *)&cmd_vf_allmulti_set,
14741                 (void *)&cmd_vf_allmulti_vf,
14742                 (void *)&cmd_vf_allmulti_allmulti,
14743                 (void *)&cmd_vf_allmulti_port_id,
14744                 (void *)&cmd_vf_allmulti_vf_id,
14745                 (void *)&cmd_vf_allmulti_on_off,
14746                 NULL,
14747         },
14748 };
14749
14750 /* vf broadcast mode configuration */
14751
14752 /* Common result structure for vf broadcast */
14753 struct cmd_set_vf_broadcast_result {
14754         cmdline_fixed_string_t set;
14755         cmdline_fixed_string_t vf;
14756         cmdline_fixed_string_t broadcast;
14757         portid_t port_id;
14758         uint16_t vf_id;
14759         cmdline_fixed_string_t on_off;
14760 };
14761
14762 /* Common CLI fields for vf broadcast enable disable */
14763 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14764         TOKEN_STRING_INITIALIZER
14765                 (struct cmd_set_vf_broadcast_result,
14766                  set, "set");
14767 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14768         TOKEN_STRING_INITIALIZER
14769                 (struct cmd_set_vf_broadcast_result,
14770                  vf, "vf");
14771 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_set_vf_broadcast_result,
14774                  broadcast, "broadcast");
14775 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14776         TOKEN_NUM_INITIALIZER
14777                 (struct cmd_set_vf_broadcast_result,
14778                  port_id, UINT16);
14779 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14780         TOKEN_NUM_INITIALIZER
14781                 (struct cmd_set_vf_broadcast_result,
14782                  vf_id, UINT16);
14783 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14784         TOKEN_STRING_INITIALIZER
14785                 (struct cmd_set_vf_broadcast_result,
14786                  on_off, "on#off");
14787
14788 static void
14789 cmd_set_vf_broadcast_parsed(
14790         void *parsed_result,
14791         __attribute__((unused)) struct cmdline *cl,
14792         __attribute__((unused)) void *data)
14793 {
14794         struct cmd_set_vf_broadcast_result *res = parsed_result;
14795         int ret = -ENOTSUP;
14796
14797         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14798
14799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14800                 return;
14801
14802 #ifdef RTE_LIBRTE_I40E_PMD
14803         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14804                                             res->vf_id, is_on);
14805 #endif
14806
14807         switch (ret) {
14808         case 0:
14809                 break;
14810         case -EINVAL:
14811                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14812                 break;
14813         case -ENODEV:
14814                 printf("invalid port_id %d\n", res->port_id);
14815                 break;
14816         case -ENOTSUP:
14817                 printf("function not implemented\n");
14818                 break;
14819         default:
14820                 printf("programming error: (%s)\n", strerror(-ret));
14821         }
14822 }
14823
14824 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14825         .f = cmd_set_vf_broadcast_parsed,
14826         .data = NULL,
14827         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14828         .tokens = {
14829                 (void *)&cmd_set_vf_broadcast_set,
14830                 (void *)&cmd_set_vf_broadcast_vf,
14831                 (void *)&cmd_set_vf_broadcast_broadcast,
14832                 (void *)&cmd_set_vf_broadcast_port_id,
14833                 (void *)&cmd_set_vf_broadcast_vf_id,
14834                 (void *)&cmd_set_vf_broadcast_on_off,
14835                 NULL,
14836         },
14837 };
14838
14839 /* vf vlan tag configuration */
14840
14841 /* Common result structure for vf vlan tag */
14842 struct cmd_set_vf_vlan_tag_result {
14843         cmdline_fixed_string_t set;
14844         cmdline_fixed_string_t vf;
14845         cmdline_fixed_string_t vlan;
14846         cmdline_fixed_string_t tag;
14847         portid_t port_id;
14848         uint16_t vf_id;
14849         cmdline_fixed_string_t on_off;
14850 };
14851
14852 /* Common CLI fields for vf vlan tag enable disable */
14853 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14854         TOKEN_STRING_INITIALIZER
14855                 (struct cmd_set_vf_vlan_tag_result,
14856                  set, "set");
14857 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_set_vf_vlan_tag_result,
14860                  vf, "vf");
14861 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_set_vf_vlan_tag_result,
14864                  vlan, "vlan");
14865 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_set_vf_vlan_tag_result,
14868                  tag, "tag");
14869 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14870         TOKEN_NUM_INITIALIZER
14871                 (struct cmd_set_vf_vlan_tag_result,
14872                  port_id, UINT16);
14873 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14874         TOKEN_NUM_INITIALIZER
14875                 (struct cmd_set_vf_vlan_tag_result,
14876                  vf_id, UINT16);
14877 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14878         TOKEN_STRING_INITIALIZER
14879                 (struct cmd_set_vf_vlan_tag_result,
14880                  on_off, "on#off");
14881
14882 static void
14883 cmd_set_vf_vlan_tag_parsed(
14884         void *parsed_result,
14885         __attribute__((unused)) struct cmdline *cl,
14886         __attribute__((unused)) void *data)
14887 {
14888         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14889         int ret = -ENOTSUP;
14890
14891         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14892
14893         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14894                 return;
14895
14896 #ifdef RTE_LIBRTE_I40E_PMD
14897         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14898                                            res->vf_id, is_on);
14899 #endif
14900
14901         switch (ret) {
14902         case 0:
14903                 break;
14904         case -EINVAL:
14905                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14906                 break;
14907         case -ENODEV:
14908                 printf("invalid port_id %d\n", res->port_id);
14909                 break;
14910         case -ENOTSUP:
14911                 printf("function not implemented\n");
14912                 break;
14913         default:
14914                 printf("programming error: (%s)\n", strerror(-ret));
14915         }
14916 }
14917
14918 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14919         .f = cmd_set_vf_vlan_tag_parsed,
14920         .data = NULL,
14921         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14922         .tokens = {
14923                 (void *)&cmd_set_vf_vlan_tag_set,
14924                 (void *)&cmd_set_vf_vlan_tag_vf,
14925                 (void *)&cmd_set_vf_vlan_tag_vlan,
14926                 (void *)&cmd_set_vf_vlan_tag_tag,
14927                 (void *)&cmd_set_vf_vlan_tag_port_id,
14928                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14929                 (void *)&cmd_set_vf_vlan_tag_on_off,
14930                 NULL,
14931         },
14932 };
14933
14934 /* Common definition of VF and TC TX bandwidth configuration */
14935 struct cmd_vf_tc_bw_result {
14936         cmdline_fixed_string_t set;
14937         cmdline_fixed_string_t vf;
14938         cmdline_fixed_string_t tc;
14939         cmdline_fixed_string_t tx;
14940         cmdline_fixed_string_t min_bw;
14941         cmdline_fixed_string_t max_bw;
14942         cmdline_fixed_string_t strict_link_prio;
14943         portid_t port_id;
14944         uint16_t vf_id;
14945         uint8_t tc_no;
14946         uint32_t bw;
14947         cmdline_fixed_string_t bw_list;
14948         uint8_t tc_map;
14949 };
14950
14951 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14952         TOKEN_STRING_INITIALIZER
14953                 (struct cmd_vf_tc_bw_result,
14954                  set, "set");
14955 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14956         TOKEN_STRING_INITIALIZER
14957                 (struct cmd_vf_tc_bw_result,
14958                  vf, "vf");
14959 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14960         TOKEN_STRING_INITIALIZER
14961                 (struct cmd_vf_tc_bw_result,
14962                  tc, "tc");
14963 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_vf_tc_bw_result,
14966                  tx, "tx");
14967 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14968         TOKEN_STRING_INITIALIZER
14969                 (struct cmd_vf_tc_bw_result,
14970                  strict_link_prio, "strict-link-priority");
14971 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14972         TOKEN_STRING_INITIALIZER
14973                 (struct cmd_vf_tc_bw_result,
14974                  min_bw, "min-bandwidth");
14975 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14976         TOKEN_STRING_INITIALIZER
14977                 (struct cmd_vf_tc_bw_result,
14978                  max_bw, "max-bandwidth");
14979 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14980         TOKEN_NUM_INITIALIZER
14981                 (struct cmd_vf_tc_bw_result,
14982                  port_id, UINT16);
14983 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14984         TOKEN_NUM_INITIALIZER
14985                 (struct cmd_vf_tc_bw_result,
14986                  vf_id, UINT16);
14987 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14988         TOKEN_NUM_INITIALIZER
14989                 (struct cmd_vf_tc_bw_result,
14990                  tc_no, UINT8);
14991 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14992         TOKEN_NUM_INITIALIZER
14993                 (struct cmd_vf_tc_bw_result,
14994                  bw, UINT32);
14995 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14996         TOKEN_STRING_INITIALIZER
14997                 (struct cmd_vf_tc_bw_result,
14998                  bw_list, NULL);
14999 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15000         TOKEN_NUM_INITIALIZER
15001                 (struct cmd_vf_tc_bw_result,
15002                  tc_map, UINT8);
15003
15004 /* VF max bandwidth setting */
15005 static void
15006 cmd_vf_max_bw_parsed(
15007         void *parsed_result,
15008         __attribute__((unused)) struct cmdline *cl,
15009         __attribute__((unused)) void *data)
15010 {
15011         struct cmd_vf_tc_bw_result *res = parsed_result;
15012         int ret = -ENOTSUP;
15013
15014         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15015                 return;
15016
15017 #ifdef RTE_LIBRTE_I40E_PMD
15018         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15019                                          res->vf_id, res->bw);
15020 #endif
15021
15022         switch (ret) {
15023         case 0:
15024                 break;
15025         case -EINVAL:
15026                 printf("invalid vf_id %d or bandwidth %d\n",
15027                        res->vf_id, res->bw);
15028                 break;
15029         case -ENODEV:
15030                 printf("invalid port_id %d\n", res->port_id);
15031                 break;
15032         case -ENOTSUP:
15033                 printf("function not implemented\n");
15034                 break;
15035         default:
15036                 printf("programming error: (%s)\n", strerror(-ret));
15037         }
15038 }
15039
15040 cmdline_parse_inst_t cmd_vf_max_bw = {
15041         .f = cmd_vf_max_bw_parsed,
15042         .data = NULL,
15043         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15044         .tokens = {
15045                 (void *)&cmd_vf_tc_bw_set,
15046                 (void *)&cmd_vf_tc_bw_vf,
15047                 (void *)&cmd_vf_tc_bw_tx,
15048                 (void *)&cmd_vf_tc_bw_max_bw,
15049                 (void *)&cmd_vf_tc_bw_port_id,
15050                 (void *)&cmd_vf_tc_bw_vf_id,
15051                 (void *)&cmd_vf_tc_bw_bw,
15052                 NULL,
15053         },
15054 };
15055
15056 static int
15057 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15058                            uint8_t *tc_num,
15059                            char *str)
15060 {
15061         uint32_t size;
15062         const char *p, *p0 = str;
15063         char s[256];
15064         char *end;
15065         char *str_fld[16];
15066         uint16_t i;
15067         int ret;
15068
15069         p = strchr(p0, '(');
15070         if (p == NULL) {
15071                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15072                 return -1;
15073         }
15074         p++;
15075         p0 = strchr(p, ')');
15076         if (p0 == NULL) {
15077                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15078                 return -1;
15079         }
15080         size = p0 - p;
15081         if (size >= sizeof(s)) {
15082                 printf("The string size exceeds the internal buffer size\n");
15083                 return -1;
15084         }
15085         snprintf(s, sizeof(s), "%.*s", size, p);
15086         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15087         if (ret <= 0) {
15088                 printf("Failed to get the bandwidth list. ");
15089                 return -1;
15090         }
15091         *tc_num = ret;
15092         for (i = 0; i < ret; i++)
15093                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15094
15095         return 0;
15096 }
15097
15098 /* TC min bandwidth setting */
15099 static void
15100 cmd_vf_tc_min_bw_parsed(
15101         void *parsed_result,
15102         __attribute__((unused)) struct cmdline *cl,
15103         __attribute__((unused)) void *data)
15104 {
15105         struct cmd_vf_tc_bw_result *res = parsed_result;
15106         uint8_t tc_num;
15107         uint8_t bw[16];
15108         int ret = -ENOTSUP;
15109
15110         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15111                 return;
15112
15113         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15114         if (ret)
15115                 return;
15116
15117 #ifdef RTE_LIBRTE_I40E_PMD
15118         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15119                                               tc_num, bw);
15120 #endif
15121
15122         switch (ret) {
15123         case 0:
15124                 break;
15125         case -EINVAL:
15126                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15127                 break;
15128         case -ENODEV:
15129                 printf("invalid port_id %d\n", res->port_id);
15130                 break;
15131         case -ENOTSUP:
15132                 printf("function not implemented\n");
15133                 break;
15134         default:
15135                 printf("programming error: (%s)\n", strerror(-ret));
15136         }
15137 }
15138
15139 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15140         .f = cmd_vf_tc_min_bw_parsed,
15141         .data = NULL,
15142         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15143                     " <bw1, bw2, ...>",
15144         .tokens = {
15145                 (void *)&cmd_vf_tc_bw_set,
15146                 (void *)&cmd_vf_tc_bw_vf,
15147                 (void *)&cmd_vf_tc_bw_tc,
15148                 (void *)&cmd_vf_tc_bw_tx,
15149                 (void *)&cmd_vf_tc_bw_min_bw,
15150                 (void *)&cmd_vf_tc_bw_port_id,
15151                 (void *)&cmd_vf_tc_bw_vf_id,
15152                 (void *)&cmd_vf_tc_bw_bw_list,
15153                 NULL,
15154         },
15155 };
15156
15157 static void
15158 cmd_tc_min_bw_parsed(
15159         void *parsed_result,
15160         __attribute__((unused)) struct cmdline *cl,
15161         __attribute__((unused)) void *data)
15162 {
15163         struct cmd_vf_tc_bw_result *res = parsed_result;
15164         struct rte_port *port;
15165         uint8_t tc_num;
15166         uint8_t bw[16];
15167         int ret = -ENOTSUP;
15168
15169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15170                 return;
15171
15172         port = &ports[res->port_id];
15173         /** Check if the port is not started **/
15174         if (port->port_status != RTE_PORT_STOPPED) {
15175                 printf("Please stop port %d first\n", res->port_id);
15176                 return;
15177         }
15178
15179         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15180         if (ret)
15181                 return;
15182
15183 #ifdef RTE_LIBRTE_IXGBE_PMD
15184         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15185 #endif
15186
15187         switch (ret) {
15188         case 0:
15189                 break;
15190         case -EINVAL:
15191                 printf("invalid bandwidth\n");
15192                 break;
15193         case -ENODEV:
15194                 printf("invalid port_id %d\n", res->port_id);
15195                 break;
15196         case -ENOTSUP:
15197                 printf("function not implemented\n");
15198                 break;
15199         default:
15200                 printf("programming error: (%s)\n", strerror(-ret));
15201         }
15202 }
15203
15204 cmdline_parse_inst_t cmd_tc_min_bw = {
15205         .f = cmd_tc_min_bw_parsed,
15206         .data = NULL,
15207         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15208         .tokens = {
15209                 (void *)&cmd_vf_tc_bw_set,
15210                 (void *)&cmd_vf_tc_bw_tc,
15211                 (void *)&cmd_vf_tc_bw_tx,
15212                 (void *)&cmd_vf_tc_bw_min_bw,
15213                 (void *)&cmd_vf_tc_bw_port_id,
15214                 (void *)&cmd_vf_tc_bw_bw_list,
15215                 NULL,
15216         },
15217 };
15218
15219 /* TC max bandwidth setting */
15220 static void
15221 cmd_vf_tc_max_bw_parsed(
15222         void *parsed_result,
15223         __attribute__((unused)) struct cmdline *cl,
15224         __attribute__((unused)) void *data)
15225 {
15226         struct cmd_vf_tc_bw_result *res = parsed_result;
15227         int ret = -ENOTSUP;
15228
15229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15230                 return;
15231
15232 #ifdef RTE_LIBRTE_I40E_PMD
15233         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15234                                             res->tc_no, res->bw);
15235 #endif
15236
15237         switch (ret) {
15238         case 0:
15239                 break;
15240         case -EINVAL:
15241                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15242                        res->vf_id, res->tc_no, res->bw);
15243                 break;
15244         case -ENODEV:
15245                 printf("invalid port_id %d\n", res->port_id);
15246                 break;
15247         case -ENOTSUP:
15248                 printf("function not implemented\n");
15249                 break;
15250         default:
15251                 printf("programming error: (%s)\n", strerror(-ret));
15252         }
15253 }
15254
15255 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15256         .f = cmd_vf_tc_max_bw_parsed,
15257         .data = NULL,
15258         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15259                     " <bandwidth>",
15260         .tokens = {
15261                 (void *)&cmd_vf_tc_bw_set,
15262                 (void *)&cmd_vf_tc_bw_vf,
15263                 (void *)&cmd_vf_tc_bw_tc,
15264                 (void *)&cmd_vf_tc_bw_tx,
15265                 (void *)&cmd_vf_tc_bw_max_bw,
15266                 (void *)&cmd_vf_tc_bw_port_id,
15267                 (void *)&cmd_vf_tc_bw_vf_id,
15268                 (void *)&cmd_vf_tc_bw_tc_no,
15269                 (void *)&cmd_vf_tc_bw_bw,
15270                 NULL,
15271         },
15272 };
15273
15274
15275 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15276
15277 /* *** Set Port default Traffic Management Hierarchy *** */
15278 struct cmd_set_port_tm_hierarchy_default_result {
15279         cmdline_fixed_string_t set;
15280         cmdline_fixed_string_t port;
15281         cmdline_fixed_string_t tm;
15282         cmdline_fixed_string_t hierarchy;
15283         cmdline_fixed_string_t def;
15284         portid_t port_id;
15285 };
15286
15287 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15288         TOKEN_STRING_INITIALIZER(
15289                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15290 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15291         TOKEN_STRING_INITIALIZER(
15292                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15293 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15294         TOKEN_STRING_INITIALIZER(
15295                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15296 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15297         TOKEN_STRING_INITIALIZER(
15298                 struct cmd_set_port_tm_hierarchy_default_result,
15299                         hierarchy, "hierarchy");
15300 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15301         TOKEN_STRING_INITIALIZER(
15302                 struct cmd_set_port_tm_hierarchy_default_result,
15303                         def, "default");
15304 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15305         TOKEN_NUM_INITIALIZER(
15306                 struct cmd_set_port_tm_hierarchy_default_result,
15307                         port_id, UINT16);
15308
15309 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15310         __attribute__((unused)) struct cmdline *cl,
15311         __attribute__((unused)) void *data)
15312 {
15313         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15314         struct rte_port *p;
15315         portid_t port_id = res->port_id;
15316
15317         if (port_id_is_invalid(port_id, ENABLED_WARN))
15318                 return;
15319
15320         p = &ports[port_id];
15321
15322         /* Forward mode: tm */
15323         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15324                 printf("  softnicfwd mode not enabled(error)\n");
15325                 return;
15326         }
15327
15328         /* Set the default tm hierarchy */
15329         p->softport.default_tm_hierarchy_enable = 1;
15330 }
15331
15332 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15333         .f = cmd_set_port_tm_hierarchy_default_parsed,
15334         .data = NULL,
15335         .help_str = "set port tm hierarchy default <port_id>",
15336         .tokens = {
15337                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15338                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15339                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15340                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15341                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15342                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15343                 NULL,
15344         },
15345 };
15346 #endif
15347
15348 /** Set VXLAN encapsulation details */
15349 struct cmd_set_vxlan_result {
15350         cmdline_fixed_string_t set;
15351         cmdline_fixed_string_t vxlan;
15352         cmdline_fixed_string_t pos_token;
15353         cmdline_fixed_string_t ip_version;
15354         uint32_t vlan_present:1;
15355         uint32_t vni;
15356         uint16_t udp_src;
15357         uint16_t udp_dst;
15358         cmdline_ipaddr_t ip_src;
15359         cmdline_ipaddr_t ip_dst;
15360         uint16_t tci;
15361         uint8_t tos;
15362         uint8_t ttl;
15363         struct rte_ether_addr eth_src;
15364         struct rte_ether_addr eth_dst;
15365 };
15366
15367 cmdline_parse_token_string_t cmd_set_vxlan_set =
15368         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15369 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15370         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15371 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15372         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15373                                  "vxlan-tos-ttl");
15374 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15375         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15376                                  "vxlan-with-vlan");
15377 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15378         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15379                                  "ip-version");
15380 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15381         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15382                                  "ipv4#ipv6");
15383 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15384         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15385                                  "vni");
15386 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15387         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15388 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15389         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15390                                  "udp-src");
15391 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15392         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15393 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15394         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15395                                  "udp-dst");
15396 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15397         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15398 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15399         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15400                                  "ip-tos");
15401 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15402         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15403 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15404         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15405                                  "ip-ttl");
15406 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15407         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15408 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15409         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15410                                  "ip-src");
15411 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15412         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15413 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15414         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15415                                  "ip-dst");
15416 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15417         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15418 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15419         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15420                                  "vlan-tci");
15421 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15422         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15423 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15424         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15425                                  "eth-src");
15426 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15427         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15428 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15429         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15430                                  "eth-dst");
15431 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15432         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15433
15434 static void cmd_set_vxlan_parsed(void *parsed_result,
15435         __attribute__((unused)) struct cmdline *cl,
15436         __attribute__((unused)) void *data)
15437 {
15438         struct cmd_set_vxlan_result *res = parsed_result;
15439         union {
15440                 uint32_t vxlan_id;
15441                 uint8_t vni[4];
15442         } id = {
15443                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15444         };
15445
15446         vxlan_encap_conf.select_tos_ttl = 0;
15447         if (strcmp(res->vxlan, "vxlan") == 0)
15448                 vxlan_encap_conf.select_vlan = 0;
15449         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15450                 vxlan_encap_conf.select_vlan = 1;
15451         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15452                 vxlan_encap_conf.select_vlan = 0;
15453                 vxlan_encap_conf.select_tos_ttl = 1;
15454         }
15455         if (strcmp(res->ip_version, "ipv4") == 0)
15456                 vxlan_encap_conf.select_ipv4 = 1;
15457         else if (strcmp(res->ip_version, "ipv6") == 0)
15458                 vxlan_encap_conf.select_ipv4 = 0;
15459         else
15460                 return;
15461         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15462         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15463         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15464         vxlan_encap_conf.ip_tos = res->tos;
15465         vxlan_encap_conf.ip_ttl = res->ttl;
15466         if (vxlan_encap_conf.select_ipv4) {
15467                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15468                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15469         } else {
15470                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15471                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15472         }
15473         if (vxlan_encap_conf.select_vlan)
15474                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15475         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15476                    RTE_ETHER_ADDR_LEN);
15477         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15478                    RTE_ETHER_ADDR_LEN);
15479 }
15480
15481 cmdline_parse_inst_t cmd_set_vxlan = {
15482         .f = cmd_set_vxlan_parsed,
15483         .data = NULL,
15484         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15485                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15486                 " eth-src <eth-src> eth-dst <eth-dst>",
15487         .tokens = {
15488                 (void *)&cmd_set_vxlan_set,
15489                 (void *)&cmd_set_vxlan_vxlan,
15490                 (void *)&cmd_set_vxlan_ip_version,
15491                 (void *)&cmd_set_vxlan_ip_version_value,
15492                 (void *)&cmd_set_vxlan_vni,
15493                 (void *)&cmd_set_vxlan_vni_value,
15494                 (void *)&cmd_set_vxlan_udp_src,
15495                 (void *)&cmd_set_vxlan_udp_src_value,
15496                 (void *)&cmd_set_vxlan_udp_dst,
15497                 (void *)&cmd_set_vxlan_udp_dst_value,
15498                 (void *)&cmd_set_vxlan_ip_src,
15499                 (void *)&cmd_set_vxlan_ip_src_value,
15500                 (void *)&cmd_set_vxlan_ip_dst,
15501                 (void *)&cmd_set_vxlan_ip_dst_value,
15502                 (void *)&cmd_set_vxlan_eth_src,
15503                 (void *)&cmd_set_vxlan_eth_src_value,
15504                 (void *)&cmd_set_vxlan_eth_dst,
15505                 (void *)&cmd_set_vxlan_eth_dst_value,
15506                 NULL,
15507         },
15508 };
15509
15510 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15511         .f = cmd_set_vxlan_parsed,
15512         .data = NULL,
15513         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15514                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15515                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15516                 " eth-dst <eth-dst>",
15517         .tokens = {
15518                 (void *)&cmd_set_vxlan_set,
15519                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15520                 (void *)&cmd_set_vxlan_ip_version,
15521                 (void *)&cmd_set_vxlan_ip_version_value,
15522                 (void *)&cmd_set_vxlan_vni,
15523                 (void *)&cmd_set_vxlan_vni_value,
15524                 (void *)&cmd_set_vxlan_udp_src,
15525                 (void *)&cmd_set_vxlan_udp_src_value,
15526                 (void *)&cmd_set_vxlan_udp_dst,
15527                 (void *)&cmd_set_vxlan_udp_dst_value,
15528                 (void *)&cmd_set_vxlan_ip_tos,
15529                 (void *)&cmd_set_vxlan_ip_tos_value,
15530                 (void *)&cmd_set_vxlan_ip_ttl,
15531                 (void *)&cmd_set_vxlan_ip_ttl_value,
15532                 (void *)&cmd_set_vxlan_ip_src,
15533                 (void *)&cmd_set_vxlan_ip_src_value,
15534                 (void *)&cmd_set_vxlan_ip_dst,
15535                 (void *)&cmd_set_vxlan_ip_dst_value,
15536                 (void *)&cmd_set_vxlan_eth_src,
15537                 (void *)&cmd_set_vxlan_eth_src_value,
15538                 (void *)&cmd_set_vxlan_eth_dst,
15539                 (void *)&cmd_set_vxlan_eth_dst_value,
15540                 NULL,
15541         },
15542 };
15543
15544 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15545         .f = cmd_set_vxlan_parsed,
15546         .data = NULL,
15547         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15548                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15549                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15550                 " <eth-dst>",
15551         .tokens = {
15552                 (void *)&cmd_set_vxlan_set,
15553                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15554                 (void *)&cmd_set_vxlan_ip_version,
15555                 (void *)&cmd_set_vxlan_ip_version_value,
15556                 (void *)&cmd_set_vxlan_vni,
15557                 (void *)&cmd_set_vxlan_vni_value,
15558                 (void *)&cmd_set_vxlan_udp_src,
15559                 (void *)&cmd_set_vxlan_udp_src_value,
15560                 (void *)&cmd_set_vxlan_udp_dst,
15561                 (void *)&cmd_set_vxlan_udp_dst_value,
15562                 (void *)&cmd_set_vxlan_ip_src,
15563                 (void *)&cmd_set_vxlan_ip_src_value,
15564                 (void *)&cmd_set_vxlan_ip_dst,
15565                 (void *)&cmd_set_vxlan_ip_dst_value,
15566                 (void *)&cmd_set_vxlan_vlan,
15567                 (void *)&cmd_set_vxlan_vlan_value,
15568                 (void *)&cmd_set_vxlan_eth_src,
15569                 (void *)&cmd_set_vxlan_eth_src_value,
15570                 (void *)&cmd_set_vxlan_eth_dst,
15571                 (void *)&cmd_set_vxlan_eth_dst_value,
15572                 NULL,
15573         },
15574 };
15575
15576 /** Set NVGRE encapsulation details */
15577 struct cmd_set_nvgre_result {
15578         cmdline_fixed_string_t set;
15579         cmdline_fixed_string_t nvgre;
15580         cmdline_fixed_string_t pos_token;
15581         cmdline_fixed_string_t ip_version;
15582         uint32_t tni;
15583         cmdline_ipaddr_t ip_src;
15584         cmdline_ipaddr_t ip_dst;
15585         uint16_t tci;
15586         struct rte_ether_addr eth_src;
15587         struct rte_ether_addr eth_dst;
15588 };
15589
15590 cmdline_parse_token_string_t cmd_set_nvgre_set =
15591         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15592 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15593         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15594 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15595         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15596                                  "nvgre-with-vlan");
15597 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15598         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15599                                  "ip-version");
15600 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15601         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15602                                  "ipv4#ipv6");
15603 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15604         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15605                                  "tni");
15606 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15607         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15608 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15609         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15610                                  "ip-src");
15611 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15612         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15613 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15614         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15615                                  "ip-dst");
15616 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15617         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15618 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15619         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15620                                  "vlan-tci");
15621 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15622         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15623 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15624         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15625                                  "eth-src");
15626 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15627         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15628 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15629         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15630                                  "eth-dst");
15631 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15632         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15633
15634 static void cmd_set_nvgre_parsed(void *parsed_result,
15635         __attribute__((unused)) struct cmdline *cl,
15636         __attribute__((unused)) void *data)
15637 {
15638         struct cmd_set_nvgre_result *res = parsed_result;
15639         union {
15640                 uint32_t nvgre_tni;
15641                 uint8_t tni[4];
15642         } id = {
15643                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15644         };
15645
15646         if (strcmp(res->nvgre, "nvgre") == 0)
15647                 nvgre_encap_conf.select_vlan = 0;
15648         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15649                 nvgre_encap_conf.select_vlan = 1;
15650         if (strcmp(res->ip_version, "ipv4") == 0)
15651                 nvgre_encap_conf.select_ipv4 = 1;
15652         else if (strcmp(res->ip_version, "ipv6") == 0)
15653                 nvgre_encap_conf.select_ipv4 = 0;
15654         else
15655                 return;
15656         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15657         if (nvgre_encap_conf.select_ipv4) {
15658                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15659                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15660         } else {
15661                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15662                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15663         }
15664         if (nvgre_encap_conf.select_vlan)
15665                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15666         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15667                    RTE_ETHER_ADDR_LEN);
15668         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15669                    RTE_ETHER_ADDR_LEN);
15670 }
15671
15672 cmdline_parse_inst_t cmd_set_nvgre = {
15673         .f = cmd_set_nvgre_parsed,
15674         .data = NULL,
15675         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15676                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15677                 " eth-dst <eth-dst>",
15678         .tokens = {
15679                 (void *)&cmd_set_nvgre_set,
15680                 (void *)&cmd_set_nvgre_nvgre,
15681                 (void *)&cmd_set_nvgre_ip_version,
15682                 (void *)&cmd_set_nvgre_ip_version_value,
15683                 (void *)&cmd_set_nvgre_tni,
15684                 (void *)&cmd_set_nvgre_tni_value,
15685                 (void *)&cmd_set_nvgre_ip_src,
15686                 (void *)&cmd_set_nvgre_ip_src_value,
15687                 (void *)&cmd_set_nvgre_ip_dst,
15688                 (void *)&cmd_set_nvgre_ip_dst_value,
15689                 (void *)&cmd_set_nvgre_eth_src,
15690                 (void *)&cmd_set_nvgre_eth_src_value,
15691                 (void *)&cmd_set_nvgre_eth_dst,
15692                 (void *)&cmd_set_nvgre_eth_dst_value,
15693                 NULL,
15694         },
15695 };
15696
15697 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15698         .f = cmd_set_nvgre_parsed,
15699         .data = NULL,
15700         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15701                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15702                 " eth-src <eth-src> eth-dst <eth-dst>",
15703         .tokens = {
15704                 (void *)&cmd_set_nvgre_set,
15705                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15706                 (void *)&cmd_set_nvgre_ip_version,
15707                 (void *)&cmd_set_nvgre_ip_version_value,
15708                 (void *)&cmd_set_nvgre_tni,
15709                 (void *)&cmd_set_nvgre_tni_value,
15710                 (void *)&cmd_set_nvgre_ip_src,
15711                 (void *)&cmd_set_nvgre_ip_src_value,
15712                 (void *)&cmd_set_nvgre_ip_dst,
15713                 (void *)&cmd_set_nvgre_ip_dst_value,
15714                 (void *)&cmd_set_nvgre_vlan,
15715                 (void *)&cmd_set_nvgre_vlan_value,
15716                 (void *)&cmd_set_nvgre_eth_src,
15717                 (void *)&cmd_set_nvgre_eth_src_value,
15718                 (void *)&cmd_set_nvgre_eth_dst,
15719                 (void *)&cmd_set_nvgre_eth_dst_value,
15720                 NULL,
15721         },
15722 };
15723
15724 /** Set L2 encapsulation details */
15725 struct cmd_set_l2_encap_result {
15726         cmdline_fixed_string_t set;
15727         cmdline_fixed_string_t l2_encap;
15728         cmdline_fixed_string_t pos_token;
15729         cmdline_fixed_string_t ip_version;
15730         uint32_t vlan_present:1;
15731         uint16_t tci;
15732         struct rte_ether_addr eth_src;
15733         struct rte_ether_addr eth_dst;
15734 };
15735
15736 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15737         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15738 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15739         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15740 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15741         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15742                                  "l2_encap-with-vlan");
15743 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15744         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15745                                  "ip-version");
15746 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15747         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15748                                  "ipv4#ipv6");
15749 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15750         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15751                                  "vlan-tci");
15752 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15753         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15754 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15755         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15756                                  "eth-src");
15757 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15758         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15759 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15760         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15761                                  "eth-dst");
15762 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15763         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15764
15765 static void cmd_set_l2_encap_parsed(void *parsed_result,
15766         __attribute__((unused)) struct cmdline *cl,
15767         __attribute__((unused)) void *data)
15768 {
15769         struct cmd_set_l2_encap_result *res = parsed_result;
15770
15771         if (strcmp(res->l2_encap, "l2_encap") == 0)
15772                 l2_encap_conf.select_vlan = 0;
15773         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15774                 l2_encap_conf.select_vlan = 1;
15775         if (strcmp(res->ip_version, "ipv4") == 0)
15776                 l2_encap_conf.select_ipv4 = 1;
15777         else if (strcmp(res->ip_version, "ipv6") == 0)
15778                 l2_encap_conf.select_ipv4 = 0;
15779         else
15780                 return;
15781         if (l2_encap_conf.select_vlan)
15782                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15783         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15784                    RTE_ETHER_ADDR_LEN);
15785         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15786                    RTE_ETHER_ADDR_LEN);
15787 }
15788
15789 cmdline_parse_inst_t cmd_set_l2_encap = {
15790         .f = cmd_set_l2_encap_parsed,
15791         .data = NULL,
15792         .help_str = "set l2_encap ip-version ipv4|ipv6"
15793                 " eth-src <eth-src> eth-dst <eth-dst>",
15794         .tokens = {
15795                 (void *)&cmd_set_l2_encap_set,
15796                 (void *)&cmd_set_l2_encap_l2_encap,
15797                 (void *)&cmd_set_l2_encap_ip_version,
15798                 (void *)&cmd_set_l2_encap_ip_version_value,
15799                 (void *)&cmd_set_l2_encap_eth_src,
15800                 (void *)&cmd_set_l2_encap_eth_src_value,
15801                 (void *)&cmd_set_l2_encap_eth_dst,
15802                 (void *)&cmd_set_l2_encap_eth_dst_value,
15803                 NULL,
15804         },
15805 };
15806
15807 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15808         .f = cmd_set_l2_encap_parsed,
15809         .data = NULL,
15810         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15811                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15812         .tokens = {
15813                 (void *)&cmd_set_l2_encap_set,
15814                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15815                 (void *)&cmd_set_l2_encap_ip_version,
15816                 (void *)&cmd_set_l2_encap_ip_version_value,
15817                 (void *)&cmd_set_l2_encap_vlan,
15818                 (void *)&cmd_set_l2_encap_vlan_value,
15819                 (void *)&cmd_set_l2_encap_eth_src,
15820                 (void *)&cmd_set_l2_encap_eth_src_value,
15821                 (void *)&cmd_set_l2_encap_eth_dst,
15822                 (void *)&cmd_set_l2_encap_eth_dst_value,
15823                 NULL,
15824         },
15825 };
15826
15827 /** Set L2 decapsulation details */
15828 struct cmd_set_l2_decap_result {
15829         cmdline_fixed_string_t set;
15830         cmdline_fixed_string_t l2_decap;
15831         cmdline_fixed_string_t pos_token;
15832         uint32_t vlan_present:1;
15833 };
15834
15835 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15836         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15837 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15838         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15839                                  "l2_decap");
15840 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15841         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15842                                  "l2_decap-with-vlan");
15843
15844 static void cmd_set_l2_decap_parsed(void *parsed_result,
15845         __attribute__((unused)) struct cmdline *cl,
15846         __attribute__((unused)) void *data)
15847 {
15848         struct cmd_set_l2_decap_result *res = parsed_result;
15849
15850         if (strcmp(res->l2_decap, "l2_decap") == 0)
15851                 l2_decap_conf.select_vlan = 0;
15852         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15853                 l2_decap_conf.select_vlan = 1;
15854 }
15855
15856 cmdline_parse_inst_t cmd_set_l2_decap = {
15857         .f = cmd_set_l2_decap_parsed,
15858         .data = NULL,
15859         .help_str = "set l2_decap",
15860         .tokens = {
15861                 (void *)&cmd_set_l2_decap_set,
15862                 (void *)&cmd_set_l2_decap_l2_decap,
15863                 NULL,
15864         },
15865 };
15866
15867 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15868         .f = cmd_set_l2_decap_parsed,
15869         .data = NULL,
15870         .help_str = "set l2_decap-with-vlan",
15871         .tokens = {
15872                 (void *)&cmd_set_l2_decap_set,
15873                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15874                 NULL,
15875         },
15876 };
15877
15878 /** Set MPLSoGRE encapsulation details */
15879 struct cmd_set_mplsogre_encap_result {
15880         cmdline_fixed_string_t set;
15881         cmdline_fixed_string_t mplsogre;
15882         cmdline_fixed_string_t pos_token;
15883         cmdline_fixed_string_t ip_version;
15884         uint32_t vlan_present:1;
15885         uint32_t label;
15886         cmdline_ipaddr_t ip_src;
15887         cmdline_ipaddr_t ip_dst;
15888         uint16_t tci;
15889         struct rte_ether_addr eth_src;
15890         struct rte_ether_addr eth_dst;
15891 };
15892
15893 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15894         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15895                                  "set");
15896 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15897         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15898                                  "mplsogre_encap");
15899 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15900         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15901                                  mplsogre, "mplsogre_encap-with-vlan");
15902 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15903         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15904                                  pos_token, "ip-version");
15905 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15906         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15907                                  ip_version, "ipv4#ipv6");
15908 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15909         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15910                                  pos_token, "label");
15911 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15912         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15913                               UINT32);
15914 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15915         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15916                                  pos_token, "ip-src");
15917 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15918         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15919 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15920         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15921                                  pos_token, "ip-dst");
15922 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15923         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15924 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15925         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15926                                  pos_token, "vlan-tci");
15927 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15928         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15929                               UINT16);
15930 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15931         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15932                                  pos_token, "eth-src");
15933 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15934         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15935                                     eth_src);
15936 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15937         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15938                                  pos_token, "eth-dst");
15939 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15940         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15941                                     eth_dst);
15942
15943 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15944         __attribute__((unused)) struct cmdline *cl,
15945         __attribute__((unused)) void *data)
15946 {
15947         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15948         union {
15949                 uint32_t mplsogre_label;
15950                 uint8_t label[4];
15951         } id = {
15952                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15953         };
15954
15955         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15956                 mplsogre_encap_conf.select_vlan = 0;
15957         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15958                 mplsogre_encap_conf.select_vlan = 1;
15959         if (strcmp(res->ip_version, "ipv4") == 0)
15960                 mplsogre_encap_conf.select_ipv4 = 1;
15961         else if (strcmp(res->ip_version, "ipv6") == 0)
15962                 mplsogre_encap_conf.select_ipv4 = 0;
15963         else
15964                 return;
15965         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15966         if (mplsogre_encap_conf.select_ipv4) {
15967                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15968                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15969         } else {
15970                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15971                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15972         }
15973         if (mplsogre_encap_conf.select_vlan)
15974                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15975         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15976                    RTE_ETHER_ADDR_LEN);
15977         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15978                    RTE_ETHER_ADDR_LEN);
15979 }
15980
15981 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15982         .f = cmd_set_mplsogre_encap_parsed,
15983         .data = NULL,
15984         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15985                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15986                 " eth-dst <eth-dst>",
15987         .tokens = {
15988                 (void *)&cmd_set_mplsogre_encap_set,
15989                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15990                 (void *)&cmd_set_mplsogre_encap_ip_version,
15991                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15992                 (void *)&cmd_set_mplsogre_encap_label,
15993                 (void *)&cmd_set_mplsogre_encap_label_value,
15994                 (void *)&cmd_set_mplsogre_encap_ip_src,
15995                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15996                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15997                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15998                 (void *)&cmd_set_mplsogre_encap_eth_src,
15999                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16000                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16001                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16002                 NULL,
16003         },
16004 };
16005
16006 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16007         .f = cmd_set_mplsogre_encap_parsed,
16008         .data = NULL,
16009         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16010                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16011                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16012         .tokens = {
16013                 (void *)&cmd_set_mplsogre_encap_set,
16014                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16015                 (void *)&cmd_set_mplsogre_encap_ip_version,
16016                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16017                 (void *)&cmd_set_mplsogre_encap_label,
16018                 (void *)&cmd_set_mplsogre_encap_label_value,
16019                 (void *)&cmd_set_mplsogre_encap_ip_src,
16020                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16021                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16022                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16023                 (void *)&cmd_set_mplsogre_encap_vlan,
16024                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16025                 (void *)&cmd_set_mplsogre_encap_eth_src,
16026                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16027                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16028                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16029                 NULL,
16030         },
16031 };
16032
16033 /** Set MPLSoGRE decapsulation details */
16034 struct cmd_set_mplsogre_decap_result {
16035         cmdline_fixed_string_t set;
16036         cmdline_fixed_string_t mplsogre;
16037         cmdline_fixed_string_t pos_token;
16038         cmdline_fixed_string_t ip_version;
16039         uint32_t vlan_present:1;
16040 };
16041
16042 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16043         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16044                                  "set");
16045 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16046         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16047                                  "mplsogre_decap");
16048 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16049         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16050                                  mplsogre, "mplsogre_decap-with-vlan");
16051 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16052         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16053                                  pos_token, "ip-version");
16054 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16056                                  ip_version, "ipv4#ipv6");
16057
16058 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16059         __attribute__((unused)) struct cmdline *cl,
16060         __attribute__((unused)) void *data)
16061 {
16062         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16063
16064         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16065                 mplsogre_decap_conf.select_vlan = 0;
16066         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16067                 mplsogre_decap_conf.select_vlan = 1;
16068         if (strcmp(res->ip_version, "ipv4") == 0)
16069                 mplsogre_decap_conf.select_ipv4 = 1;
16070         else if (strcmp(res->ip_version, "ipv6") == 0)
16071                 mplsogre_decap_conf.select_ipv4 = 0;
16072 }
16073
16074 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16075         .f = cmd_set_mplsogre_decap_parsed,
16076         .data = NULL,
16077         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16078         .tokens = {
16079                 (void *)&cmd_set_mplsogre_decap_set,
16080                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16081                 (void *)&cmd_set_mplsogre_decap_ip_version,
16082                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16083                 NULL,
16084         },
16085 };
16086
16087 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16088         .f = cmd_set_mplsogre_decap_parsed,
16089         .data = NULL,
16090         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16091         .tokens = {
16092                 (void *)&cmd_set_mplsogre_decap_set,
16093                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16094                 (void *)&cmd_set_mplsogre_decap_ip_version,
16095                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16096                 NULL,
16097         },
16098 };
16099
16100 /** Set MPLSoUDP encapsulation details */
16101 struct cmd_set_mplsoudp_encap_result {
16102         cmdline_fixed_string_t set;
16103         cmdline_fixed_string_t mplsoudp;
16104         cmdline_fixed_string_t pos_token;
16105         cmdline_fixed_string_t ip_version;
16106         uint32_t vlan_present:1;
16107         uint32_t label;
16108         uint16_t udp_src;
16109         uint16_t udp_dst;
16110         cmdline_ipaddr_t ip_src;
16111         cmdline_ipaddr_t ip_dst;
16112         uint16_t tci;
16113         struct rte_ether_addr eth_src;
16114         struct rte_ether_addr eth_dst;
16115 };
16116
16117 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16118         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16119                                  "set");
16120 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16121         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16122                                  "mplsoudp_encap");
16123 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16124         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16125                                  mplsoudp, "mplsoudp_encap-with-vlan");
16126 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16127         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16128                                  pos_token, "ip-version");
16129 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16130         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16131                                  ip_version, "ipv4#ipv6");
16132 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16133         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16134                                  pos_token, "label");
16135 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16136         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16137                               UINT32);
16138 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16139         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16140                                  pos_token, "udp-src");
16141 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16142         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16143                               UINT16);
16144 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16145         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16146                                  pos_token, "udp-dst");
16147 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16148         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16149                               UINT16);
16150 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16151         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16152                                  pos_token, "ip-src");
16153 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16154         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16155 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16156         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16157                                  pos_token, "ip-dst");
16158 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16159         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16160 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16161         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16162                                  pos_token, "vlan-tci");
16163 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16164         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16165                               UINT16);
16166 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16167         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16168                                  pos_token, "eth-src");
16169 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16170         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16171                                     eth_src);
16172 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16173         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16174                                  pos_token, "eth-dst");
16175 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16176         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16177                                     eth_dst);
16178
16179 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16180         __attribute__((unused)) struct cmdline *cl,
16181         __attribute__((unused)) void *data)
16182 {
16183         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16184         union {
16185                 uint32_t mplsoudp_label;
16186                 uint8_t label[4];
16187         } id = {
16188                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16189         };
16190
16191         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16192                 mplsoudp_encap_conf.select_vlan = 0;
16193         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16194                 mplsoudp_encap_conf.select_vlan = 1;
16195         if (strcmp(res->ip_version, "ipv4") == 0)
16196                 mplsoudp_encap_conf.select_ipv4 = 1;
16197         else if (strcmp(res->ip_version, "ipv6") == 0)
16198                 mplsoudp_encap_conf.select_ipv4 = 0;
16199         else
16200                 return;
16201         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16202         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16203         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16204         if (mplsoudp_encap_conf.select_ipv4) {
16205                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16206                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16207         } else {
16208                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16209                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16210         }
16211         if (mplsoudp_encap_conf.select_vlan)
16212                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16213         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16214                    RTE_ETHER_ADDR_LEN);
16215         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16216                    RTE_ETHER_ADDR_LEN);
16217 }
16218
16219 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16220         .f = cmd_set_mplsoudp_encap_parsed,
16221         .data = NULL,
16222         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16223                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16224                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16225         .tokens = {
16226                 (void *)&cmd_set_mplsoudp_encap_set,
16227                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16228                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16229                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16230                 (void *)&cmd_set_mplsoudp_encap_label,
16231                 (void *)&cmd_set_mplsoudp_encap_label_value,
16232                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16233                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16234                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16235                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16236                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16237                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16238                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16239                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16240                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16241                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16242                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16243                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16244                 NULL,
16245         },
16246 };
16247
16248 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16249         .f = cmd_set_mplsoudp_encap_parsed,
16250         .data = NULL,
16251         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16252                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16253                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16254                 " eth-src <eth-src> eth-dst <eth-dst>",
16255         .tokens = {
16256                 (void *)&cmd_set_mplsoudp_encap_set,
16257                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16258                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16259                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16260                 (void *)&cmd_set_mplsoudp_encap_label,
16261                 (void *)&cmd_set_mplsoudp_encap_label_value,
16262                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16263                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16264                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16265                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16266                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16267                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16268                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16269                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16270                 (void *)&cmd_set_mplsoudp_encap_vlan,
16271                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16272                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16273                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16274                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16275                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16276                 NULL,
16277         },
16278 };
16279
16280 /** Set MPLSoUDP decapsulation details */
16281 struct cmd_set_mplsoudp_decap_result {
16282         cmdline_fixed_string_t set;
16283         cmdline_fixed_string_t mplsoudp;
16284         cmdline_fixed_string_t pos_token;
16285         cmdline_fixed_string_t ip_version;
16286         uint32_t vlan_present:1;
16287 };
16288
16289 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16290         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16291                                  "set");
16292 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16293         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16294                                  "mplsoudp_decap");
16295 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16296         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16297                                  mplsoudp, "mplsoudp_decap-with-vlan");
16298 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16299         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16300                                  pos_token, "ip-version");
16301 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16302         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16303                                  ip_version, "ipv4#ipv6");
16304
16305 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16306         __attribute__((unused)) struct cmdline *cl,
16307         __attribute__((unused)) void *data)
16308 {
16309         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16310
16311         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16312                 mplsoudp_decap_conf.select_vlan = 0;
16313         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16314                 mplsoudp_decap_conf.select_vlan = 1;
16315         if (strcmp(res->ip_version, "ipv4") == 0)
16316                 mplsoudp_decap_conf.select_ipv4 = 1;
16317         else if (strcmp(res->ip_version, "ipv6") == 0)
16318                 mplsoudp_decap_conf.select_ipv4 = 0;
16319 }
16320
16321 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16322         .f = cmd_set_mplsoudp_decap_parsed,
16323         .data = NULL,
16324         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16325         .tokens = {
16326                 (void *)&cmd_set_mplsoudp_decap_set,
16327                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16328                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16329                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16330                 NULL,
16331         },
16332 };
16333
16334 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16335         .f = cmd_set_mplsoudp_decap_parsed,
16336         .data = NULL,
16337         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16338         .tokens = {
16339                 (void *)&cmd_set_mplsoudp_decap_set,
16340                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16341                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16342                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16343                 NULL,
16344         },
16345 };
16346
16347 /* Strict link priority scheduling mode setting */
16348 static void
16349 cmd_strict_link_prio_parsed(
16350         void *parsed_result,
16351         __attribute__((unused)) struct cmdline *cl,
16352         __attribute__((unused)) void *data)
16353 {
16354         struct cmd_vf_tc_bw_result *res = parsed_result;
16355         int ret = -ENOTSUP;
16356
16357         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16358                 return;
16359
16360 #ifdef RTE_LIBRTE_I40E_PMD
16361         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16362 #endif
16363
16364         switch (ret) {
16365         case 0:
16366                 break;
16367         case -EINVAL:
16368                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16369                 break;
16370         case -ENODEV:
16371                 printf("invalid port_id %d\n", res->port_id);
16372                 break;
16373         case -ENOTSUP:
16374                 printf("function not implemented\n");
16375                 break;
16376         default:
16377                 printf("programming error: (%s)\n", strerror(-ret));
16378         }
16379 }
16380
16381 cmdline_parse_inst_t cmd_strict_link_prio = {
16382         .f = cmd_strict_link_prio_parsed,
16383         .data = NULL,
16384         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16385         .tokens = {
16386                 (void *)&cmd_vf_tc_bw_set,
16387                 (void *)&cmd_vf_tc_bw_tx,
16388                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16389                 (void *)&cmd_vf_tc_bw_port_id,
16390                 (void *)&cmd_vf_tc_bw_tc_map,
16391                 NULL,
16392         },
16393 };
16394
16395 /* Load dynamic device personalization*/
16396 struct cmd_ddp_add_result {
16397         cmdline_fixed_string_t ddp;
16398         cmdline_fixed_string_t add;
16399         portid_t port_id;
16400         char filepath[];
16401 };
16402
16403 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16404         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16405 cmdline_parse_token_string_t cmd_ddp_add_add =
16406         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16407 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16408         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16409 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16410         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16411
16412 static void
16413 cmd_ddp_add_parsed(
16414         void *parsed_result,
16415         __attribute__((unused)) struct cmdline *cl,
16416         __attribute__((unused)) void *data)
16417 {
16418         struct cmd_ddp_add_result *res = parsed_result;
16419         uint8_t *buff;
16420         uint32_t size;
16421         char *filepath;
16422         char *file_fld[2];
16423         int file_num;
16424         int ret = -ENOTSUP;
16425
16426         if (!all_ports_stopped()) {
16427                 printf("Please stop all ports first\n");
16428                 return;
16429         }
16430
16431         filepath = strdup(res->filepath);
16432         if (filepath == NULL) {
16433                 printf("Failed to allocate memory\n");
16434                 return;
16435         }
16436         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16437
16438         buff = open_file(file_fld[0], &size);
16439         if (!buff) {
16440                 free((void *)filepath);
16441                 return;
16442         }
16443
16444 #ifdef RTE_LIBRTE_I40E_PMD
16445         if (ret == -ENOTSUP)
16446                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16447                                                buff, size,
16448                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16449 #endif
16450
16451         if (ret == -EEXIST)
16452                 printf("Profile has already existed.\n");
16453         else if (ret < 0)
16454                 printf("Failed to load profile.\n");
16455         else if (file_num == 2)
16456                 save_file(file_fld[1], buff, size);
16457
16458         close_file(buff);
16459         free((void *)filepath);
16460 }
16461
16462 cmdline_parse_inst_t cmd_ddp_add = {
16463         .f = cmd_ddp_add_parsed,
16464         .data = NULL,
16465         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16466         .tokens = {
16467                 (void *)&cmd_ddp_add_ddp,
16468                 (void *)&cmd_ddp_add_add,
16469                 (void *)&cmd_ddp_add_port_id,
16470                 (void *)&cmd_ddp_add_filepath,
16471                 NULL,
16472         },
16473 };
16474
16475 /* Delete dynamic device personalization*/
16476 struct cmd_ddp_del_result {
16477         cmdline_fixed_string_t ddp;
16478         cmdline_fixed_string_t del;
16479         portid_t port_id;
16480         char filepath[];
16481 };
16482
16483 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16484         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16485 cmdline_parse_token_string_t cmd_ddp_del_del =
16486         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16487 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16488         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16489 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16490         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16491
16492 static void
16493 cmd_ddp_del_parsed(
16494         void *parsed_result,
16495         __attribute__((unused)) struct cmdline *cl,
16496         __attribute__((unused)) void *data)
16497 {
16498         struct cmd_ddp_del_result *res = parsed_result;
16499         uint8_t *buff;
16500         uint32_t size;
16501         int ret = -ENOTSUP;
16502
16503         if (!all_ports_stopped()) {
16504                 printf("Please stop all ports first\n");
16505                 return;
16506         }
16507
16508         buff = open_file(res->filepath, &size);
16509         if (!buff)
16510                 return;
16511
16512 #ifdef RTE_LIBRTE_I40E_PMD
16513         if (ret == -ENOTSUP)
16514                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16515                                                buff, size,
16516                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16517 #endif
16518
16519         if (ret == -EACCES)
16520                 printf("Profile does not exist.\n");
16521         else if (ret < 0)
16522                 printf("Failed to delete profile.\n");
16523
16524         close_file(buff);
16525 }
16526
16527 cmdline_parse_inst_t cmd_ddp_del = {
16528         .f = cmd_ddp_del_parsed,
16529         .data = NULL,
16530         .help_str = "ddp del <port_id> <backup_profile_path>",
16531         .tokens = {
16532                 (void *)&cmd_ddp_del_ddp,
16533                 (void *)&cmd_ddp_del_del,
16534                 (void *)&cmd_ddp_del_port_id,
16535                 (void *)&cmd_ddp_del_filepath,
16536                 NULL,
16537         },
16538 };
16539
16540 /* Get dynamic device personalization profile info */
16541 struct cmd_ddp_info_result {
16542         cmdline_fixed_string_t ddp;
16543         cmdline_fixed_string_t get;
16544         cmdline_fixed_string_t info;
16545         char filepath[];
16546 };
16547
16548 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16549         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16550 cmdline_parse_token_string_t cmd_ddp_info_get =
16551         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16552 cmdline_parse_token_string_t cmd_ddp_info_info =
16553         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16554 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16555         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16556
16557 static void
16558 cmd_ddp_info_parsed(
16559         void *parsed_result,
16560         __attribute__((unused)) struct cmdline *cl,
16561         __attribute__((unused)) void *data)
16562 {
16563         struct cmd_ddp_info_result *res = parsed_result;
16564         uint8_t *pkg;
16565         uint32_t pkg_size;
16566         int ret = -ENOTSUP;
16567 #ifdef RTE_LIBRTE_I40E_PMD
16568         uint32_t i, j, n;
16569         uint8_t *buff;
16570         uint32_t buff_size = 0;
16571         struct rte_pmd_i40e_profile_info info;
16572         uint32_t dev_num = 0;
16573         struct rte_pmd_i40e_ddp_device_id *devs;
16574         uint32_t proto_num = 0;
16575         struct rte_pmd_i40e_proto_info *proto = NULL;
16576         uint32_t pctype_num = 0;
16577         struct rte_pmd_i40e_ptype_info *pctype;
16578         uint32_t ptype_num = 0;
16579         struct rte_pmd_i40e_ptype_info *ptype;
16580         uint8_t proto_id;
16581
16582 #endif
16583
16584         pkg = open_file(res->filepath, &pkg_size);
16585         if (!pkg)
16586                 return;
16587
16588 #ifdef RTE_LIBRTE_I40E_PMD
16589         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16590                                 (uint8_t *)&info, sizeof(info),
16591                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16592         if (!ret) {
16593                 printf("Global Track id:       0x%x\n", info.track_id);
16594                 printf("Global Version:        %d.%d.%d.%d\n",
16595                         info.version.major,
16596                         info.version.minor,
16597                         info.version.update,
16598                         info.version.draft);
16599                 printf("Global Package name:   %s\n\n", info.name);
16600         }
16601
16602         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16603                                 (uint8_t *)&info, sizeof(info),
16604                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16605         if (!ret) {
16606                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16607                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16608                         info.version.major,
16609                         info.version.minor,
16610                         info.version.update,
16611                         info.version.draft);
16612                 printf("i40e Profile name:     %s\n\n", info.name);
16613         }
16614
16615         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16616                                 (uint8_t *)&buff_size, sizeof(buff_size),
16617                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16618         if (!ret && buff_size) {
16619                 buff = (uint8_t *)malloc(buff_size);
16620                 if (buff) {
16621                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16622                                                 buff, buff_size,
16623                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16624                         if (!ret)
16625                                 printf("Package Notes:\n%s\n\n", buff);
16626                         free(buff);
16627                 }
16628         }
16629
16630         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16631                                 (uint8_t *)&dev_num, sizeof(dev_num),
16632                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16633         if (!ret && dev_num) {
16634                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16635                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16636                 if (devs) {
16637                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16638                                                 (uint8_t *)devs, buff_size,
16639                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16640                         if (!ret) {
16641                                 printf("List of supported devices:\n");
16642                                 for (i = 0; i < dev_num; i++) {
16643                                         printf("  %04X:%04X %04X:%04X\n",
16644                                                 devs[i].vendor_dev_id >> 16,
16645                                                 devs[i].vendor_dev_id & 0xFFFF,
16646                                                 devs[i].sub_vendor_dev_id >> 16,
16647                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16648                                 }
16649                                 printf("\n");
16650                         }
16651                         free(devs);
16652                 }
16653         }
16654
16655         /* get information about protocols and packet types */
16656         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16657                 (uint8_t *)&proto_num, sizeof(proto_num),
16658                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16659         if (ret || !proto_num)
16660                 goto no_print_return;
16661
16662         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16663         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16664         if (!proto)
16665                 goto no_print_return;
16666
16667         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16668                                         buff_size,
16669                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16670         if (!ret) {
16671                 printf("List of used protocols:\n");
16672                 for (i = 0; i < proto_num; i++)
16673                         printf("  %2u: %s\n", proto[i].proto_id,
16674                                proto[i].name);
16675                 printf("\n");
16676         }
16677         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16678                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16679                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16680         if (ret || !pctype_num)
16681                 goto no_print_pctypes;
16682
16683         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16684         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16685         if (!pctype)
16686                 goto no_print_pctypes;
16687
16688         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16689                                         buff_size,
16690                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16691         if (ret) {
16692                 free(pctype);
16693                 goto no_print_pctypes;
16694         }
16695
16696         printf("List of defined packet classification types:\n");
16697         for (i = 0; i < pctype_num; i++) {
16698                 printf("  %2u:", pctype[i].ptype_id);
16699                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16700                         proto_id = pctype[i].protocols[j];
16701                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16702                                 for (n = 0; n < proto_num; n++) {
16703                                         if (proto[n].proto_id == proto_id) {
16704                                                 printf(" %s", proto[n].name);
16705                                                 break;
16706                                         }
16707                                 }
16708                         }
16709                 }
16710                 printf("\n");
16711         }
16712         printf("\n");
16713         free(pctype);
16714
16715 no_print_pctypes:
16716
16717         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16718                                         sizeof(ptype_num),
16719                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16720         if (ret || !ptype_num)
16721                 goto no_print_return;
16722
16723         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16724         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16725         if (!ptype)
16726                 goto no_print_return;
16727
16728         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16729                                         buff_size,
16730                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16731         if (ret) {
16732                 free(ptype);
16733                 goto no_print_return;
16734         }
16735         printf("List of defined packet types:\n");
16736         for (i = 0; i < ptype_num; i++) {
16737                 printf("  %2u:", ptype[i].ptype_id);
16738                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16739                         proto_id = ptype[i].protocols[j];
16740                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16741                                 for (n = 0; n < proto_num; n++) {
16742                                         if (proto[n].proto_id == proto_id) {
16743                                                 printf(" %s", proto[n].name);
16744                                                 break;
16745                                         }
16746                                 }
16747                         }
16748                 }
16749                 printf("\n");
16750         }
16751         free(ptype);
16752         printf("\n");
16753
16754         ret = 0;
16755 no_print_return:
16756         if (proto)
16757                 free(proto);
16758 #endif
16759         if (ret == -ENOTSUP)
16760                 printf("Function not supported in PMD driver\n");
16761         close_file(pkg);
16762 }
16763
16764 cmdline_parse_inst_t cmd_ddp_get_info = {
16765         .f = cmd_ddp_info_parsed,
16766         .data = NULL,
16767         .help_str = "ddp get info <profile_path>",
16768         .tokens = {
16769                 (void *)&cmd_ddp_info_ddp,
16770                 (void *)&cmd_ddp_info_get,
16771                 (void *)&cmd_ddp_info_info,
16772                 (void *)&cmd_ddp_info_filepath,
16773                 NULL,
16774         },
16775 };
16776
16777 /* Get dynamic device personalization profile info list*/
16778 #define PROFILE_INFO_SIZE 48
16779 #define MAX_PROFILE_NUM 16
16780
16781 struct cmd_ddp_get_list_result {
16782         cmdline_fixed_string_t ddp;
16783         cmdline_fixed_string_t get;
16784         cmdline_fixed_string_t list;
16785         portid_t port_id;
16786 };
16787
16788 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16789         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16790 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16791         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16792 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16793         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16794 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16795         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16796
16797 static void
16798 cmd_ddp_get_list_parsed(
16799         __attribute__((unused)) void *parsed_result,
16800         __attribute__((unused)) struct cmdline *cl,
16801         __attribute__((unused)) void *data)
16802 {
16803 #ifdef RTE_LIBRTE_I40E_PMD
16804         struct cmd_ddp_get_list_result *res = parsed_result;
16805         struct rte_pmd_i40e_profile_list *p_list;
16806         struct rte_pmd_i40e_profile_info *p_info;
16807         uint32_t p_num;
16808         uint32_t size;
16809         uint32_t i;
16810 #endif
16811         int ret = -ENOTSUP;
16812
16813 #ifdef RTE_LIBRTE_I40E_PMD
16814         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16815         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16816         if (!p_list)
16817                 printf("%s: Failed to malloc buffer\n", __func__);
16818
16819         if (ret == -ENOTSUP)
16820                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16821                                                 (uint8_t *)p_list, size);
16822
16823         if (!ret) {
16824                 p_num = p_list->p_count;
16825                 printf("Profile number is: %d\n\n", p_num);
16826
16827                 for (i = 0; i < p_num; i++) {
16828                         p_info = &p_list->p_info[i];
16829                         printf("Profile %d:\n", i);
16830                         printf("Track id:     0x%x\n", p_info->track_id);
16831                         printf("Version:      %d.%d.%d.%d\n",
16832                                p_info->version.major,
16833                                p_info->version.minor,
16834                                p_info->version.update,
16835                                p_info->version.draft);
16836                         printf("Profile name: %s\n\n", p_info->name);
16837                 }
16838         }
16839
16840         free(p_list);
16841 #endif
16842
16843         if (ret < 0)
16844                 printf("Failed to get ddp list\n");
16845 }
16846
16847 cmdline_parse_inst_t cmd_ddp_get_list = {
16848         .f = cmd_ddp_get_list_parsed,
16849         .data = NULL,
16850         .help_str = "ddp get list <port_id>",
16851         .tokens = {
16852                 (void *)&cmd_ddp_get_list_ddp,
16853                 (void *)&cmd_ddp_get_list_get,
16854                 (void *)&cmd_ddp_get_list_list,
16855                 (void *)&cmd_ddp_get_list_port_id,
16856                 NULL,
16857         },
16858 };
16859
16860 /* Configure input set */
16861 struct cmd_cfg_input_set_result {
16862         cmdline_fixed_string_t port;
16863         cmdline_fixed_string_t cfg;
16864         portid_t port_id;
16865         cmdline_fixed_string_t pctype;
16866         uint8_t pctype_id;
16867         cmdline_fixed_string_t inset_type;
16868         cmdline_fixed_string_t opt;
16869         cmdline_fixed_string_t field;
16870         uint8_t field_idx;
16871 };
16872
16873 static void
16874 cmd_cfg_input_set_parsed(
16875         __attribute__((unused)) void *parsed_result,
16876         __attribute__((unused)) struct cmdline *cl,
16877         __attribute__((unused)) void *data)
16878 {
16879 #ifdef RTE_LIBRTE_I40E_PMD
16880         struct cmd_cfg_input_set_result *res = parsed_result;
16881         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16882         struct rte_pmd_i40e_inset inset;
16883 #endif
16884         int ret = -ENOTSUP;
16885
16886         if (!all_ports_stopped()) {
16887                 printf("Please stop all ports first\n");
16888                 return;
16889         }
16890
16891 #ifdef RTE_LIBRTE_I40E_PMD
16892         if (!strcmp(res->inset_type, "hash_inset"))
16893                 inset_type = INSET_HASH;
16894         else if (!strcmp(res->inset_type, "fdir_inset"))
16895                 inset_type = INSET_FDIR;
16896         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16897                 inset_type = INSET_FDIR_FLX;
16898         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16899                                      &inset, inset_type);
16900         if (ret) {
16901                 printf("Failed to get input set.\n");
16902                 return;
16903         }
16904
16905         if (!strcmp(res->opt, "get")) {
16906                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16907                                                    res->field_idx);
16908                 if (ret)
16909                         printf("Field index %d is enabled.\n", res->field_idx);
16910                 else
16911                         printf("Field index %d is disabled.\n", res->field_idx);
16912                 return;
16913         } else if (!strcmp(res->opt, "set"))
16914                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16915                                                    res->field_idx);
16916         else if (!strcmp(res->opt, "clear"))
16917                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16918                                                      res->field_idx);
16919         if (ret) {
16920                 printf("Failed to configure input set field.\n");
16921                 return;
16922         }
16923
16924         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16925                                      &inset, inset_type);
16926         if (ret) {
16927                 printf("Failed to set input set.\n");
16928                 return;
16929         }
16930 #endif
16931
16932         if (ret == -ENOTSUP)
16933                 printf("Function not supported\n");
16934 }
16935
16936 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16937         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16938                                  port, "port");
16939 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16940         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16941                                  cfg, "config");
16942 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16943         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16944                               port_id, UINT16);
16945 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16946         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16947                                  pctype, "pctype");
16948 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16949         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16950                               pctype_id, UINT8);
16951 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16952         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16953                                  inset_type,
16954                                  "hash_inset#fdir_inset#fdir_flx_inset");
16955 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16956         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16957                                  opt, "get#set#clear");
16958 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16959         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16960                                  field, "field");
16961 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16962         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16963                               field_idx, UINT8);
16964
16965 cmdline_parse_inst_t cmd_cfg_input_set = {
16966         .f = cmd_cfg_input_set_parsed,
16967         .data = NULL,
16968         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16969                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16970         .tokens = {
16971                 (void *)&cmd_cfg_input_set_port,
16972                 (void *)&cmd_cfg_input_set_cfg,
16973                 (void *)&cmd_cfg_input_set_port_id,
16974                 (void *)&cmd_cfg_input_set_pctype,
16975                 (void *)&cmd_cfg_input_set_pctype_id,
16976                 (void *)&cmd_cfg_input_set_inset_type,
16977                 (void *)&cmd_cfg_input_set_opt,
16978                 (void *)&cmd_cfg_input_set_field,
16979                 (void *)&cmd_cfg_input_set_field_idx,
16980                 NULL,
16981         },
16982 };
16983
16984 /* Clear input set */
16985 struct cmd_clear_input_set_result {
16986         cmdline_fixed_string_t port;
16987         cmdline_fixed_string_t cfg;
16988         portid_t port_id;
16989         cmdline_fixed_string_t pctype;
16990         uint8_t pctype_id;
16991         cmdline_fixed_string_t inset_type;
16992         cmdline_fixed_string_t clear;
16993         cmdline_fixed_string_t all;
16994 };
16995
16996 static void
16997 cmd_clear_input_set_parsed(
16998         __attribute__((unused)) void *parsed_result,
16999         __attribute__((unused)) struct cmdline *cl,
17000         __attribute__((unused)) void *data)
17001 {
17002 #ifdef RTE_LIBRTE_I40E_PMD
17003         struct cmd_clear_input_set_result *res = parsed_result;
17004         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17005         struct rte_pmd_i40e_inset inset;
17006 #endif
17007         int ret = -ENOTSUP;
17008
17009         if (!all_ports_stopped()) {
17010                 printf("Please stop all ports first\n");
17011                 return;
17012         }
17013
17014 #ifdef RTE_LIBRTE_I40E_PMD
17015         if (!strcmp(res->inset_type, "hash_inset"))
17016                 inset_type = INSET_HASH;
17017         else if (!strcmp(res->inset_type, "fdir_inset"))
17018                 inset_type = INSET_FDIR;
17019         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17020                 inset_type = INSET_FDIR_FLX;
17021
17022         memset(&inset, 0, sizeof(inset));
17023
17024         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17025                                      &inset, inset_type);
17026         if (ret) {
17027                 printf("Failed to clear input set.\n");
17028                 return;
17029         }
17030
17031 #endif
17032
17033         if (ret == -ENOTSUP)
17034                 printf("Function not supported\n");
17035 }
17036
17037 cmdline_parse_token_string_t cmd_clear_input_set_port =
17038         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17039                                  port, "port");
17040 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17041         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17042                                  cfg, "config");
17043 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17044         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17045                               port_id, UINT16);
17046 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17047         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17048                                  pctype, "pctype");
17049 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17050         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17051                               pctype_id, UINT8);
17052 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17053         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17054                                  inset_type,
17055                                  "hash_inset#fdir_inset#fdir_flx_inset");
17056 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17057         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17058                                  clear, "clear");
17059 cmdline_parse_token_string_t cmd_clear_input_set_all =
17060         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17061                                  all, "all");
17062
17063 cmdline_parse_inst_t cmd_clear_input_set = {
17064         .f = cmd_clear_input_set_parsed,
17065         .data = NULL,
17066         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17067                     "fdir_inset|fdir_flx_inset clear all",
17068         .tokens = {
17069                 (void *)&cmd_clear_input_set_port,
17070                 (void *)&cmd_clear_input_set_cfg,
17071                 (void *)&cmd_clear_input_set_port_id,
17072                 (void *)&cmd_clear_input_set_pctype,
17073                 (void *)&cmd_clear_input_set_pctype_id,
17074                 (void *)&cmd_clear_input_set_inset_type,
17075                 (void *)&cmd_clear_input_set_clear,
17076                 (void *)&cmd_clear_input_set_all,
17077                 NULL,
17078         },
17079 };
17080
17081 /* show vf stats */
17082
17083 /* Common result structure for show vf stats */
17084 struct cmd_show_vf_stats_result {
17085         cmdline_fixed_string_t show;
17086         cmdline_fixed_string_t vf;
17087         cmdline_fixed_string_t stats;
17088         portid_t port_id;
17089         uint16_t vf_id;
17090 };
17091
17092 /* Common CLI fields show vf stats*/
17093 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17094         TOKEN_STRING_INITIALIZER
17095                 (struct cmd_show_vf_stats_result,
17096                  show, "show");
17097 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17098         TOKEN_STRING_INITIALIZER
17099                 (struct cmd_show_vf_stats_result,
17100                  vf, "vf");
17101 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17102         TOKEN_STRING_INITIALIZER
17103                 (struct cmd_show_vf_stats_result,
17104                  stats, "stats");
17105 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17106         TOKEN_NUM_INITIALIZER
17107                 (struct cmd_show_vf_stats_result,
17108                  port_id, UINT16);
17109 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17110         TOKEN_NUM_INITIALIZER
17111                 (struct cmd_show_vf_stats_result,
17112                  vf_id, UINT16);
17113
17114 static void
17115 cmd_show_vf_stats_parsed(
17116         void *parsed_result,
17117         __attribute__((unused)) struct cmdline *cl,
17118         __attribute__((unused)) void *data)
17119 {
17120         struct cmd_show_vf_stats_result *res = parsed_result;
17121         struct rte_eth_stats stats;
17122         int ret = -ENOTSUP;
17123         static const char *nic_stats_border = "########################";
17124
17125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17126                 return;
17127
17128         memset(&stats, 0, sizeof(stats));
17129
17130 #ifdef RTE_LIBRTE_I40E_PMD
17131         if (ret == -ENOTSUP)
17132                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17133                                                 res->vf_id,
17134                                                 &stats);
17135 #endif
17136 #ifdef RTE_LIBRTE_BNXT_PMD
17137         if (ret == -ENOTSUP)
17138                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17139                                                 res->vf_id,
17140                                                 &stats);
17141 #endif
17142
17143         switch (ret) {
17144         case 0:
17145                 break;
17146         case -EINVAL:
17147                 printf("invalid vf_id %d\n", res->vf_id);
17148                 break;
17149         case -ENODEV:
17150                 printf("invalid port_id %d\n", res->port_id);
17151                 break;
17152         case -ENOTSUP:
17153                 printf("function not implemented\n");
17154                 break;
17155         default:
17156                 printf("programming error: (%s)\n", strerror(-ret));
17157         }
17158
17159         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17160                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17161
17162         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17163                "%-"PRIu64"\n",
17164                stats.ipackets, stats.imissed, stats.ibytes);
17165         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17166         printf("  RX-nombuf:  %-10"PRIu64"\n",
17167                stats.rx_nombuf);
17168         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17169                "%-"PRIu64"\n",
17170                stats.opackets, stats.oerrors, stats.obytes);
17171
17172         printf("  %s############################%s\n",
17173                                nic_stats_border, nic_stats_border);
17174 }
17175
17176 cmdline_parse_inst_t cmd_show_vf_stats = {
17177         .f = cmd_show_vf_stats_parsed,
17178         .data = NULL,
17179         .help_str = "show vf stats <port_id> <vf_id>",
17180         .tokens = {
17181                 (void *)&cmd_show_vf_stats_show,
17182                 (void *)&cmd_show_vf_stats_vf,
17183                 (void *)&cmd_show_vf_stats_stats,
17184                 (void *)&cmd_show_vf_stats_port_id,
17185                 (void *)&cmd_show_vf_stats_vf_id,
17186                 NULL,
17187         },
17188 };
17189
17190 /* clear vf stats */
17191
17192 /* Common result structure for clear vf stats */
17193 struct cmd_clear_vf_stats_result {
17194         cmdline_fixed_string_t clear;
17195         cmdline_fixed_string_t vf;
17196         cmdline_fixed_string_t stats;
17197         portid_t port_id;
17198         uint16_t vf_id;
17199 };
17200
17201 /* Common CLI fields clear vf stats*/
17202 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17203         TOKEN_STRING_INITIALIZER
17204                 (struct cmd_clear_vf_stats_result,
17205                  clear, "clear");
17206 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17207         TOKEN_STRING_INITIALIZER
17208                 (struct cmd_clear_vf_stats_result,
17209                  vf, "vf");
17210 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_clear_vf_stats_result,
17213                  stats, "stats");
17214 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17215         TOKEN_NUM_INITIALIZER
17216                 (struct cmd_clear_vf_stats_result,
17217                  port_id, UINT16);
17218 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17219         TOKEN_NUM_INITIALIZER
17220                 (struct cmd_clear_vf_stats_result,
17221                  vf_id, UINT16);
17222
17223 static void
17224 cmd_clear_vf_stats_parsed(
17225         void *parsed_result,
17226         __attribute__((unused)) struct cmdline *cl,
17227         __attribute__((unused)) void *data)
17228 {
17229         struct cmd_clear_vf_stats_result *res = parsed_result;
17230         int ret = -ENOTSUP;
17231
17232         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17233                 return;
17234
17235 #ifdef RTE_LIBRTE_I40E_PMD
17236         if (ret == -ENOTSUP)
17237                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17238                                                   res->vf_id);
17239 #endif
17240 #ifdef RTE_LIBRTE_BNXT_PMD
17241         if (ret == -ENOTSUP)
17242                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17243                                                   res->vf_id);
17244 #endif
17245
17246         switch (ret) {
17247         case 0:
17248                 break;
17249         case -EINVAL:
17250                 printf("invalid vf_id %d\n", res->vf_id);
17251                 break;
17252         case -ENODEV:
17253                 printf("invalid port_id %d\n", res->port_id);
17254                 break;
17255         case -ENOTSUP:
17256                 printf("function not implemented\n");
17257                 break;
17258         default:
17259                 printf("programming error: (%s)\n", strerror(-ret));
17260         }
17261 }
17262
17263 cmdline_parse_inst_t cmd_clear_vf_stats = {
17264         .f = cmd_clear_vf_stats_parsed,
17265         .data = NULL,
17266         .help_str = "clear vf stats <port_id> <vf_id>",
17267         .tokens = {
17268                 (void *)&cmd_clear_vf_stats_clear,
17269                 (void *)&cmd_clear_vf_stats_vf,
17270                 (void *)&cmd_clear_vf_stats_stats,
17271                 (void *)&cmd_clear_vf_stats_port_id,
17272                 (void *)&cmd_clear_vf_stats_vf_id,
17273                 NULL,
17274         },
17275 };
17276
17277 /* port config pctype mapping reset */
17278
17279 /* Common result structure for port config pctype mapping reset */
17280 struct cmd_pctype_mapping_reset_result {
17281         cmdline_fixed_string_t port;
17282         cmdline_fixed_string_t config;
17283         portid_t port_id;
17284         cmdline_fixed_string_t pctype;
17285         cmdline_fixed_string_t mapping;
17286         cmdline_fixed_string_t reset;
17287 };
17288
17289 /* Common CLI fields for port config pctype mapping reset*/
17290 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_pctype_mapping_reset_result,
17293                  port, "port");
17294 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_pctype_mapping_reset_result,
17297                  config, "config");
17298 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17299         TOKEN_NUM_INITIALIZER
17300                 (struct cmd_pctype_mapping_reset_result,
17301                  port_id, UINT16);
17302 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17303         TOKEN_STRING_INITIALIZER
17304                 (struct cmd_pctype_mapping_reset_result,
17305                  pctype, "pctype");
17306 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17307         TOKEN_STRING_INITIALIZER
17308                 (struct cmd_pctype_mapping_reset_result,
17309                  mapping, "mapping");
17310 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17311         TOKEN_STRING_INITIALIZER
17312                 (struct cmd_pctype_mapping_reset_result,
17313                  reset, "reset");
17314
17315 static void
17316 cmd_pctype_mapping_reset_parsed(
17317         void *parsed_result,
17318         __attribute__((unused)) struct cmdline *cl,
17319         __attribute__((unused)) void *data)
17320 {
17321         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17322         int ret = -ENOTSUP;
17323
17324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17325                 return;
17326
17327 #ifdef RTE_LIBRTE_I40E_PMD
17328         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17329 #endif
17330
17331         switch (ret) {
17332         case 0:
17333                 break;
17334         case -ENODEV:
17335                 printf("invalid port_id %d\n", res->port_id);
17336                 break;
17337         case -ENOTSUP:
17338                 printf("function not implemented\n");
17339                 break;
17340         default:
17341                 printf("programming error: (%s)\n", strerror(-ret));
17342         }
17343 }
17344
17345 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17346         .f = cmd_pctype_mapping_reset_parsed,
17347         .data = NULL,
17348         .help_str = "port config <port_id> pctype mapping reset",
17349         .tokens = {
17350                 (void *)&cmd_pctype_mapping_reset_port,
17351                 (void *)&cmd_pctype_mapping_reset_config,
17352                 (void *)&cmd_pctype_mapping_reset_port_id,
17353                 (void *)&cmd_pctype_mapping_reset_pctype,
17354                 (void *)&cmd_pctype_mapping_reset_mapping,
17355                 (void *)&cmd_pctype_mapping_reset_reset,
17356                 NULL,
17357         },
17358 };
17359
17360 /* show port pctype mapping */
17361
17362 /* Common result structure for show port pctype mapping */
17363 struct cmd_pctype_mapping_get_result {
17364         cmdline_fixed_string_t show;
17365         cmdline_fixed_string_t port;
17366         portid_t port_id;
17367         cmdline_fixed_string_t pctype;
17368         cmdline_fixed_string_t mapping;
17369 };
17370
17371 /* Common CLI fields for pctype mapping get */
17372 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17373         TOKEN_STRING_INITIALIZER
17374                 (struct cmd_pctype_mapping_get_result,
17375                  show, "show");
17376 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17377         TOKEN_STRING_INITIALIZER
17378                 (struct cmd_pctype_mapping_get_result,
17379                  port, "port");
17380 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17381         TOKEN_NUM_INITIALIZER
17382                 (struct cmd_pctype_mapping_get_result,
17383                  port_id, UINT16);
17384 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17385         TOKEN_STRING_INITIALIZER
17386                 (struct cmd_pctype_mapping_get_result,
17387                  pctype, "pctype");
17388 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_pctype_mapping_get_result,
17391                  mapping, "mapping");
17392
17393 static void
17394 cmd_pctype_mapping_get_parsed(
17395         void *parsed_result,
17396         __attribute__((unused)) struct cmdline *cl,
17397         __attribute__((unused)) void *data)
17398 {
17399         struct cmd_pctype_mapping_get_result *res = parsed_result;
17400         int ret = -ENOTSUP;
17401 #ifdef RTE_LIBRTE_I40E_PMD
17402         struct rte_pmd_i40e_flow_type_mapping
17403                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17404         int i, j, first_pctype;
17405 #endif
17406
17407         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17408                 return;
17409
17410 #ifdef RTE_LIBRTE_I40E_PMD
17411         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17412 #endif
17413
17414         switch (ret) {
17415         case 0:
17416                 break;
17417         case -ENODEV:
17418                 printf("invalid port_id %d\n", res->port_id);
17419                 return;
17420         case -ENOTSUP:
17421                 printf("function not implemented\n");
17422                 return;
17423         default:
17424                 printf("programming error: (%s)\n", strerror(-ret));
17425                 return;
17426         }
17427
17428 #ifdef RTE_LIBRTE_I40E_PMD
17429         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17430                 if (mapping[i].pctype != 0ULL) {
17431                         first_pctype = 1;
17432
17433                         printf("pctype: ");
17434                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17435                                 if (mapping[i].pctype & (1ULL << j)) {
17436                                         printf(first_pctype ?
17437                                                "%02d" : ",%02d", j);
17438                                         first_pctype = 0;
17439                                 }
17440                         }
17441                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17442                 }
17443         }
17444 #endif
17445 }
17446
17447 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17448         .f = cmd_pctype_mapping_get_parsed,
17449         .data = NULL,
17450         .help_str = "show port <port_id> pctype mapping",
17451         .tokens = {
17452                 (void *)&cmd_pctype_mapping_get_show,
17453                 (void *)&cmd_pctype_mapping_get_port,
17454                 (void *)&cmd_pctype_mapping_get_port_id,
17455                 (void *)&cmd_pctype_mapping_get_pctype,
17456                 (void *)&cmd_pctype_mapping_get_mapping,
17457                 NULL,
17458         },
17459 };
17460
17461 /* port config pctype mapping update */
17462
17463 /* Common result structure for port config pctype mapping update */
17464 struct cmd_pctype_mapping_update_result {
17465         cmdline_fixed_string_t port;
17466         cmdline_fixed_string_t config;
17467         portid_t port_id;
17468         cmdline_fixed_string_t pctype;
17469         cmdline_fixed_string_t mapping;
17470         cmdline_fixed_string_t update;
17471         cmdline_fixed_string_t pctype_list;
17472         uint16_t flow_type;
17473 };
17474
17475 /* Common CLI fields for pctype mapping update*/
17476 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17477         TOKEN_STRING_INITIALIZER
17478                 (struct cmd_pctype_mapping_update_result,
17479                  port, "port");
17480 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17481         TOKEN_STRING_INITIALIZER
17482                 (struct cmd_pctype_mapping_update_result,
17483                  config, "config");
17484 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17485         TOKEN_NUM_INITIALIZER
17486                 (struct cmd_pctype_mapping_update_result,
17487                  port_id, UINT16);
17488 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17489         TOKEN_STRING_INITIALIZER
17490                 (struct cmd_pctype_mapping_update_result,
17491                  pctype, "pctype");
17492 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17493         TOKEN_STRING_INITIALIZER
17494                 (struct cmd_pctype_mapping_update_result,
17495                  mapping, "mapping");
17496 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17497         TOKEN_STRING_INITIALIZER
17498                 (struct cmd_pctype_mapping_update_result,
17499                  update, "update");
17500 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17501         TOKEN_STRING_INITIALIZER
17502                 (struct cmd_pctype_mapping_update_result,
17503                  pctype_list, NULL);
17504 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17505         TOKEN_NUM_INITIALIZER
17506                 (struct cmd_pctype_mapping_update_result,
17507                  flow_type, UINT16);
17508
17509 static void
17510 cmd_pctype_mapping_update_parsed(
17511         void *parsed_result,
17512         __attribute__((unused)) struct cmdline *cl,
17513         __attribute__((unused)) void *data)
17514 {
17515         struct cmd_pctype_mapping_update_result *res = parsed_result;
17516         int ret = -ENOTSUP;
17517 #ifdef RTE_LIBRTE_I40E_PMD
17518         struct rte_pmd_i40e_flow_type_mapping mapping;
17519         unsigned int i;
17520         unsigned int nb_item;
17521         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17522 #endif
17523
17524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17525                 return;
17526
17527 #ifdef RTE_LIBRTE_I40E_PMD
17528         nb_item = parse_item_list(res->pctype_list, "pctypes",
17529                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17530         mapping.flow_type = res->flow_type;
17531         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17532                 mapping.pctype |= (1ULL << pctype_list[i]);
17533         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17534                                                 &mapping,
17535                                                 1,
17536                                                 0);
17537 #endif
17538
17539         switch (ret) {
17540         case 0:
17541                 break;
17542         case -EINVAL:
17543                 printf("invalid pctype or flow type\n");
17544                 break;
17545         case -ENODEV:
17546                 printf("invalid port_id %d\n", res->port_id);
17547                 break;
17548         case -ENOTSUP:
17549                 printf("function not implemented\n");
17550                 break;
17551         default:
17552                 printf("programming error: (%s)\n", strerror(-ret));
17553         }
17554 }
17555
17556 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17557         .f = cmd_pctype_mapping_update_parsed,
17558         .data = NULL,
17559         .help_str = "port config <port_id> pctype mapping update"
17560         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17561         .tokens = {
17562                 (void *)&cmd_pctype_mapping_update_port,
17563                 (void *)&cmd_pctype_mapping_update_config,
17564                 (void *)&cmd_pctype_mapping_update_port_id,
17565                 (void *)&cmd_pctype_mapping_update_pctype,
17566                 (void *)&cmd_pctype_mapping_update_mapping,
17567                 (void *)&cmd_pctype_mapping_update_update,
17568                 (void *)&cmd_pctype_mapping_update_pc_type,
17569                 (void *)&cmd_pctype_mapping_update_flow_type,
17570                 NULL,
17571         },
17572 };
17573
17574 /* ptype mapping get */
17575
17576 /* Common result structure for ptype mapping get */
17577 struct cmd_ptype_mapping_get_result {
17578         cmdline_fixed_string_t ptype;
17579         cmdline_fixed_string_t mapping;
17580         cmdline_fixed_string_t get;
17581         portid_t port_id;
17582         uint8_t valid_only;
17583 };
17584
17585 /* Common CLI fields for ptype mapping get */
17586 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17587         TOKEN_STRING_INITIALIZER
17588                 (struct cmd_ptype_mapping_get_result,
17589                  ptype, "ptype");
17590 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17591         TOKEN_STRING_INITIALIZER
17592                 (struct cmd_ptype_mapping_get_result,
17593                  mapping, "mapping");
17594 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17595         TOKEN_STRING_INITIALIZER
17596                 (struct cmd_ptype_mapping_get_result,
17597                  get, "get");
17598 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17599         TOKEN_NUM_INITIALIZER
17600                 (struct cmd_ptype_mapping_get_result,
17601                  port_id, UINT16);
17602 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17603         TOKEN_NUM_INITIALIZER
17604                 (struct cmd_ptype_mapping_get_result,
17605                  valid_only, UINT8);
17606
17607 static void
17608 cmd_ptype_mapping_get_parsed(
17609         void *parsed_result,
17610         __attribute__((unused)) struct cmdline *cl,
17611         __attribute__((unused)) void *data)
17612 {
17613         struct cmd_ptype_mapping_get_result *res = parsed_result;
17614         int ret = -ENOTSUP;
17615 #ifdef RTE_LIBRTE_I40E_PMD
17616         int max_ptype_num = 256;
17617         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17618         uint16_t count;
17619         int i;
17620 #endif
17621
17622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17623                 return;
17624
17625 #ifdef RTE_LIBRTE_I40E_PMD
17626         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17627                                         mapping,
17628                                         max_ptype_num,
17629                                         &count,
17630                                         res->valid_only);
17631 #endif
17632
17633         switch (ret) {
17634         case 0:
17635                 break;
17636         case -ENODEV:
17637                 printf("invalid port_id %d\n", res->port_id);
17638                 break;
17639         case -ENOTSUP:
17640                 printf("function not implemented\n");
17641                 break;
17642         default:
17643                 printf("programming error: (%s)\n", strerror(-ret));
17644         }
17645
17646 #ifdef RTE_LIBRTE_I40E_PMD
17647         if (!ret) {
17648                 for (i = 0; i < count; i++)
17649                         printf("%3d\t0x%08x\n",
17650                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17651         }
17652 #endif
17653 }
17654
17655 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17656         .f = cmd_ptype_mapping_get_parsed,
17657         .data = NULL,
17658         .help_str = "ptype mapping get <port_id> <valid_only>",
17659         .tokens = {
17660                 (void *)&cmd_ptype_mapping_get_ptype,
17661                 (void *)&cmd_ptype_mapping_get_mapping,
17662                 (void *)&cmd_ptype_mapping_get_get,
17663                 (void *)&cmd_ptype_mapping_get_port_id,
17664                 (void *)&cmd_ptype_mapping_get_valid_only,
17665                 NULL,
17666         },
17667 };
17668
17669 /* ptype mapping replace */
17670
17671 /* Common result structure for ptype mapping replace */
17672 struct cmd_ptype_mapping_replace_result {
17673         cmdline_fixed_string_t ptype;
17674         cmdline_fixed_string_t mapping;
17675         cmdline_fixed_string_t replace;
17676         portid_t port_id;
17677         uint32_t target;
17678         uint8_t mask;
17679         uint32_t pkt_type;
17680 };
17681
17682 /* Common CLI fields for ptype mapping replace */
17683 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17684         TOKEN_STRING_INITIALIZER
17685                 (struct cmd_ptype_mapping_replace_result,
17686                  ptype, "ptype");
17687 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17688         TOKEN_STRING_INITIALIZER
17689                 (struct cmd_ptype_mapping_replace_result,
17690                  mapping, "mapping");
17691 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17692         TOKEN_STRING_INITIALIZER
17693                 (struct cmd_ptype_mapping_replace_result,
17694                  replace, "replace");
17695 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17696         TOKEN_NUM_INITIALIZER
17697                 (struct cmd_ptype_mapping_replace_result,
17698                  port_id, UINT16);
17699 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17700         TOKEN_NUM_INITIALIZER
17701                 (struct cmd_ptype_mapping_replace_result,
17702                  target, UINT32);
17703 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17704         TOKEN_NUM_INITIALIZER
17705                 (struct cmd_ptype_mapping_replace_result,
17706                  mask, UINT8);
17707 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17708         TOKEN_NUM_INITIALIZER
17709                 (struct cmd_ptype_mapping_replace_result,
17710                  pkt_type, UINT32);
17711
17712 static void
17713 cmd_ptype_mapping_replace_parsed(
17714         void *parsed_result,
17715         __attribute__((unused)) struct cmdline *cl,
17716         __attribute__((unused)) void *data)
17717 {
17718         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17719         int ret = -ENOTSUP;
17720
17721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17722                 return;
17723
17724 #ifdef RTE_LIBRTE_I40E_PMD
17725         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17726                                         res->target,
17727                                         res->mask,
17728                                         res->pkt_type);
17729 #endif
17730
17731         switch (ret) {
17732         case 0:
17733                 break;
17734         case -EINVAL:
17735                 printf("invalid ptype 0x%8x or 0x%8x\n",
17736                                 res->target, res->pkt_type);
17737                 break;
17738         case -ENODEV:
17739                 printf("invalid port_id %d\n", res->port_id);
17740                 break;
17741         case -ENOTSUP:
17742                 printf("function not implemented\n");
17743                 break;
17744         default:
17745                 printf("programming error: (%s)\n", strerror(-ret));
17746         }
17747 }
17748
17749 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17750         .f = cmd_ptype_mapping_replace_parsed,
17751         .data = NULL,
17752         .help_str =
17753                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17754         .tokens = {
17755                 (void *)&cmd_ptype_mapping_replace_ptype,
17756                 (void *)&cmd_ptype_mapping_replace_mapping,
17757                 (void *)&cmd_ptype_mapping_replace_replace,
17758                 (void *)&cmd_ptype_mapping_replace_port_id,
17759                 (void *)&cmd_ptype_mapping_replace_target,
17760                 (void *)&cmd_ptype_mapping_replace_mask,
17761                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17762                 NULL,
17763         },
17764 };
17765
17766 /* ptype mapping reset */
17767
17768 /* Common result structure for ptype mapping reset */
17769 struct cmd_ptype_mapping_reset_result {
17770         cmdline_fixed_string_t ptype;
17771         cmdline_fixed_string_t mapping;
17772         cmdline_fixed_string_t reset;
17773         portid_t port_id;
17774 };
17775
17776 /* Common CLI fields for ptype mapping reset*/
17777 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17778         TOKEN_STRING_INITIALIZER
17779                 (struct cmd_ptype_mapping_reset_result,
17780                  ptype, "ptype");
17781 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17782         TOKEN_STRING_INITIALIZER
17783                 (struct cmd_ptype_mapping_reset_result,
17784                  mapping, "mapping");
17785 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17786         TOKEN_STRING_INITIALIZER
17787                 (struct cmd_ptype_mapping_reset_result,
17788                  reset, "reset");
17789 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17790         TOKEN_NUM_INITIALIZER
17791                 (struct cmd_ptype_mapping_reset_result,
17792                  port_id, UINT16);
17793
17794 static void
17795 cmd_ptype_mapping_reset_parsed(
17796         void *parsed_result,
17797         __attribute__((unused)) struct cmdline *cl,
17798         __attribute__((unused)) void *data)
17799 {
17800         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17801         int ret = -ENOTSUP;
17802
17803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17804                 return;
17805
17806 #ifdef RTE_LIBRTE_I40E_PMD
17807         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17808 #endif
17809
17810         switch (ret) {
17811         case 0:
17812                 break;
17813         case -ENODEV:
17814                 printf("invalid port_id %d\n", res->port_id);
17815                 break;
17816         case -ENOTSUP:
17817                 printf("function not implemented\n");
17818                 break;
17819         default:
17820                 printf("programming error: (%s)\n", strerror(-ret));
17821         }
17822 }
17823
17824 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17825         .f = cmd_ptype_mapping_reset_parsed,
17826         .data = NULL,
17827         .help_str = "ptype mapping reset <port_id>",
17828         .tokens = {
17829                 (void *)&cmd_ptype_mapping_reset_ptype,
17830                 (void *)&cmd_ptype_mapping_reset_mapping,
17831                 (void *)&cmd_ptype_mapping_reset_reset,
17832                 (void *)&cmd_ptype_mapping_reset_port_id,
17833                 NULL,
17834         },
17835 };
17836
17837 /* ptype mapping update */
17838
17839 /* Common result structure for ptype mapping update */
17840 struct cmd_ptype_mapping_update_result {
17841         cmdline_fixed_string_t ptype;
17842         cmdline_fixed_string_t mapping;
17843         cmdline_fixed_string_t reset;
17844         portid_t port_id;
17845         uint8_t hw_ptype;
17846         uint32_t sw_ptype;
17847 };
17848
17849 /* Common CLI fields for ptype mapping update*/
17850 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17851         TOKEN_STRING_INITIALIZER
17852                 (struct cmd_ptype_mapping_update_result,
17853                  ptype, "ptype");
17854 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17855         TOKEN_STRING_INITIALIZER
17856                 (struct cmd_ptype_mapping_update_result,
17857                  mapping, "mapping");
17858 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17859         TOKEN_STRING_INITIALIZER
17860                 (struct cmd_ptype_mapping_update_result,
17861                  reset, "update");
17862 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17863         TOKEN_NUM_INITIALIZER
17864                 (struct cmd_ptype_mapping_update_result,
17865                  port_id, UINT16);
17866 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17867         TOKEN_NUM_INITIALIZER
17868                 (struct cmd_ptype_mapping_update_result,
17869                  hw_ptype, UINT8);
17870 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17871         TOKEN_NUM_INITIALIZER
17872                 (struct cmd_ptype_mapping_update_result,
17873                  sw_ptype, UINT32);
17874
17875 static void
17876 cmd_ptype_mapping_update_parsed(
17877         void *parsed_result,
17878         __attribute__((unused)) struct cmdline *cl,
17879         __attribute__((unused)) void *data)
17880 {
17881         struct cmd_ptype_mapping_update_result *res = parsed_result;
17882         int ret = -ENOTSUP;
17883 #ifdef RTE_LIBRTE_I40E_PMD
17884         struct rte_pmd_i40e_ptype_mapping mapping;
17885 #endif
17886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17887                 return;
17888
17889 #ifdef RTE_LIBRTE_I40E_PMD
17890         mapping.hw_ptype = res->hw_ptype;
17891         mapping.sw_ptype = res->sw_ptype;
17892         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17893                                                 &mapping,
17894                                                 1,
17895                                                 0);
17896 #endif
17897
17898         switch (ret) {
17899         case 0:
17900                 break;
17901         case -EINVAL:
17902                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17903                 break;
17904         case -ENODEV:
17905                 printf("invalid port_id %d\n", res->port_id);
17906                 break;
17907         case -ENOTSUP:
17908                 printf("function not implemented\n");
17909                 break;
17910         default:
17911                 printf("programming error: (%s)\n", strerror(-ret));
17912         }
17913 }
17914
17915 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17916         .f = cmd_ptype_mapping_update_parsed,
17917         .data = NULL,
17918         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17919         .tokens = {
17920                 (void *)&cmd_ptype_mapping_update_ptype,
17921                 (void *)&cmd_ptype_mapping_update_mapping,
17922                 (void *)&cmd_ptype_mapping_update_update,
17923                 (void *)&cmd_ptype_mapping_update_port_id,
17924                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17925                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17926                 NULL,
17927         },
17928 };
17929
17930 /* Common result structure for file commands */
17931 struct cmd_cmdfile_result {
17932         cmdline_fixed_string_t load;
17933         cmdline_fixed_string_t filename;
17934 };
17935
17936 /* Common CLI fields for file commands */
17937 cmdline_parse_token_string_t cmd_load_cmdfile =
17938         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17939 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17940         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17941
17942 static void
17943 cmd_load_from_file_parsed(
17944         void *parsed_result,
17945         __attribute__((unused)) struct cmdline *cl,
17946         __attribute__((unused)) void *data)
17947 {
17948         struct cmd_cmdfile_result *res = parsed_result;
17949
17950         cmdline_read_from_file(res->filename);
17951 }
17952
17953 cmdline_parse_inst_t cmd_load_from_file = {
17954         .f = cmd_load_from_file_parsed,
17955         .data = NULL,
17956         .help_str = "load <filename>",
17957         .tokens = {
17958                 (void *)&cmd_load_cmdfile,
17959                 (void *)&cmd_load_cmdfile_filename,
17960                 NULL,
17961         },
17962 };
17963
17964 /* Get Rx offloads capabilities */
17965 struct cmd_rx_offload_get_capa_result {
17966         cmdline_fixed_string_t show;
17967         cmdline_fixed_string_t port;
17968         portid_t port_id;
17969         cmdline_fixed_string_t rx_offload;
17970         cmdline_fixed_string_t capabilities;
17971 };
17972
17973 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17974         TOKEN_STRING_INITIALIZER
17975                 (struct cmd_rx_offload_get_capa_result,
17976                  show, "show");
17977 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17978         TOKEN_STRING_INITIALIZER
17979                 (struct cmd_rx_offload_get_capa_result,
17980                  port, "port");
17981 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17982         TOKEN_NUM_INITIALIZER
17983                 (struct cmd_rx_offload_get_capa_result,
17984                  port_id, UINT16);
17985 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17986         TOKEN_STRING_INITIALIZER
17987                 (struct cmd_rx_offload_get_capa_result,
17988                  rx_offload, "rx_offload");
17989 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17990         TOKEN_STRING_INITIALIZER
17991                 (struct cmd_rx_offload_get_capa_result,
17992                  capabilities, "capabilities");
17993
17994 static void
17995 print_rx_offloads(uint64_t offloads)
17996 {
17997         uint64_t single_offload;
17998         int begin;
17999         int end;
18000         int bit;
18001
18002         if (offloads == 0)
18003                 return;
18004
18005         begin = __builtin_ctzll(offloads);
18006         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18007
18008         single_offload = 1ULL << begin;
18009         for (bit = begin; bit < end; bit++) {
18010                 if (offloads & single_offload)
18011                         printf(" %s",
18012                                rte_eth_dev_rx_offload_name(single_offload));
18013                 single_offload <<= 1;
18014         }
18015 }
18016
18017 static void
18018 cmd_rx_offload_get_capa_parsed(
18019         void *parsed_result,
18020         __attribute__((unused)) struct cmdline *cl,
18021         __attribute__((unused)) void *data)
18022 {
18023         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18024         struct rte_eth_dev_info dev_info;
18025         portid_t port_id = res->port_id;
18026         uint64_t queue_offloads;
18027         uint64_t port_offloads;
18028         int ret;
18029
18030         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18031         if (ret != 0)
18032                 return;
18033
18034         queue_offloads = dev_info.rx_queue_offload_capa;
18035         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18036
18037         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18038         printf("  Per Queue :");
18039         print_rx_offloads(queue_offloads);
18040
18041         printf("\n");
18042         printf("  Per Port  :");
18043         print_rx_offloads(port_offloads);
18044         printf("\n\n");
18045 }
18046
18047 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18048         .f = cmd_rx_offload_get_capa_parsed,
18049         .data = NULL,
18050         .help_str = "show port <port_id> rx_offload capabilities",
18051         .tokens = {
18052                 (void *)&cmd_rx_offload_get_capa_show,
18053                 (void *)&cmd_rx_offload_get_capa_port,
18054                 (void *)&cmd_rx_offload_get_capa_port_id,
18055                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18056                 (void *)&cmd_rx_offload_get_capa_capabilities,
18057                 NULL,
18058         }
18059 };
18060
18061 /* Get Rx offloads configuration */
18062 struct cmd_rx_offload_get_configuration_result {
18063         cmdline_fixed_string_t show;
18064         cmdline_fixed_string_t port;
18065         portid_t port_id;
18066         cmdline_fixed_string_t rx_offload;
18067         cmdline_fixed_string_t configuration;
18068 };
18069
18070 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18071         TOKEN_STRING_INITIALIZER
18072                 (struct cmd_rx_offload_get_configuration_result,
18073                  show, "show");
18074 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18075         TOKEN_STRING_INITIALIZER
18076                 (struct cmd_rx_offload_get_configuration_result,
18077                  port, "port");
18078 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18079         TOKEN_NUM_INITIALIZER
18080                 (struct cmd_rx_offload_get_configuration_result,
18081                  port_id, UINT16);
18082 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18083         TOKEN_STRING_INITIALIZER
18084                 (struct cmd_rx_offload_get_configuration_result,
18085                  rx_offload, "rx_offload");
18086 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18087         TOKEN_STRING_INITIALIZER
18088                 (struct cmd_rx_offload_get_configuration_result,
18089                  configuration, "configuration");
18090
18091 static void
18092 cmd_rx_offload_get_configuration_parsed(
18093         void *parsed_result,
18094         __attribute__((unused)) struct cmdline *cl,
18095         __attribute__((unused)) void *data)
18096 {
18097         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18098         struct rte_eth_dev_info dev_info;
18099         portid_t port_id = res->port_id;
18100         struct rte_port *port = &ports[port_id];
18101         uint64_t port_offloads;
18102         uint64_t queue_offloads;
18103         uint16_t nb_rx_queues;
18104         int q;
18105         int ret;
18106
18107         printf("Rx Offloading Configuration of port %d :\n", port_id);
18108
18109         port_offloads = port->dev_conf.rxmode.offloads;
18110         printf("  Port :");
18111         print_rx_offloads(port_offloads);
18112         printf("\n");
18113
18114         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18115         if (ret != 0)
18116                 return;
18117
18118         nb_rx_queues = dev_info.nb_rx_queues;
18119         for (q = 0; q < nb_rx_queues; q++) {
18120                 queue_offloads = port->rx_conf[q].offloads;
18121                 printf("  Queue[%2d] :", q);
18122                 print_rx_offloads(queue_offloads);
18123                 printf("\n");
18124         }
18125         printf("\n");
18126 }
18127
18128 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18129         .f = cmd_rx_offload_get_configuration_parsed,
18130         .data = NULL,
18131         .help_str = "show port <port_id> rx_offload configuration",
18132         .tokens = {
18133                 (void *)&cmd_rx_offload_get_configuration_show,
18134                 (void *)&cmd_rx_offload_get_configuration_port,
18135                 (void *)&cmd_rx_offload_get_configuration_port_id,
18136                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18137                 (void *)&cmd_rx_offload_get_configuration_configuration,
18138                 NULL,
18139         }
18140 };
18141
18142 /* Enable/Disable a per port offloading */
18143 struct cmd_config_per_port_rx_offload_result {
18144         cmdline_fixed_string_t port;
18145         cmdline_fixed_string_t config;
18146         portid_t port_id;
18147         cmdline_fixed_string_t rx_offload;
18148         cmdline_fixed_string_t offload;
18149         cmdline_fixed_string_t on_off;
18150 };
18151
18152 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18153         TOKEN_STRING_INITIALIZER
18154                 (struct cmd_config_per_port_rx_offload_result,
18155                  port, "port");
18156 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18157         TOKEN_STRING_INITIALIZER
18158                 (struct cmd_config_per_port_rx_offload_result,
18159                  config, "config");
18160 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18161         TOKEN_NUM_INITIALIZER
18162                 (struct cmd_config_per_port_rx_offload_result,
18163                  port_id, UINT16);
18164 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18165         TOKEN_STRING_INITIALIZER
18166                 (struct cmd_config_per_port_rx_offload_result,
18167                  rx_offload, "rx_offload");
18168 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18169         TOKEN_STRING_INITIALIZER
18170                 (struct cmd_config_per_port_rx_offload_result,
18171                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18172                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18173                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18174                            "scatter#timestamp#security#keep_crc#rss_hash");
18175 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18176         TOKEN_STRING_INITIALIZER
18177                 (struct cmd_config_per_port_rx_offload_result,
18178                  on_off, "on#off");
18179
18180 static uint64_t
18181 search_rx_offload(const char *name)
18182 {
18183         uint64_t single_offload;
18184         const char *single_name;
18185         int found = 0;
18186         unsigned int bit;
18187
18188         single_offload = 1;
18189         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18190                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18191                 if (!strcasecmp(single_name, name)) {
18192                         found = 1;
18193                         break;
18194                 }
18195                 single_offload <<= 1;
18196         }
18197
18198         if (found)
18199                 return single_offload;
18200
18201         return 0;
18202 }
18203
18204 static void
18205 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18206                                 __attribute__((unused)) struct cmdline *cl,
18207                                 __attribute__((unused)) void *data)
18208 {
18209         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18210         portid_t port_id = res->port_id;
18211         struct rte_eth_dev_info dev_info;
18212         struct rte_port *port = &ports[port_id];
18213         uint64_t single_offload;
18214         uint16_t nb_rx_queues;
18215         int q;
18216         int ret;
18217
18218         if (port->port_status != RTE_PORT_STOPPED) {
18219                 printf("Error: Can't config offload when Port %d "
18220                        "is not stopped\n", port_id);
18221                 return;
18222         }
18223
18224         single_offload = search_rx_offload(res->offload);
18225         if (single_offload == 0) {
18226                 printf("Unknown offload name: %s\n", res->offload);
18227                 return;
18228         }
18229
18230         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18231         if (ret != 0)
18232                 return;
18233
18234         nb_rx_queues = dev_info.nb_rx_queues;
18235         if (!strcmp(res->on_off, "on")) {
18236                 port->dev_conf.rxmode.offloads |= single_offload;
18237                 for (q = 0; q < nb_rx_queues; q++)
18238                         port->rx_conf[q].offloads |= single_offload;
18239         } else {
18240                 port->dev_conf.rxmode.offloads &= ~single_offload;
18241                 for (q = 0; q < nb_rx_queues; q++)
18242                         port->rx_conf[q].offloads &= ~single_offload;
18243         }
18244
18245         cmd_reconfig_device_queue(port_id, 1, 1);
18246 }
18247
18248 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18249         .f = cmd_config_per_port_rx_offload_parsed,
18250         .data = NULL,
18251         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18252                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18253                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18254                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18255                     "on|off",
18256         .tokens = {
18257                 (void *)&cmd_config_per_port_rx_offload_result_port,
18258                 (void *)&cmd_config_per_port_rx_offload_result_config,
18259                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18260                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18261                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18262                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18263                 NULL,
18264         }
18265 };
18266
18267 /* Enable/Disable a per queue offloading */
18268 struct cmd_config_per_queue_rx_offload_result {
18269         cmdline_fixed_string_t port;
18270         portid_t port_id;
18271         cmdline_fixed_string_t rxq;
18272         uint16_t queue_id;
18273         cmdline_fixed_string_t rx_offload;
18274         cmdline_fixed_string_t offload;
18275         cmdline_fixed_string_t on_off;
18276 };
18277
18278 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18279         TOKEN_STRING_INITIALIZER
18280                 (struct cmd_config_per_queue_rx_offload_result,
18281                  port, "port");
18282 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18283         TOKEN_NUM_INITIALIZER
18284                 (struct cmd_config_per_queue_rx_offload_result,
18285                  port_id, UINT16);
18286 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18287         TOKEN_STRING_INITIALIZER
18288                 (struct cmd_config_per_queue_rx_offload_result,
18289                  rxq, "rxq");
18290 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18291         TOKEN_NUM_INITIALIZER
18292                 (struct cmd_config_per_queue_rx_offload_result,
18293                  queue_id, UINT16);
18294 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18295         TOKEN_STRING_INITIALIZER
18296                 (struct cmd_config_per_queue_rx_offload_result,
18297                  rx_offload, "rx_offload");
18298 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18299         TOKEN_STRING_INITIALIZER
18300                 (struct cmd_config_per_queue_rx_offload_result,
18301                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18302                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18303                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18304                            "scatter#timestamp#security#keep_crc");
18305 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18306         TOKEN_STRING_INITIALIZER
18307                 (struct cmd_config_per_queue_rx_offload_result,
18308                  on_off, "on#off");
18309
18310 static void
18311 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18312                                 __attribute__((unused)) struct cmdline *cl,
18313                                 __attribute__((unused)) void *data)
18314 {
18315         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18316         struct rte_eth_dev_info dev_info;
18317         portid_t port_id = res->port_id;
18318         uint16_t queue_id = res->queue_id;
18319         struct rte_port *port = &ports[port_id];
18320         uint64_t single_offload;
18321         int ret;
18322
18323         if (port->port_status != RTE_PORT_STOPPED) {
18324                 printf("Error: Can't config offload when Port %d "
18325                        "is not stopped\n", port_id);
18326                 return;
18327         }
18328
18329         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18330         if (ret != 0)
18331                 return;
18332
18333         if (queue_id >= dev_info.nb_rx_queues) {
18334                 printf("Error: input queue_id should be 0 ... "
18335                        "%d\n", dev_info.nb_rx_queues - 1);
18336                 return;
18337         }
18338
18339         single_offload = search_rx_offload(res->offload);
18340         if (single_offload == 0) {
18341                 printf("Unknown offload name: %s\n", res->offload);
18342                 return;
18343         }
18344
18345         if (!strcmp(res->on_off, "on"))
18346                 port->rx_conf[queue_id].offloads |= single_offload;
18347         else
18348                 port->rx_conf[queue_id].offloads &= ~single_offload;
18349
18350         cmd_reconfig_device_queue(port_id, 1, 1);
18351 }
18352
18353 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18354         .f = cmd_config_per_queue_rx_offload_parsed,
18355         .data = NULL,
18356         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18357                     "vlan_strip|ipv4_cksum|"
18358                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18359                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18360                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18361                     "on|off",
18362         .tokens = {
18363                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18364                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18365                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18366                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18367                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18368                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18369                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18370                 NULL,
18371         }
18372 };
18373
18374 /* Get Tx offloads capabilities */
18375 struct cmd_tx_offload_get_capa_result {
18376         cmdline_fixed_string_t show;
18377         cmdline_fixed_string_t port;
18378         portid_t port_id;
18379         cmdline_fixed_string_t tx_offload;
18380         cmdline_fixed_string_t capabilities;
18381 };
18382
18383 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18384         TOKEN_STRING_INITIALIZER
18385                 (struct cmd_tx_offload_get_capa_result,
18386                  show, "show");
18387 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18388         TOKEN_STRING_INITIALIZER
18389                 (struct cmd_tx_offload_get_capa_result,
18390                  port, "port");
18391 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18392         TOKEN_NUM_INITIALIZER
18393                 (struct cmd_tx_offload_get_capa_result,
18394                  port_id, UINT16);
18395 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18396         TOKEN_STRING_INITIALIZER
18397                 (struct cmd_tx_offload_get_capa_result,
18398                  tx_offload, "tx_offload");
18399 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18400         TOKEN_STRING_INITIALIZER
18401                 (struct cmd_tx_offload_get_capa_result,
18402                  capabilities, "capabilities");
18403
18404 static void
18405 print_tx_offloads(uint64_t offloads)
18406 {
18407         uint64_t single_offload;
18408         int begin;
18409         int end;
18410         int bit;
18411
18412         if (offloads == 0)
18413                 return;
18414
18415         begin = __builtin_ctzll(offloads);
18416         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18417
18418         single_offload = 1ULL << begin;
18419         for (bit = begin; bit < end; bit++) {
18420                 if (offloads & single_offload)
18421                         printf(" %s",
18422                                rte_eth_dev_tx_offload_name(single_offload));
18423                 single_offload <<= 1;
18424         }
18425 }
18426
18427 static void
18428 cmd_tx_offload_get_capa_parsed(
18429         void *parsed_result,
18430         __attribute__((unused)) struct cmdline *cl,
18431         __attribute__((unused)) void *data)
18432 {
18433         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18434         struct rte_eth_dev_info dev_info;
18435         portid_t port_id = res->port_id;
18436         uint64_t queue_offloads;
18437         uint64_t port_offloads;
18438         int ret;
18439
18440         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18441         if (ret != 0)
18442                 return;
18443
18444         queue_offloads = dev_info.tx_queue_offload_capa;
18445         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18446
18447         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18448         printf("  Per Queue :");
18449         print_tx_offloads(queue_offloads);
18450
18451         printf("\n");
18452         printf("  Per Port  :");
18453         print_tx_offloads(port_offloads);
18454         printf("\n\n");
18455 }
18456
18457 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18458         .f = cmd_tx_offload_get_capa_parsed,
18459         .data = NULL,
18460         .help_str = "show port <port_id> tx_offload capabilities",
18461         .tokens = {
18462                 (void *)&cmd_tx_offload_get_capa_show,
18463                 (void *)&cmd_tx_offload_get_capa_port,
18464                 (void *)&cmd_tx_offload_get_capa_port_id,
18465                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18466                 (void *)&cmd_tx_offload_get_capa_capabilities,
18467                 NULL,
18468         }
18469 };
18470
18471 /* Get Tx offloads configuration */
18472 struct cmd_tx_offload_get_configuration_result {
18473         cmdline_fixed_string_t show;
18474         cmdline_fixed_string_t port;
18475         portid_t port_id;
18476         cmdline_fixed_string_t tx_offload;
18477         cmdline_fixed_string_t configuration;
18478 };
18479
18480 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18481         TOKEN_STRING_INITIALIZER
18482                 (struct cmd_tx_offload_get_configuration_result,
18483                  show, "show");
18484 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18485         TOKEN_STRING_INITIALIZER
18486                 (struct cmd_tx_offload_get_configuration_result,
18487                  port, "port");
18488 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18489         TOKEN_NUM_INITIALIZER
18490                 (struct cmd_tx_offload_get_configuration_result,
18491                  port_id, UINT16);
18492 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18493         TOKEN_STRING_INITIALIZER
18494                 (struct cmd_tx_offload_get_configuration_result,
18495                  tx_offload, "tx_offload");
18496 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18497         TOKEN_STRING_INITIALIZER
18498                 (struct cmd_tx_offload_get_configuration_result,
18499                  configuration, "configuration");
18500
18501 static void
18502 cmd_tx_offload_get_configuration_parsed(
18503         void *parsed_result,
18504         __attribute__((unused)) struct cmdline *cl,
18505         __attribute__((unused)) void *data)
18506 {
18507         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18508         struct rte_eth_dev_info dev_info;
18509         portid_t port_id = res->port_id;
18510         struct rte_port *port = &ports[port_id];
18511         uint64_t port_offloads;
18512         uint64_t queue_offloads;
18513         uint16_t nb_tx_queues;
18514         int q;
18515         int ret;
18516
18517         printf("Tx Offloading Configuration of port %d :\n", port_id);
18518
18519         port_offloads = port->dev_conf.txmode.offloads;
18520         printf("  Port :");
18521         print_tx_offloads(port_offloads);
18522         printf("\n");
18523
18524         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18525         if (ret != 0)
18526                 return;
18527
18528         nb_tx_queues = dev_info.nb_tx_queues;
18529         for (q = 0; q < nb_tx_queues; q++) {
18530                 queue_offloads = port->tx_conf[q].offloads;
18531                 printf("  Queue[%2d] :", q);
18532                 print_tx_offloads(queue_offloads);
18533                 printf("\n");
18534         }
18535         printf("\n");
18536 }
18537
18538 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18539         .f = cmd_tx_offload_get_configuration_parsed,
18540         .data = NULL,
18541         .help_str = "show port <port_id> tx_offload configuration",
18542         .tokens = {
18543                 (void *)&cmd_tx_offload_get_configuration_show,
18544                 (void *)&cmd_tx_offload_get_configuration_port,
18545                 (void *)&cmd_tx_offload_get_configuration_port_id,
18546                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18547                 (void *)&cmd_tx_offload_get_configuration_configuration,
18548                 NULL,
18549         }
18550 };
18551
18552 /* Enable/Disable a per port offloading */
18553 struct cmd_config_per_port_tx_offload_result {
18554         cmdline_fixed_string_t port;
18555         cmdline_fixed_string_t config;
18556         portid_t port_id;
18557         cmdline_fixed_string_t tx_offload;
18558         cmdline_fixed_string_t offload;
18559         cmdline_fixed_string_t on_off;
18560 };
18561
18562 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_config_per_port_tx_offload_result,
18565                  port, "port");
18566 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18567         TOKEN_STRING_INITIALIZER
18568                 (struct cmd_config_per_port_tx_offload_result,
18569                  config, "config");
18570 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18571         TOKEN_NUM_INITIALIZER
18572                 (struct cmd_config_per_port_tx_offload_result,
18573                  port_id, UINT16);
18574 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18575         TOKEN_STRING_INITIALIZER
18576                 (struct cmd_config_per_port_tx_offload_result,
18577                  tx_offload, "tx_offload");
18578 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18579         TOKEN_STRING_INITIALIZER
18580                 (struct cmd_config_per_port_tx_offload_result,
18581                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18582                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18583                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18584                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18585                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18586 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18587         TOKEN_STRING_INITIALIZER
18588                 (struct cmd_config_per_port_tx_offload_result,
18589                  on_off, "on#off");
18590
18591 static uint64_t
18592 search_tx_offload(const char *name)
18593 {
18594         uint64_t single_offload;
18595         const char *single_name;
18596         int found = 0;
18597         unsigned int bit;
18598
18599         single_offload = 1;
18600         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18601                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18602                 if (single_name == NULL)
18603                         break;
18604                 if (!strcasecmp(single_name, name)) {
18605                         found = 1;
18606                         break;
18607                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18608                         break;
18609                 single_offload <<= 1;
18610         }
18611
18612         if (found)
18613                 return single_offload;
18614
18615         return 0;
18616 }
18617
18618 static void
18619 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18620                                 __attribute__((unused)) struct cmdline *cl,
18621                                 __attribute__((unused)) void *data)
18622 {
18623         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18624         portid_t port_id = res->port_id;
18625         struct rte_eth_dev_info dev_info;
18626         struct rte_port *port = &ports[port_id];
18627         uint64_t single_offload;
18628         uint16_t nb_tx_queues;
18629         int q;
18630         int ret;
18631
18632         if (port->port_status != RTE_PORT_STOPPED) {
18633                 printf("Error: Can't config offload when Port %d "
18634                        "is not stopped\n", port_id);
18635                 return;
18636         }
18637
18638         single_offload = search_tx_offload(res->offload);
18639         if (single_offload == 0) {
18640                 printf("Unknown offload name: %s\n", res->offload);
18641                 return;
18642         }
18643
18644         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18645         if (ret != 0)
18646                 return;
18647
18648         nb_tx_queues = dev_info.nb_tx_queues;
18649         if (!strcmp(res->on_off, "on")) {
18650                 port->dev_conf.txmode.offloads |= single_offload;
18651                 for (q = 0; q < nb_tx_queues; q++)
18652                         port->tx_conf[q].offloads |= single_offload;
18653         } else {
18654                 port->dev_conf.txmode.offloads &= ~single_offload;
18655                 for (q = 0; q < nb_tx_queues; q++)
18656                         port->tx_conf[q].offloads &= ~single_offload;
18657         }
18658
18659         cmd_reconfig_device_queue(port_id, 1, 1);
18660 }
18661
18662 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18663         .f = cmd_config_per_port_tx_offload_parsed,
18664         .data = NULL,
18665         .help_str = "port config <port_id> tx_offload "
18666                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18667                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18668                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18669                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18670                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18671         .tokens = {
18672                 (void *)&cmd_config_per_port_tx_offload_result_port,
18673                 (void *)&cmd_config_per_port_tx_offload_result_config,
18674                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18675                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18676                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18677                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18678                 NULL,
18679         }
18680 };
18681
18682 /* Enable/Disable a per queue offloading */
18683 struct cmd_config_per_queue_tx_offload_result {
18684         cmdline_fixed_string_t port;
18685         portid_t port_id;
18686         cmdline_fixed_string_t txq;
18687         uint16_t queue_id;
18688         cmdline_fixed_string_t tx_offload;
18689         cmdline_fixed_string_t offload;
18690         cmdline_fixed_string_t on_off;
18691 };
18692
18693 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18694         TOKEN_STRING_INITIALIZER
18695                 (struct cmd_config_per_queue_tx_offload_result,
18696                  port, "port");
18697 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18698         TOKEN_NUM_INITIALIZER
18699                 (struct cmd_config_per_queue_tx_offload_result,
18700                  port_id, UINT16);
18701 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18702         TOKEN_STRING_INITIALIZER
18703                 (struct cmd_config_per_queue_tx_offload_result,
18704                  txq, "txq");
18705 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18706         TOKEN_NUM_INITIALIZER
18707                 (struct cmd_config_per_queue_tx_offload_result,
18708                  queue_id, UINT16);
18709 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18710         TOKEN_STRING_INITIALIZER
18711                 (struct cmd_config_per_queue_tx_offload_result,
18712                  tx_offload, "tx_offload");
18713 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18714         TOKEN_STRING_INITIALIZER
18715                 (struct cmd_config_per_queue_tx_offload_result,
18716                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18717                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18718                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18719                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18720                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18721 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18722         TOKEN_STRING_INITIALIZER
18723                 (struct cmd_config_per_queue_tx_offload_result,
18724                  on_off, "on#off");
18725
18726 static void
18727 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18728                                 __attribute__((unused)) struct cmdline *cl,
18729                                 __attribute__((unused)) void *data)
18730 {
18731         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18732         struct rte_eth_dev_info dev_info;
18733         portid_t port_id = res->port_id;
18734         uint16_t queue_id = res->queue_id;
18735         struct rte_port *port = &ports[port_id];
18736         uint64_t single_offload;
18737         int ret;
18738
18739         if (port->port_status != RTE_PORT_STOPPED) {
18740                 printf("Error: Can't config offload when Port %d "
18741                        "is not stopped\n", port_id);
18742                 return;
18743         }
18744
18745         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18746         if (ret != 0)
18747                 return;
18748
18749         if (queue_id >= dev_info.nb_tx_queues) {
18750                 printf("Error: input queue_id should be 0 ... "
18751                        "%d\n", dev_info.nb_tx_queues - 1);
18752                 return;
18753         }
18754
18755         single_offload = search_tx_offload(res->offload);
18756         if (single_offload == 0) {
18757                 printf("Unknown offload name: %s\n", res->offload);
18758                 return;
18759         }
18760
18761         if (!strcmp(res->on_off, "on"))
18762                 port->tx_conf[queue_id].offloads |= single_offload;
18763         else
18764                 port->tx_conf[queue_id].offloads &= ~single_offload;
18765
18766         cmd_reconfig_device_queue(port_id, 1, 1);
18767 }
18768
18769 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18770         .f = cmd_config_per_queue_tx_offload_parsed,
18771         .data = NULL,
18772         .help_str = "port <port_id> txq <queue_id> tx_offload "
18773                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18774                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18775                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18776                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18777                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18778                     "on|off",
18779         .tokens = {
18780                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18781                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18782                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18783                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18784                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18785                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18786                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18787                 NULL,
18788         }
18789 };
18790
18791 /* *** configure tx_metadata for specific port *** */
18792 struct cmd_config_tx_metadata_specific_result {
18793         cmdline_fixed_string_t port;
18794         cmdline_fixed_string_t keyword;
18795         uint16_t port_id;
18796         cmdline_fixed_string_t item;
18797         uint32_t value;
18798 };
18799
18800 static void
18801 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18802                                 __attribute__((unused)) struct cmdline *cl,
18803                                 __attribute__((unused)) void *data)
18804 {
18805         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18806
18807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18808                 return;
18809         ports[res->port_id].tx_metadata = res->value;
18810         /* Add/remove callback to insert valid metadata in every Tx packet. */
18811         if (ports[res->port_id].tx_metadata)
18812                 add_tx_md_callback(res->port_id);
18813         else
18814                 remove_tx_md_callback(res->port_id);
18815         rte_flow_dynf_metadata_register();
18816 }
18817
18818 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18819         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18820                         port, "port");
18821 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18822         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18823                         keyword, "config");
18824 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18825         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18826                         port_id, UINT16);
18827 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18828         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18829                         item, "tx_metadata");
18830 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18831         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18832                         value, UINT32);
18833
18834 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18835         .f = cmd_config_tx_metadata_specific_parsed,
18836         .data = NULL,
18837         .help_str = "port config <port_id> tx_metadata <value>",
18838         .tokens = {
18839                 (void *)&cmd_config_tx_metadata_specific_port,
18840                 (void *)&cmd_config_tx_metadata_specific_keyword,
18841                 (void *)&cmd_config_tx_metadata_specific_id,
18842                 (void *)&cmd_config_tx_metadata_specific_item,
18843                 (void *)&cmd_config_tx_metadata_specific_value,
18844                 NULL,
18845         },
18846 };
18847
18848 /* *** set dynf *** */
18849 struct cmd_config_tx_dynf_specific_result {
18850         cmdline_fixed_string_t port;
18851         cmdline_fixed_string_t keyword;
18852         uint16_t port_id;
18853         cmdline_fixed_string_t item;
18854         cmdline_fixed_string_t name;
18855         cmdline_fixed_string_t value;
18856 };
18857
18858 static void
18859 cmd_config_dynf_specific_parsed(void *parsed_result,
18860                                 __attribute__((unused)) struct cmdline *cl,
18861                                 __attribute__((unused)) void *data)
18862 {
18863         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18864         struct rte_mbuf_dynflag desc_flag;
18865         int flag;
18866         uint64_t old_port_flags;
18867
18868         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18869                 return;
18870         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18871         if (flag <= 0) {
18872                 if (strlcpy(desc_flag.name, res->name,
18873                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18874                         printf("Flag name too long\n");
18875                         return;
18876                 }
18877                 desc_flag.flags = 0;
18878                 flag = rte_mbuf_dynflag_register(&desc_flag);
18879                 if (flag < 0) {
18880                         printf("Can't register flag\n");
18881                         return;
18882                 }
18883                 strcpy(dynf_names[flag], desc_flag.name);
18884         }
18885         old_port_flags = ports[res->port_id].mbuf_dynf;
18886         if (!strcmp(res->value, "set")) {
18887                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18888                 if (old_port_flags == 0)
18889                         add_tx_dynf_callback(res->port_id);
18890         } else {
18891                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18892                 if (ports[res->port_id].mbuf_dynf == 0)
18893                         remove_tx_dynf_callback(res->port_id);
18894         }
18895 }
18896
18897 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18898         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18899                         keyword, "port");
18900 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18901         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18902                         keyword, "config");
18903 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18904         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18905                         port_id, UINT16);
18906 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18907         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18908                         item, "dynf");
18909 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18910         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18911                         name, NULL);
18912 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18913         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18914                         value, "set#clear");
18915
18916 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18917         .f = cmd_config_dynf_specific_parsed,
18918         .data = NULL,
18919         .help_str = "port config <port id> dynf <name> set|clear",
18920         .tokens = {
18921                 (void *)&cmd_config_tx_dynf_specific_port,
18922                 (void *)&cmd_config_tx_dynf_specific_keyword,
18923                 (void *)&cmd_config_tx_dynf_specific_port_id,
18924                 (void *)&cmd_config_tx_dynf_specific_item,
18925                 (void *)&cmd_config_tx_dynf_specific_name,
18926                 (void *)&cmd_config_tx_dynf_specific_value,
18927                 NULL,
18928         },
18929 };
18930
18931 /* *** display tx_metadata per port configuration *** */
18932 struct cmd_show_tx_metadata_result {
18933         cmdline_fixed_string_t cmd_show;
18934         cmdline_fixed_string_t cmd_port;
18935         cmdline_fixed_string_t cmd_keyword;
18936         portid_t cmd_pid;
18937 };
18938
18939 static void
18940 cmd_show_tx_metadata_parsed(void *parsed_result,
18941                 __attribute__((unused)) struct cmdline *cl,
18942                 __attribute__((unused)) void *data)
18943 {
18944         struct cmd_show_tx_metadata_result *res = parsed_result;
18945
18946         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18947                 printf("invalid port id %u\n", res->cmd_pid);
18948                 return;
18949         }
18950         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18951                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18952                        ports[res->cmd_pid].tx_metadata);
18953         }
18954 }
18955
18956 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18957         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18958                         cmd_show, "show");
18959 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18960         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18961                         cmd_port, "port");
18962 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18963         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18964                         cmd_pid, UINT16);
18965 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18966         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18967                         cmd_keyword, "tx_metadata");
18968
18969 cmdline_parse_inst_t cmd_show_tx_metadata = {
18970         .f = cmd_show_tx_metadata_parsed,
18971         .data = NULL,
18972         .help_str = "show port <port_id> tx_metadata",
18973         .tokens = {
18974                 (void *)&cmd_show_tx_metadata_show,
18975                 (void *)&cmd_show_tx_metadata_port,
18976                 (void *)&cmd_show_tx_metadata_pid,
18977                 (void *)&cmd_show_tx_metadata_keyword,
18978                 NULL,
18979         },
18980 };
18981
18982 /* show port supported ptypes */
18983
18984 /* Common result structure for show port ptypes */
18985 struct cmd_show_port_supported_ptypes_result {
18986         cmdline_fixed_string_t show;
18987         cmdline_fixed_string_t port;
18988         portid_t port_id;
18989         cmdline_fixed_string_t ptypes;
18990 };
18991
18992 /* Common CLI fields for show port ptypes */
18993 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18994         TOKEN_STRING_INITIALIZER
18995                 (struct cmd_show_port_supported_ptypes_result,
18996                  show, "show");
18997 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18998         TOKEN_STRING_INITIALIZER
18999                 (struct cmd_show_port_supported_ptypes_result,
19000                  port, "port");
19001 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19002         TOKEN_NUM_INITIALIZER
19003                 (struct cmd_show_port_supported_ptypes_result,
19004                  port_id, UINT16);
19005 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19006         TOKEN_STRING_INITIALIZER
19007                 (struct cmd_show_port_supported_ptypes_result,
19008                  ptypes, "ptypes");
19009
19010 static void
19011 cmd_show_port_supported_ptypes_parsed(
19012         void *parsed_result,
19013         __attribute__((unused)) struct cmdline *cl,
19014         __attribute__((unused)) void *data)
19015 {
19016 #define RSVD_PTYPE_MASK       0xf0000000
19017 #define MAX_PTYPES_PER_LAYER  16
19018 #define LTYPE_NAMESIZE        32
19019 #define PTYPE_NAMESIZE        256
19020         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19021         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19022         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19023         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19024         uint16_t port_id = res->port_id;
19025         int ret, i;
19026
19027         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19028         if (ret < 0)
19029                 return;
19030
19031         while (ptype_mask != RSVD_PTYPE_MASK) {
19032
19033                 switch (ptype_mask) {
19034                 case RTE_PTYPE_L2_MASK:
19035                         strlcpy(ltype, "L2", sizeof(ltype));
19036                         break;
19037                 case RTE_PTYPE_L3_MASK:
19038                         strlcpy(ltype, "L3", sizeof(ltype));
19039                         break;
19040                 case RTE_PTYPE_L4_MASK:
19041                         strlcpy(ltype, "L4", sizeof(ltype));
19042                         break;
19043                 case RTE_PTYPE_TUNNEL_MASK:
19044                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19045                         break;
19046                 case RTE_PTYPE_INNER_L2_MASK:
19047                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19048                         break;
19049                 case RTE_PTYPE_INNER_L3_MASK:
19050                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19051                         break;
19052                 case RTE_PTYPE_INNER_L4_MASK:
19053                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19054                         break;
19055                 default:
19056                         return;
19057                 }
19058
19059                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19060                                                        ptype_mask, ptypes,
19061                                                        MAX_PTYPES_PER_LAYER);
19062
19063                 if (ret > 0)
19064                         printf("Supported %s ptypes:\n", ltype);
19065                 else
19066                         printf("%s ptypes unsupported\n", ltype);
19067
19068                 for (i = 0; i < ret; ++i) {
19069                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19070                         printf("%s\n", buf);
19071                 }
19072
19073                 ptype_mask <<= 4;
19074         }
19075 }
19076
19077 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19078         .f = cmd_show_port_supported_ptypes_parsed,
19079         .data = NULL,
19080         .help_str = "show port <port_id> ptypes",
19081         .tokens = {
19082                 (void *)&cmd_show_port_supported_ptypes_show,
19083                 (void *)&cmd_show_port_supported_ptypes_port,
19084                 (void *)&cmd_show_port_supported_ptypes_port_id,
19085                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19086                 NULL,
19087         },
19088 };
19089
19090 /* *** display rx/tx descriptor status *** */
19091 struct cmd_show_rx_tx_desc_status_result {
19092         cmdline_fixed_string_t cmd_show;
19093         cmdline_fixed_string_t cmd_port;
19094         cmdline_fixed_string_t cmd_keyword;
19095         cmdline_fixed_string_t cmd_desc;
19096         cmdline_fixed_string_t cmd_status;
19097         portid_t cmd_pid;
19098         portid_t cmd_qid;
19099         portid_t cmd_did;
19100 };
19101
19102 static void
19103 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19104                 __attribute__((unused)) struct cmdline *cl,
19105                 __attribute__((unused)) void *data)
19106 {
19107         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19108         int rc;
19109
19110         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19111                 printf("invalid port id %u\n", res->cmd_pid);
19112                 return;
19113         }
19114
19115         if (!strcmp(res->cmd_keyword, "rxq")) {
19116                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19117                                              res->cmd_did);
19118                 if (rc < 0) {
19119                         printf("Invalid queueid = %d\n", res->cmd_qid);
19120                         return;
19121                 }
19122                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19123                         printf("Desc status = AVAILABLE\n");
19124                 else if (rc == RTE_ETH_RX_DESC_DONE)
19125                         printf("Desc status = DONE\n");
19126                 else
19127                         printf("Desc status = UNAVAILABLE\n");
19128         } else if (!strcmp(res->cmd_keyword, "txq")) {
19129                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19130                                              res->cmd_did);
19131                 if (rc < 0) {
19132                         printf("Invalid queueid = %d\n", res->cmd_qid);
19133                         return;
19134                 }
19135                 if (rc == RTE_ETH_TX_DESC_FULL)
19136                         printf("Desc status = FULL\n");
19137                 else if (rc == RTE_ETH_TX_DESC_DONE)
19138                         printf("Desc status = DONE\n");
19139                 else
19140                         printf("Desc status = UNAVAILABLE\n");
19141         }
19142 }
19143
19144 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19145         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19146                         cmd_show, "show");
19147 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19148         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19149                         cmd_port, "port");
19150 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19151         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19152                         cmd_pid, UINT16);
19153 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19154         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19155                         cmd_keyword, "rxq#txq");
19156 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19157         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19158                         cmd_qid, UINT16);
19159 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19160         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19161                         cmd_desc, "desc");
19162 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19163         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19164                         cmd_did, UINT16);
19165 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19166         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19167                         cmd_status, "status");
19168 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19169         .f = cmd_show_rx_tx_desc_status_parsed,
19170         .data = NULL,
19171         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19172                 "status",
19173         .tokens = {
19174                 (void *)&cmd_show_rx_tx_desc_status_show,
19175                 (void *)&cmd_show_rx_tx_desc_status_port,
19176                 (void *)&cmd_show_rx_tx_desc_status_pid,
19177                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19178                 (void *)&cmd_show_rx_tx_desc_status_qid,
19179                 (void *)&cmd_show_rx_tx_desc_status_desc,
19180                 (void *)&cmd_show_rx_tx_desc_status_did,
19181                 (void *)&cmd_show_rx_tx_desc_status_status,
19182                 NULL,
19183         },
19184 };
19185
19186 /* Common result structure for set port ptypes */
19187 struct cmd_set_port_ptypes_result {
19188         cmdline_fixed_string_t set;
19189         cmdline_fixed_string_t port;
19190         portid_t port_id;
19191         cmdline_fixed_string_t ptype_mask;
19192         uint32_t mask;
19193 };
19194
19195 /* Common CLI fields for set port ptypes */
19196 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19197         TOKEN_STRING_INITIALIZER
19198                 (struct cmd_set_port_ptypes_result,
19199                  set, "set");
19200 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19201         TOKEN_STRING_INITIALIZER
19202                 (struct cmd_set_port_ptypes_result,
19203                  port, "port");
19204 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19205         TOKEN_NUM_INITIALIZER
19206                 (struct cmd_set_port_ptypes_result,
19207                  port_id, UINT16);
19208 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19209         TOKEN_STRING_INITIALIZER
19210                 (struct cmd_set_port_ptypes_result,
19211                  ptype_mask, "ptype_mask");
19212 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19213         TOKEN_NUM_INITIALIZER
19214                 (struct cmd_set_port_ptypes_result,
19215                  mask, UINT32);
19216
19217 static void
19218 cmd_set_port_ptypes_parsed(
19219         void *parsed_result,
19220         __attribute__((unused)) struct cmdline *cl,
19221         __attribute__((unused)) void *data)
19222 {
19223         struct cmd_set_port_ptypes_result *res = parsed_result;
19224 #define PTYPE_NAMESIZE        256
19225         char ptype_name[PTYPE_NAMESIZE];
19226         uint16_t port_id = res->port_id;
19227         uint32_t ptype_mask = res->mask;
19228         int ret, i;
19229
19230         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19231                                                NULL, 0);
19232         if (ret <= 0) {
19233                 printf("Port %d doesn't support any ptypes.\n", port_id);
19234                 return;
19235         }
19236
19237         uint32_t ptypes[ret];
19238
19239         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19240         if (ret < 0) {
19241                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19242                 return;
19243         }
19244
19245         printf("Successfully set following ptypes for Port %d\n", port_id);
19246         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19247                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19248                 printf("%s\n", ptype_name);
19249         }
19250
19251         clear_ptypes = false;
19252 }
19253
19254 cmdline_parse_inst_t cmd_set_port_ptypes = {
19255         .f = cmd_set_port_ptypes_parsed,
19256         .data = NULL,
19257         .help_str = "set port <port_id> ptype_mask <mask>",
19258         .tokens = {
19259                 (void *)&cmd_set_port_ptypes_set,
19260                 (void *)&cmd_set_port_ptypes_port,
19261                 (void *)&cmd_set_port_ptypes_port_id,
19262                 (void *)&cmd_set_port_ptypes_mask_str,
19263                 (void *)&cmd_set_port_ptypes_mask_u32,
19264                 NULL,
19265         },
19266 };
19267
19268 /* *** display mac addresses added to a port *** */
19269 struct cmd_showport_macs_result {
19270         cmdline_fixed_string_t cmd_show;
19271         cmdline_fixed_string_t cmd_port;
19272         cmdline_fixed_string_t cmd_keyword;
19273         portid_t cmd_pid;
19274 };
19275
19276 static void
19277 cmd_showport_macs_parsed(void *parsed_result,
19278                 __attribute__((unused)) struct cmdline *cl,
19279                 __attribute__((unused)) void *data)
19280 {
19281         struct cmd_showport_macs_result *res = parsed_result;
19282
19283         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19284                 return;
19285
19286         if (!strcmp(res->cmd_keyword, "macs"))
19287                 show_macs(res->cmd_pid);
19288         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19289                 show_mcast_macs(res->cmd_pid);
19290 }
19291
19292 cmdline_parse_token_string_t cmd_showport_macs_show =
19293         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19294                         cmd_show, "show");
19295 cmdline_parse_token_string_t cmd_showport_macs_port =
19296         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19297                         cmd_port, "port");
19298 cmdline_parse_token_num_t cmd_showport_macs_pid =
19299         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19300                         cmd_pid, UINT16);
19301 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19302         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19303                         cmd_keyword, "macs#mcast_macs");
19304
19305 cmdline_parse_inst_t cmd_showport_macs = {
19306         .f = cmd_showport_macs_parsed,
19307         .data = NULL,
19308         .help_str = "show port <port_id> macs|mcast_macs",
19309         .tokens = {
19310                 (void *)&cmd_showport_macs_show,
19311                 (void *)&cmd_showport_macs_port,
19312                 (void *)&cmd_showport_macs_pid,
19313                 (void *)&cmd_showport_macs_keyword,
19314                 NULL,
19315         },
19316 };
19317
19318 /* ******************************************************************************** */
19319
19320 /* list of instructions */
19321 cmdline_parse_ctx_t main_ctx[] = {
19322         (cmdline_parse_inst_t *)&cmd_help_brief,
19323         (cmdline_parse_inst_t *)&cmd_help_long,
19324         (cmdline_parse_inst_t *)&cmd_quit,
19325         (cmdline_parse_inst_t *)&cmd_load_from_file,
19326         (cmdline_parse_inst_t *)&cmd_showport,
19327         (cmdline_parse_inst_t *)&cmd_showqueue,
19328         (cmdline_parse_inst_t *)&cmd_showportall,
19329         (cmdline_parse_inst_t *)&cmd_showdevice,
19330         (cmdline_parse_inst_t *)&cmd_showcfg,
19331         (cmdline_parse_inst_t *)&cmd_showfwdall,
19332         (cmdline_parse_inst_t *)&cmd_start,
19333         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19334         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19335         (cmdline_parse_inst_t *)&cmd_set_link_up,
19336         (cmdline_parse_inst_t *)&cmd_set_link_down,
19337         (cmdline_parse_inst_t *)&cmd_reset,
19338         (cmdline_parse_inst_t *)&cmd_set_numbers,
19339         (cmdline_parse_inst_t *)&cmd_set_log,
19340         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19341         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19342         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19343         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19344         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19345         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19346         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19347         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19348         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19349         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19350         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19351         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19352         (cmdline_parse_inst_t *)&cmd_set_link_check,
19353         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19354         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19355         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19356         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19357 #ifdef RTE_LIBRTE_PMD_BOND
19358         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19359         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19360         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19361         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19362         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19363         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19364         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19365         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19366         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19367         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19368         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19369 #endif
19370         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19371         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19372         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19373         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19374         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19375         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19376         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19377         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19378         (cmdline_parse_inst_t *)&cmd_csum_set,
19379         (cmdline_parse_inst_t *)&cmd_csum_show,
19380         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19381         (cmdline_parse_inst_t *)&cmd_tso_set,
19382         (cmdline_parse_inst_t *)&cmd_tso_show,
19383         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19384         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19385         (cmdline_parse_inst_t *)&cmd_gro_enable,
19386         (cmdline_parse_inst_t *)&cmd_gro_flush,
19387         (cmdline_parse_inst_t *)&cmd_gro_show,
19388         (cmdline_parse_inst_t *)&cmd_gso_enable,
19389         (cmdline_parse_inst_t *)&cmd_gso_size,
19390         (cmdline_parse_inst_t *)&cmd_gso_show,
19391         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19392         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19393         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19394         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19395         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19396         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19397         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19398         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19399         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19400         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19401         (cmdline_parse_inst_t *)&cmd_config_dcb,
19402         (cmdline_parse_inst_t *)&cmd_read_reg,
19403         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19404         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19405         (cmdline_parse_inst_t *)&cmd_write_reg,
19406         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19407         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19408         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19409         (cmdline_parse_inst_t *)&cmd_stop,
19410         (cmdline_parse_inst_t *)&cmd_mac_addr,
19411         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19412         (cmdline_parse_inst_t *)&cmd_set_qmap,
19413         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19414         (cmdline_parse_inst_t *)&cmd_operate_port,
19415         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19416         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19417         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19418         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19419         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19420         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19421         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19422         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19423         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19424         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19425         (cmdline_parse_inst_t *)&cmd_config_mtu,
19426         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19427         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19428         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19429         (cmdline_parse_inst_t *)&cmd_config_rss,
19430         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19431         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19432         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19433         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19434         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19435         (cmdline_parse_inst_t *)&cmd_showport_reta,
19436         (cmdline_parse_inst_t *)&cmd_showport_macs,
19437         (cmdline_parse_inst_t *)&cmd_config_burst,
19438         (cmdline_parse_inst_t *)&cmd_config_thresh,
19439         (cmdline_parse_inst_t *)&cmd_config_threshold,
19440         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19441         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19442         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19443         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19444         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19445         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19446         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19447         (cmdline_parse_inst_t *)&cmd_global_config,
19448         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19449         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19450         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19451         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19452         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19453         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19454         (cmdline_parse_inst_t *)&cmd_dump,
19455         (cmdline_parse_inst_t *)&cmd_dump_one,
19456         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19457         (cmdline_parse_inst_t *)&cmd_syn_filter,
19458         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19459         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19460         (cmdline_parse_inst_t *)&cmd_flex_filter,
19461         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19462         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19463         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19464         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19465         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19466         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19467         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19468         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19469         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19470         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19471         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19472         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19473         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19474         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19475         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19476         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19477         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19478         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19479         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19480         (cmdline_parse_inst_t *)&cmd_flow,
19481         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19482         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19483         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19484         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19485         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19486         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19487         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19488         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19489         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19490         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19491         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19492         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19493         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19494         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19495         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19496         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19497         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19498         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19499         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19500         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19501         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19502         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19503         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19504         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19505         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19506         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19507         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19508         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19509         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19510         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19511         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19512         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19513         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19514         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19515         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19516         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19517         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19518         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19519         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19520         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19521         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19522         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19523         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19524         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19525         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19526         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19527         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19528         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19529         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19530 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19531         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19532 #endif
19533         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19534         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19535         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19536         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19537         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19538         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19539         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19540         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19541         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19542         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19543         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19544         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19545         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19546         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19547         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19548         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19549         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19550         (cmdline_parse_inst_t *)&cmd_ddp_add,
19551         (cmdline_parse_inst_t *)&cmd_ddp_del,
19552         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19553         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19554         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19555         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19556         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19557         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19558         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19559         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19560         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19561         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19562         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19563         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19564
19565         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19566         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19567         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19568         (cmdline_parse_inst_t *)&cmd_queue_region,
19569         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19570         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19571         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19572         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19573         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19574         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19575         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19576         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19577         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19578         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19579         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19580         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19581         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19582         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19583         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19584         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19585         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19586         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19587         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19588         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19589         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19590         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19591         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19592         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19593         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19594         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19595         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19596         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19597         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19598         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19599         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19600         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19601         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19602         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19603         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19604 #ifdef RTE_LIBRTE_BPF
19605         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19606         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19607 #endif
19608         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19609         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19610         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19611         (cmdline_parse_inst_t *)&cmd_set_raw,
19612         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19613         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19614         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19615         NULL,
19616 };
19617
19618 /* read cmdline commands from file */
19619 void
19620 cmdline_read_from_file(const char *filename)
19621 {
19622         struct cmdline *cl;
19623
19624         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19625         if (cl == NULL) {
19626                 printf("Failed to create file based cmdline context: %s\n",
19627                        filename);
19628                 return;
19629         }
19630
19631         cmdline_interact(cl);
19632         cmdline_quit(cl);
19633
19634         cmdline_free(cl);
19635
19636         printf("Read CLI commands from %s\n", filename);
19637 }
19638
19639 /* prompt function, called from main on MASTER lcore */
19640 void
19641 prompt(void)
19642 {
19643         /* initialize non-constant commands */
19644         cmd_set_fwd_mode_init();
19645         cmd_set_fwd_retry_mode_init();
19646
19647         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19648         if (testpmd_cl == NULL)
19649                 return;
19650         cmdline_interact(testpmd_cl);
19651         cmdline_stdin_exit(testpmd_cl);
19652 }
19653
19654 void
19655 prompt_exit(void)
19656 {
19657         if (testpmd_cl != NULL)
19658                 cmdline_quit(testpmd_cl);
19659 }
19660
19661 static void
19662 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19663 {
19664         if (id == (portid_t)RTE_PORT_ALL) {
19665                 portid_t pid;
19666
19667                 RTE_ETH_FOREACH_DEV(pid) {
19668                         /* check if need_reconfig has been set to 1 */
19669                         if (ports[pid].need_reconfig == 0)
19670                                 ports[pid].need_reconfig = dev;
19671                         /* check if need_reconfig_queues has been set to 1 */
19672                         if (ports[pid].need_reconfig_queues == 0)
19673                                 ports[pid].need_reconfig_queues = queue;
19674                 }
19675         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19676                 /* check if need_reconfig has been set to 1 */
19677                 if (ports[id].need_reconfig == 0)
19678                         ports[id].need_reconfig = dev;
19679                 /* check if need_reconfig_queues has been set to 1 */
19680                 if (ports[id].need_reconfig_queues == 0)
19681                         ports[id].need_reconfig_queues = queue;
19682         }
19683 }