app/testpmd: support dumping socket memory
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management 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                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port X rss reta (size) (mask0,mask1,...)\n"
170                         "    Display the rss redirection table entry indicated"
171                         " by masks on port X. size is used to indicate the"
172                         " hardware supported reta size\n\n"
173
174                         "show port (port_id) rss-hash [key]\n"
175                         "    Display the RSS hash functions and RSS hash key of port\n\n"
176
177                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178                         "    Clear information for port_id, or all.\n\n"
179
180                         "show (rxq|txq) info (port_id) (queue_id)\n"
181                         "    Display information for configured RX/TX queue.\n\n"
182
183                         "show config (rxtx|cores|fwd|txpkts)\n"
184                         "    Display the given configuration.\n\n"
185
186                         "read rxd (port_id) (queue_id) (rxd_id)\n"
187                         "    Display an RX descriptor of a port RX queue.\n\n"
188
189                         "read txd (port_id) (queue_id) (txd_id)\n"
190                         "    Display a TX descriptor of a port TX queue.\n\n"
191
192                         "ddp get list (port_id)\n"
193                         "    Get ddp profile info list\n\n"
194
195                         "ddp get info (profile_path)\n"
196                         "    Get ddp profile information.\n\n"
197
198                         "show vf stats (port_id) (vf_id)\n"
199                         "    Display a VF's statistics.\n\n"
200
201                         "clear vf stats (port_id) (vf_id)\n"
202                         "    Reset a VF's statistics.\n\n"
203
204                         "show port (port_id) pctype mapping\n"
205                         "    Get flow ptype to pctype mapping on a port\n\n"
206
207                         "show port meter stats (port_id) (meter_id) (clear)\n"
208                         "    Get meter stats on a port\n\n"
209
210                         "show fwd stats all\n"
211                         "    Display statistics for all fwd engines.\n\n"
212
213                         "clear fwd stats all\n"
214                         "    Clear statistics for all fwd engines.\n\n"
215
216                         "show port (port_id) rx_offload capabilities\n"
217                         "    List all per queue and per port Rx offloading"
218                         " capabilities of a port\n\n"
219
220                         "show port (port_id) rx_offload configuration\n"
221                         "    List port level and all queue level"
222                         " Rx offloading configuration\n\n"
223
224                         "show port (port_id) tx_offload capabilities\n"
225                         "    List all per queue and per port"
226                         " Tx offloading capabilities of a port\n\n"
227
228                         "show port (port_id) tx_offload configuration\n"
229                         "    List port level and all queue level"
230                         " Tx offloading configuration\n\n"
231
232                         "show port (port_id) tx_metadata\n"
233                         "    Show Tx metadata value set"
234                         " for a specific port\n\n"
235
236                         "show port (port_id) ptypes\n"
237                         "    Show port supported ptypes"
238                         " for a specific port\n\n"
239
240                         "show device info (<identifier>|all)"
241                         "       Show general information about devices probed.\n\n"
242
243                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244                         "       Show status of rx|tx descriptor.\n\n"
245
246                         "show port (port_id) macs|mcast_macs"
247                         "       Display list of mac addresses added to port.\n\n"
248                 );
249         }
250
251         if (show_all || !strcmp(res->section, "config")) {
252                 cmdline_printf(
253                         cl,
254                         "\n"
255                         "Configuration:\n"
256                         "--------------\n"
257                         "Configuration changes only become active when"
258                         " forwarding is started/restarted.\n\n"
259
260                         "set default\n"
261                         "    Reset forwarding to the default configuration.\n\n"
262
263                         "set verbose (level)\n"
264                         "    Set the debug verbosity level X.\n\n"
265
266                         "set log global|(type) (level)\n"
267                         "    Set the log level.\n\n"
268
269                         "set nbport (num)\n"
270                         "    Set number of ports.\n\n"
271
272                         "set nbcore (num)\n"
273                         "    Set number of cores.\n\n"
274
275                         "set coremask (mask)\n"
276                         "    Set the forwarding cores hexadecimal mask.\n\n"
277
278                         "set portmask (mask)\n"
279                         "    Set the forwarding ports hexadecimal mask.\n\n"
280
281                         "set burst (num)\n"
282                         "    Set number of packets per burst.\n\n"
283
284                         "set burst tx delay (microseconds) retry (num)\n"
285                         "    Set the transmit delay time and number of retries,"
286                         " effective when retry is enabled.\n\n"
287
288                         "set txpkts (x[,y]*)\n"
289                         "    Set the length of each segment of TXONLY"
290                         " and optionally CSUM packets.\n\n"
291
292                         "set txsplit (off|on|rand)\n"
293                         "    Set the split policy for the TX packets."
294                         " Right now only applicable for CSUM and TXONLY"
295                         " modes\n\n"
296
297                         "set corelist (x[,y]*)\n"
298                         "    Set the list of forwarding cores.\n\n"
299
300                         "set portlist (x[,y]*)\n"
301                         "    Set the list of forwarding ports.\n\n"
302
303                         "set port setup on (iterator|event)\n"
304                         "    Select how attached port is retrieved for setup.\n\n"
305
306                         "set tx loopback (port_id) (on|off)\n"
307                         "    Enable or disable tx loopback.\n\n"
308
309                         "set all queues drop (port_id) (on|off)\n"
310                         "    Set drop enable bit for all queues.\n\n"
311
312                         "set vf split drop (port_id) (vf_id) (on|off)\n"
313                         "    Set split drop enable bit for a VF from the PF.\n\n"
314
315                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316                         "    Set MAC antispoof for a VF from the PF.\n\n"
317
318                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319                         "    Enable MACsec offload.\n\n"
320
321                         "set macsec offload (port_id) off\n"
322                         "    Disable MACsec offload.\n\n"
323
324                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325                         "    Configure MACsec secure connection (SC).\n\n"
326
327                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328                         "    Configure MACsec secure association (SA).\n\n"
329
330                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
331                         "    Set VF broadcast for a VF from the PF.\n\n"
332
333                         "vlan set stripq (on|off) (port_id,queue_id)\n"
334                         "    Set the VLAN strip for a queue on a port.\n\n"
335
336                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338
339                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340                         "    Set VLAN insert for a VF from the PF.\n\n"
341
342                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343                         "    Set VLAN antispoof for a VF from the PF.\n\n"
344
345                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
346                         "    Set VLAN tag for a VF from the PF.\n\n"
347
348                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349                         "    Set a VF's max bandwidth(Mbps).\n\n"
350
351                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353
354                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356
357                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
358                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
359
360                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362
363                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
365
366                         "vlan set (inner|outer) tpid (value) (port_id)\n"
367                         "    Set the VLAN TPID for Packet Filtering on"
368                         " a port\n\n"
369
370                         "rx_vlan add (vlan_id|all) (port_id)\n"
371                         "    Add a vlan_id, or all identifiers, to the set"
372                         " of VLAN identifiers filtered by port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id|all) (port_id)\n"
375                         "    Remove a vlan_id, or all identifiers, from the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379                         "    Add a vlan_id, to the set of VLAN identifiers"
380                         "filtered for VF(s) from port_id.\n\n"
381
382                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Remove a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   add a tunnel filter of a port.\n\n"
390
391                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394                         "   remove a tunnel filter of a port.\n\n"
395
396                         "rx_vxlan_port add (udp_port) (port_id)\n"
397                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
398
399                         "rx_vxlan_port rm (udp_port) (port_id)\n"
400                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
401
402                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
404                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405
406                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
407                         "    Set port based TX VLAN insertion.\n\n"
408
409                         "tx_vlan reset (port_id)\n"
410                         "    Disable hardware insertion of a VLAN header in"
411                         " packets sent on a port.\n\n"
412
413                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414                         "    Select hardware or software calculation of the"
415                         " checksum when transmitting a packet using the"
416                         " csum forward engine.\n"
417                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
418                         "    outer-ip concerns the outer IP layer in"
419                         "    outer-udp concerns the outer UDP layer in"
420                         " case the packet is recognized as a tunnel packet by"
421                         " the forward engine (vxlan, gre and ipip are supported)\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "csum parse-tunnel (on|off) (tx_port_id)\n"
425                         "    If disabled, treat tunnel packets as non-tunneled"
426                         " packets (treat inner headers as payload). The port\n"
427                         "    argument is the port used for TX in csum forward"
428                         " engine.\n\n"
429
430                         "csum show (port_id)\n"
431                         "    Display tx checksum offload configuration\n\n"
432
433                         "tso set (segsize) (portid)\n"
434                         "    Enable TCP Segmentation Offload in csum forward"
435                         " engine.\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "tso show (portid)"
439                         "    Display the status of TCP Segmentation Offload.\n\n"
440
441                         "set port (port_id) gro on|off\n"
442                         "    Enable or disable Generic Receive Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "show port (port_id) gro\n"
446                         "    Display GRO configuration.\n\n"
447
448                         "set gro flush (cycles)\n"
449                         "    Set the cycle to flush GROed packets from"
450                         " reassembly tables.\n\n"
451
452                         "set port (port_id) gso (on|off)"
453                         "    Enable or disable Generic Segmentation Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "set gso segsz (length)\n"
457                         "    Set max packet length for output GSO segments,"
458                         " including packet header and payload.\n\n"
459
460                         "show port (port_id) gso\n"
461                         "    Show GSO configuration.\n\n"
462
463                         "set fwd (%s)\n"
464                         "    Set packet forwarding mode.\n\n"
465
466                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467                         "    Add a MAC address on port_id.\n\n"
468
469                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470                         "    Remove a MAC address from port_id.\n\n"
471
472                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473                         "    Set the default MAC address for port_id.\n\n"
474
475                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476                         "    Add a MAC address for a VF on the port.\n\n"
477
478                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479                         "    Set the MAC address for a VF from the PF.\n\n"
480
481                         "set eth-peer (port_id) (peer_addr)\n"
482                         "    set the peer address for certain port.\n\n"
483
484                         "set port (port_id) uta (mac_address|all) (on|off)\n"
485                         "    Add/Remove a or all unicast hash filter(s)"
486                         "from port X.\n\n"
487
488                         "set promisc (port_id|all) (on|off)\n"
489                         "    Set the promiscuous mode on port_id, or all.\n\n"
490
491                         "set allmulti (port_id|all) (on|off)\n"
492                         "    Set the allmulti mode on port_id, or all.\n\n"
493
494                         "set vf promisc (port_id) (vf_id) (on|off)\n"
495                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
496
497                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
498                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
499
500                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502                         " (on|off) autoneg (on|off) (port_id)\n"
503                         "set flow_ctrl rx (on|off) (portid)\n"
504                         "set flow_ctrl tx (on|off) (portid)\n"
505                         "set flow_ctrl high_water (high_water) (portid)\n"
506                         "set flow_ctrl low_water (low_water) (portid)\n"
507                         "set flow_ctrl pause_time (pause_time) (portid)\n"
508                         "set flow_ctrl send_xon (send_xon) (portid)\n"
509                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510                         "set flow_ctrl autoneg (on|off) (port_id)\n"
511                         "    Set the link flow control parameter on a port.\n\n"
512
513                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (priority) (port_id)\n"
515                         "    Set the priority flow control parameter on a"
516                         " port.\n\n"
517
518                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
520                         " queue on port.\n"
521                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522                         " on port 0 to mapping 5.\n\n"
523
524                         "set xstats-hide-zero on|off\n"
525                         "    Set the option to hide the zero values"
526                         " for xstats display.\n"
527
528                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
529                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
530
531                         "set port (port_id) vf (vf_id) (mac_addr)"
532                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533                         "   Add/Remove unicast or multicast MAC addr filter"
534                         " for a VF.\n\n"
535
536                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537                         "|MPE) (on|off)\n"
538                         "    AUPE:accepts untagged VLAN;"
539                         "ROPE:accept unicast hash\n\n"
540                         "    BAM:accepts broadcast packets;"
541                         "MPE:accepts all multicast packets\n\n"
542                         "    Enable/Disable a VF receive mode of a port\n\n"
543
544                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
545                         "    Set rate limit for a queue of a port\n\n"
546
547                         "set port (port_id) vf (vf_id) rate (rate_num) "
548                         "queue_mask (queue_mask_value)\n"
549                         "    Set rate limit for queues in VF of a port\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554                         "   Set pool or vlan type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
557                         " to pool 0.\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (uplink-mirror|downlink-mirror) dst-pool"
561                         " (pool_id) (on|off)\n"
562                         "   Set uplink or downlink type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564                         " 0 on' enable mirror income traffic to pool 0.\n\n"
565
566                         "reset port (port_id) mirror-rule (rule_id)\n"
567                         "   Reset a mirror rule.\n\n"
568
569                         "set flush_rx (on|off)\n"
570                         "   Flush (default) or don't flush RX streams before"
571                         " forwarding. Mainly used with PCAP drivers.\n\n"
572
573                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the bypass mode for the lowest port on bypass enabled"
575                         " NIC.\n\n"
576
577                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
578                         "mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the event required to initiate specified bypass mode for"
580                         " the lowest port on a bypass enabled NIC where:\n"
581                         "       timeout   = enable bypass after watchdog timeout.\n"
582                         "       os_on     = enable bypass when OS/board is powered on.\n"
583                         "       os_off    = enable bypass when OS/board is powered off.\n"
584                         "       power_on  = enable bypass when power supply is turned on.\n"
585                         "       power_off = enable bypass when power supply is turned off."
586                         "\n\n"
587
588                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589                         "   Set the bypass watchdog timeout to 'n' seconds"
590                         " where 0 = instant.\n\n"
591
592                         "show bypass config (port_id)\n"
593                         "   Show the bypass configuration for a bypass enabled NIC"
594                         " using the lowest port on the NIC.\n\n"
595
596 #ifdef RTE_LIBRTE_PMD_BOND
597                         "create bonded device (mode) (socket)\n"
598                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
599
600                         "add bonding slave (slave_id) (port_id)\n"
601                         "       Add a slave device to a bonded device.\n\n"
602
603                         "remove bonding slave (slave_id) (port_id)\n"
604                         "       Remove a slave device from a bonded device.\n\n"
605
606                         "set bonding mode (value) (port_id)\n"
607                         "       Set the bonding mode on a bonded device.\n\n"
608
609                         "set bonding primary (slave_id) (port_id)\n"
610                         "       Set the primary slave for a bonded device.\n\n"
611
612                         "show bonding config (port_id)\n"
613                         "       Show the bonding config for port_id.\n\n"
614
615                         "set bonding mac_addr (port_id) (address)\n"
616                         "       Set the MAC address of a bonded device.\n\n"
617
618                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
620
621                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
623
624                         "set bonding mon_period (port_id) (value)\n"
625                         "       Set the bonding link status monitoring polling period in ms.\n\n"
626
627                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
629
630 #endif
631                         "set link-up port (port_id)\n"
632                         "       Set link up for a port.\n\n"
633
634                         "set link-down port (port_id)\n"
635                         "       Set link down for a port.\n\n"
636
637                         "E-tag set insertion on port-tag-id (value)"
638                         " port (port_id) vf (vf_id)\n"
639                         "    Enable E-tag insertion for a VF on a port\n\n"
640
641                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
642                         "    Disable E-tag insertion for a VF on a port\n\n"
643
644                         "E-tag set stripping (on|off) port (port_id)\n"
645                         "    Enable/disable E-tag stripping on a port\n\n"
646
647                         "E-tag set forwarding (on|off) port (port_id)\n"
648                         "    Enable/disable E-tag based forwarding"
649                         " on a port\n\n"
650
651                         "E-tag set filter add e-tag-id (value) dst-pool"
652                         " (pool_id) port (port_id)\n"
653                         "    Add an E-tag forwarding filter on a port\n\n"
654
655                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
656                         "    Delete an E-tag forwarding filter on a port\n\n"
657
658                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
659                         "    Load a profile package on a port\n\n"
660
661                         "ddp del (port_id) (backup_profile_path)\n"
662                         "    Delete a profile package from a port\n\n"
663
664                         "ptype mapping get (port_id) (valid_only)\n"
665                         "    Get ptype mapping on a port\n\n"
666
667                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668                         "    Replace target with the pkt_type in ptype mapping\n\n"
669
670                         "ptype mapping reset (port_id)\n"
671                         "    Reset ptype mapping on a port\n\n"
672
673                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674                         "    Update a ptype mapping item on a port\n\n"
675
676                         "set port (port_id) ptype_mask (ptype_mask)\n"
677                         "    set packet types classification for a specific port\n\n"
678
679                         "set port (port_id) queue-region region_id (value) "
680                         "queue_start_index (value) queue_num (value)\n"
681                         "    Set a queue region on a port\n\n"
682
683                         "set port (port_id) queue-region region_id (value) "
684                         "flowtype (value)\n"
685                         "    Set a flowtype region index on a port\n\n"
686
687                         "set port (port_id) queue-region UP (value) region_id (value)\n"
688                         "    Set the mapping of User Priority to "
689                         "queue region on a port\n\n"
690
691                         "set port (port_id) queue-region flush (on|off)\n"
692                         "    flush all queue region related configuration\n\n"
693
694                         "show port meter cap (port_id)\n"
695                         "    Show port meter capability information\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712                         "(dscp_tbl_entry63)]\n"
713                         "    meter create\n\n"
714
715                         "enable port meter (port_id) (mtr_id)\n"
716                         "    meter enable\n\n"
717
718                         "disable port meter (port_id) (mtr_id)\n"
719                         "    meter disable\n\n"
720
721                         "del port meter (port_id) (mtr_id)\n"
722                         "    meter delete\n\n"
723
724                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
725                         "    meter update meter profile\n\n"
726
727                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729                         "    update meter dscp table entries\n\n"
730
731                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732                         "(action0) [(action1) (action2)]\n"
733                         "    meter update policer action\n\n"
734
735                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736                         "    meter update stats\n\n"
737
738                         "show port (port_id) queue-region\n"
739                         "    show all queue region related configuration info\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|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                                 __rte_unused struct cmdline *cl,
1308                                 __rte_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                         __rte_unused struct cmdline *cl,
1354                                 __rte_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                                 __rte_unused struct cmdline *cl,
1403                                 __rte_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_multi_string_t identifier;
1450 };
1451
1452 static void cmd_operate_attach_port_parsed(void *parsed_result,
1453                                 __rte_unused struct cmdline *cl,
1454                                 __rte_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, TOKEN_STRING_MULTI);
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                                 __rte_unused struct cmdline *cl,
1496                                 __rte_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                                 __rte_unused struct cmdline *cl,
1539                                 __rte_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                         __rte_unused struct cmdline *cl,
1636                         __rte_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                                 __rte_unused struct cmdline *cl,
1708                                 __rte_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                         __rte_unused struct cmdline *cl,
1782                         __rte_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                                 __rte_unused struct cmdline *cl,
1838                                 __rte_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                         __rte_unused struct cmdline *cl,
1898                         __rte_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                                 __rte_unused struct cmdline *cl,
1988                                 __rte_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                                 __rte_unused struct cmdline *cl,
2070                                 __rte_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                       __rte_unused struct cmdline *cl,
2142                       __rte_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                                 __rte_unused struct cmdline *cl,
2193                                 __rte_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                         __rte_unused struct cmdline *cl,
2261                         __rte_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                                __rte_unused struct cmdline *cl,
2409                                __rte_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                                  __rte_unused struct cmdline *cl,
2508                                  __rte_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                         __rte_unused struct cmdline *cl,
2602                         __rte_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                         __rte_unused struct cmdline *cl,
2697                         __rte_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         __rte_unused struct cmdline *cl,
2795         __rte_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                         __rte_unused struct cmdline *cl,
2951                         __rte_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                          __rte_unused struct cmdline *cl,
3073                          __rte_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                                 __rte_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                         __rte_unused struct cmdline *cl,
3208                         __rte_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                         __rte_unused struct cmdline *cl,
3306                         __rte_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                         __rte_unused struct cmdline *cl,
3397                         __rte_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                         __rte_unused struct cmdline *cl,
3466                         __rte_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(__rte_unused void *parsed_result,
3524                             __rte_unused struct cmdline *cl,
3525                             __rte_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                                 __rte_unused struct cmdline *cl,
3617                                 __rte_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                                 __rte_unused struct cmdline *cl,
3685                                 __rte_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                            __rte_unused struct cmdline *cl,
3733                            __rte_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                    __rte_unused struct cmdline *cl,
3780                    __rte_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                       __rte_unused struct cmdline *cl,
3828                       __rte_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                       __rte_unused struct cmdline *cl,
3874                       __rte_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                               __rte_unused struct cmdline *cl,
3915                               __rte_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                           __rte_unused struct cmdline *cl,
3966                           __rte_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                           __rte_unused struct cmdline *cl,
4070                           __rte_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                           __rte_unused struct cmdline *cl,
4132                           __rte_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                        __rte_unused struct cmdline *cl,
4181                        __rte_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                             __rte_unused struct cmdline *cl,
4235                             __rte_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                             __rte_unused struct cmdline *cl,
4294                             __rte_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                          __rte_unused struct cmdline *cl,
4348                          __rte_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                        __rte_unused struct cmdline *cl,
4470                        __rte_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                        __rte_unused struct cmdline *cl,
4621                        __rte_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                        __rte_unused struct cmdline *cl,
4674                        __rte_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                           __rte_unused struct cmdline *cl,
4813                           __rte_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                 __rte_unused struct cmdline *cl,
4934                 __rte_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                 __rte_unused struct cmdline *cl,
4984                 __rte_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                 __rte_unused struct cmdline *cl,
5030                 __rte_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                 __rte_unused struct cmdline *cl,
5078                 __rte_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                        __rte_unused struct cmdline *cl,
5128                        __rte_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                        __rte_unused struct cmdline *cl,
5186                        __rte_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                 __rte_unused struct cmdline *cl,
5243                 __rte_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                 __rte_unused struct cmdline *cl,
5282                 __rte_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                 __rte_unused struct cmdline *cl,
5324                 __rte_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                 __rte_unused struct cmdline *cl,
5392                 __rte_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                 __rte_unused struct cmdline *cl,
5499                 __rte_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                 __rte_unused struct cmdline *cl,
5561                 __rte_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                 __rte_unused  struct cmdline *cl,
5661                 __rte_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                 __rte_unused  struct cmdline *cl,
5714                 __rte_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                 __rte_unused  struct cmdline *cl,
5792                 __rte_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                 __rte_unused  struct cmdline *cl,
5858                 __rte_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                 __rte_unused  struct cmdline *cl,
6002                 __rte_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                 __rte_unused  struct cmdline *cl,
6059                 __rte_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                 __rte_unused  struct cmdline *cl,
6117                 __rte_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                 __rte_unused  struct cmdline *cl,
6177                 __rte_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                 __rte_unused  struct cmdline *cl,
6257                 __rte_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                 __rte_unused  struct cmdline *cl,
6312                 __rte_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                 __rte_unused struct cmdline *cl,
6368                 __rte_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                                     __rte_unused struct cmdline *cl,
6430                                     __rte_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                             __rte_unused struct cmdline *cl,
6490                             __rte_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                                         __rte_unused struct cmdline *cl,
6561                                         __rte_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                                         __rte_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                                         __rte_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                               __rte_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                        __rte_unused struct cmdline *cl,
7077                        __rte_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(__rte_unused void *parsed_result,
7171                              struct cmdline *cl,
7172                              __rte_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(__rte_unused void *parsed_result,
7204                              __rte_unused struct cmdline *cl,
7205                              __rte_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(__rte_unused void *parsed_result,
7228                           __rte_unused struct cmdline *cl,
7229                           __rte_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                           __rte_unused struct cmdline *cl,
7263                           __rte_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(__rte_unused void *parsed_result,
7312                              __rte_unused struct cmdline *cl,
7313                              __rte_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                                 __rte_unused void *parsed_result,
7352                                 __rte_unused struct cmdline *cl,
7353                                 __rte_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                                __rte_unused struct cmdline *cl,
7381                                __rte_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                                 __rte_unused struct cmdline *cl,
7424                                 __rte_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                                 __rte_unused struct cmdline *cl,
7498                                 __rte_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                                 __rte_unused struct cmdline *cl,
7562                                 __rte_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         __rte_unused struct cmdline *cl,
7609         __rte_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                     __rte_unused struct cmdline *cl,
7698                     __rte_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                               __rte_unused struct cmdline *cl,
7739                               __rte_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                         __rte_unused struct cmdline *cl,
7793                         __rte_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                      __rte_unused struct cmdline *cl,
7837                      __rte_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                                __rte_unused struct cmdline *cl,
7882                                __rte_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                          __rte_unused struct cmdline *cl,
7942                          __rte_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                         __rte_unused struct cmdline *cl,
7991                         __rte_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(__rte_unused void *parsed_result,
8033                             struct cmdline *cl,
8034                             __rte_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                 __rte_unused struct cmdline *cl,
8062                 __rte_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                         __rte_unused struct cmdline *cl,
8117                         __rte_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                        __rte_unused struct cmdline *cl,
8165                        __rte_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                         __rte_unused struct cmdline *cl,
8218                         __rte_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                        __rte_unused struct cmdline *cl,
8263                        __rte_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                        __rte_unused struct cmdline *cl,
8324                        __rte_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                        __rte_unused struct cmdline *cl,
8388                        __rte_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                        __rte_unused struct cmdline *cl,
8491                        __rte_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                        __rte_unused struct cmdline *cl,
8553                        __rte_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                 __rte_unused struct cmdline *cl,
8644                 __rte_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                           __rte_unused struct cmdline *cl,
8721                           __rte_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                 __rte_unused struct cmdline *cl,
8814                 __rte_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                 __rte_unused struct cmdline *cl,
8883                 __rte_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                           __rte_unused struct cmdline *cl,
8965                           __rte_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                           __rte_unused struct cmdline *cl,
9109                           __rte_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                                __rte_unused struct cmdline *cl,
9171                                __rte_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                          __rte_unused struct cmdline *cl,
9254                          __rte_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                        __rte_unused struct cmdline *cl,
9344                        __rte_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                        __rte_unused struct cmdline *cl,
9455                        __rte_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                        __rte_unused struct cmdline *cl,
9529                        __rte_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
9570 /* Dump the socket memory statistics on console */
9571 static void
9572 dump_socket_mem(FILE *f)
9573 {
9574         struct rte_malloc_socket_stats socket_stats;
9575         unsigned int i;
9576         size_t total = 0;
9577         size_t alloc = 0;
9578         size_t free = 0;
9579         unsigned int n_alloc = 0;
9580         unsigned int n_free = 0;
9581         static size_t last_allocs;
9582         static size_t last_total;
9583
9584
9585         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9586                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9587                     !socket_stats.heap_totalsz_bytes)
9588                         continue;
9589                 total += socket_stats.heap_totalsz_bytes;
9590                 alloc += socket_stats.heap_allocsz_bytes;
9591                 free += socket_stats.heap_freesz_bytes;
9592                 n_alloc += socket_stats.alloc_count;
9593                 n_free += socket_stats.free_count;
9594                 fprintf(f,
9595                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9596                         i,
9597                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9598                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9599                         (double)socket_stats.heap_allocsz_bytes * 100 /
9600                         (double)socket_stats.heap_totalsz_bytes,
9601                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9602                         socket_stats.alloc_count,
9603                         socket_stats.free_count);
9604         }
9605         fprintf(f,
9606                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9607                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9608                 (double)alloc * 100 / (double)total,
9609                 (double)free / (1024 * 1024),
9610                 n_alloc, n_free);
9611         if (last_allocs)
9612                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9613                         ((double)total - (double)last_total) / (1024 * 1024),
9614                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9615         last_allocs = alloc;
9616         last_total = total;
9617 }
9618
9619 static void cmd_dump_parsed(void *parsed_result,
9620                             __rte_unused struct cmdline *cl,
9621                             __rte_unused void *data)
9622 {
9623         struct cmd_dump_result *res = parsed_result;
9624
9625         if (!strcmp(res->dump, "dump_physmem"))
9626                 rte_dump_physmem_layout(stdout);
9627         else if (!strcmp(res->dump, "dump_socket_mem"))
9628                 dump_socket_mem(stdout);
9629         else if (!strcmp(res->dump, "dump_memzone"))
9630                 rte_memzone_dump(stdout);
9631         else if (!strcmp(res->dump, "dump_struct_sizes"))
9632                 dump_struct_sizes();
9633         else if (!strcmp(res->dump, "dump_ring"))
9634                 rte_ring_list_dump(stdout);
9635         else if (!strcmp(res->dump, "dump_mempool"))
9636                 rte_mempool_list_dump(stdout);
9637         else if (!strcmp(res->dump, "dump_devargs"))
9638                 rte_devargs_dump(stdout);
9639         else if (!strcmp(res->dump, "dump_log_types"))
9640                 rte_log_dump(stdout);
9641 }
9642
9643 cmdline_parse_token_string_t cmd_dump_dump =
9644         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9645                 "dump_physmem#"
9646                 "dump_memzone#"
9647                 "dump_socket_mem#"
9648                 "dump_struct_sizes#"
9649                 "dump_ring#"
9650                 "dump_mempool#"
9651                 "dump_devargs#"
9652                 "dump_log_types");
9653
9654 cmdline_parse_inst_t cmd_dump = {
9655         .f = cmd_dump_parsed,  /* function to call */
9656         .data = NULL,      /* 2nd arg of func */
9657         .help_str = "Dump status",
9658         .tokens = {        /* token list, NULL terminated */
9659                 (void *)&cmd_dump_dump,
9660                 NULL,
9661         },
9662 };
9663
9664 /* ******************************************************************************** */
9665
9666 struct cmd_dump_one_result {
9667         cmdline_fixed_string_t dump;
9668         cmdline_fixed_string_t name;
9669 };
9670
9671 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9672                                 __rte_unused void *data)
9673 {
9674         struct cmd_dump_one_result *res = parsed_result;
9675
9676         if (!strcmp(res->dump, "dump_ring")) {
9677                 struct rte_ring *r;
9678                 r = rte_ring_lookup(res->name);
9679                 if (r == NULL) {
9680                         cmdline_printf(cl, "Cannot find ring\n");
9681                         return;
9682                 }
9683                 rte_ring_dump(stdout, r);
9684         } else if (!strcmp(res->dump, "dump_mempool")) {
9685                 struct rte_mempool *mp;
9686                 mp = rte_mempool_lookup(res->name);
9687                 if (mp == NULL) {
9688                         cmdline_printf(cl, "Cannot find mempool\n");
9689                         return;
9690                 }
9691                 rte_mempool_dump(stdout, mp);
9692         }
9693 }
9694
9695 cmdline_parse_token_string_t cmd_dump_one_dump =
9696         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9697                                  "dump_ring#dump_mempool");
9698
9699 cmdline_parse_token_string_t cmd_dump_one_name =
9700         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9701
9702 cmdline_parse_inst_t cmd_dump_one = {
9703         .f = cmd_dump_one_parsed,  /* function to call */
9704         .data = NULL,      /* 2nd arg of func */
9705         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9706         .tokens = {        /* token list, NULL terminated */
9707                 (void *)&cmd_dump_one_dump,
9708                 (void *)&cmd_dump_one_name,
9709                 NULL,
9710         },
9711 };
9712
9713 /* *** Add/Del syn filter *** */
9714 struct cmd_syn_filter_result {
9715         cmdline_fixed_string_t filter;
9716         portid_t port_id;
9717         cmdline_fixed_string_t ops;
9718         cmdline_fixed_string_t priority;
9719         cmdline_fixed_string_t high;
9720         cmdline_fixed_string_t queue;
9721         uint16_t queue_id;
9722 };
9723
9724 static void
9725 cmd_syn_filter_parsed(void *parsed_result,
9726                         __rte_unused struct cmdline *cl,
9727                         __rte_unused void *data)
9728 {
9729         struct cmd_syn_filter_result *res = parsed_result;
9730         struct rte_eth_syn_filter syn_filter;
9731         int ret = 0;
9732
9733         ret = rte_eth_dev_filter_supported(res->port_id,
9734                                         RTE_ETH_FILTER_SYN);
9735         if (ret < 0) {
9736                 printf("syn filter is not supported on port %u.\n",
9737                                 res->port_id);
9738                 return;
9739         }
9740
9741         memset(&syn_filter, 0, sizeof(syn_filter));
9742
9743         if (!strcmp(res->ops, "add")) {
9744                 if (!strcmp(res->high, "high"))
9745                         syn_filter.hig_pri = 1;
9746                 else
9747                         syn_filter.hig_pri = 0;
9748
9749                 syn_filter.queue = res->queue_id;
9750                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9751                                                 RTE_ETH_FILTER_SYN,
9752                                                 RTE_ETH_FILTER_ADD,
9753                                                 &syn_filter);
9754         } else
9755                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9756                                                 RTE_ETH_FILTER_SYN,
9757                                                 RTE_ETH_FILTER_DELETE,
9758                                                 &syn_filter);
9759
9760         if (ret < 0)
9761                 printf("syn filter programming error: (%s)\n",
9762                                 strerror(-ret));
9763 }
9764
9765 cmdline_parse_token_string_t cmd_syn_filter_filter =
9766         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9767         filter, "syn_filter");
9768 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9769         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9770         port_id, UINT16);
9771 cmdline_parse_token_string_t cmd_syn_filter_ops =
9772         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9773         ops, "add#del");
9774 cmdline_parse_token_string_t cmd_syn_filter_priority =
9775         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9776                                 priority, "priority");
9777 cmdline_parse_token_string_t cmd_syn_filter_high =
9778         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9779                                 high, "high#low");
9780 cmdline_parse_token_string_t cmd_syn_filter_queue =
9781         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9782                                 queue, "queue");
9783 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9784         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9785                                 queue_id, UINT16);
9786
9787 cmdline_parse_inst_t cmd_syn_filter = {
9788         .f = cmd_syn_filter_parsed,
9789         .data = NULL,
9790         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9791                 "<queue_id>: Add/Delete syn filter",
9792         .tokens = {
9793                 (void *)&cmd_syn_filter_filter,
9794                 (void *)&cmd_syn_filter_port_id,
9795                 (void *)&cmd_syn_filter_ops,
9796                 (void *)&cmd_syn_filter_priority,
9797                 (void *)&cmd_syn_filter_high,
9798                 (void *)&cmd_syn_filter_queue,
9799                 (void *)&cmd_syn_filter_queue_id,
9800                 NULL,
9801         },
9802 };
9803
9804 /* *** queue region set *** */
9805 struct cmd_queue_region_result {
9806         cmdline_fixed_string_t set;
9807         cmdline_fixed_string_t port;
9808         portid_t port_id;
9809         cmdline_fixed_string_t cmd;
9810         cmdline_fixed_string_t region;
9811         uint8_t  region_id;
9812         cmdline_fixed_string_t queue_start_index;
9813         uint8_t  queue_id;
9814         cmdline_fixed_string_t queue_num;
9815         uint8_t  queue_num_value;
9816 };
9817
9818 static void
9819 cmd_queue_region_parsed(void *parsed_result,
9820                         __rte_unused struct cmdline *cl,
9821                         __rte_unused void *data)
9822 {
9823         struct cmd_queue_region_result *res = parsed_result;
9824         int ret = -ENOTSUP;
9825 #ifdef RTE_LIBRTE_I40E_PMD
9826         struct rte_pmd_i40e_queue_region_conf region_conf;
9827         enum rte_pmd_i40e_queue_region_op op_type;
9828 #endif
9829
9830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9831                 return;
9832
9833 #ifdef RTE_LIBRTE_I40E_PMD
9834         memset(&region_conf, 0, sizeof(region_conf));
9835         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9836         region_conf.region_id = res->region_id;
9837         region_conf.queue_num = res->queue_num_value;
9838         region_conf.queue_start_index = res->queue_id;
9839
9840         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9841                                 op_type, &region_conf);
9842 #endif
9843
9844         switch (ret) {
9845         case 0:
9846                 break;
9847         case -ENOTSUP:
9848                 printf("function not implemented or supported\n");
9849                 break;
9850         default:
9851                 printf("queue region config error: (%s)\n", strerror(-ret));
9852         }
9853 }
9854
9855 cmdline_parse_token_string_t cmd_queue_region_set =
9856 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9857                 set, "set");
9858 cmdline_parse_token_string_t cmd_queue_region_port =
9859         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9860 cmdline_parse_token_num_t cmd_queue_region_port_id =
9861         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9862                                 port_id, UINT16);
9863 cmdline_parse_token_string_t cmd_queue_region_cmd =
9864         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9865                                  cmd, "queue-region");
9866 cmdline_parse_token_string_t cmd_queue_region_id =
9867         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9868                                 region, "region_id");
9869 cmdline_parse_token_num_t cmd_queue_region_index =
9870         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9871                                 region_id, UINT8);
9872 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9873         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9874                                 queue_start_index, "queue_start_index");
9875 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9876         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9877                                 queue_id, UINT8);
9878 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9879         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9880                                 queue_num, "queue_num");
9881 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9882         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9883                                 queue_num_value, UINT8);
9884
9885 cmdline_parse_inst_t cmd_queue_region = {
9886         .f = cmd_queue_region_parsed,
9887         .data = NULL,
9888         .help_str = "set port <port_id> queue-region region_id <value> "
9889                 "queue_start_index <value> queue_num <value>: Set a queue region",
9890         .tokens = {
9891                 (void *)&cmd_queue_region_set,
9892                 (void *)&cmd_queue_region_port,
9893                 (void *)&cmd_queue_region_port_id,
9894                 (void *)&cmd_queue_region_cmd,
9895                 (void *)&cmd_queue_region_id,
9896                 (void *)&cmd_queue_region_index,
9897                 (void *)&cmd_queue_region_queue_start_index,
9898                 (void *)&cmd_queue_region_queue_id,
9899                 (void *)&cmd_queue_region_queue_num,
9900                 (void *)&cmd_queue_region_queue_num_value,
9901                 NULL,
9902         },
9903 };
9904
9905 /* *** queue region and flowtype set *** */
9906 struct cmd_region_flowtype_result {
9907         cmdline_fixed_string_t set;
9908         cmdline_fixed_string_t port;
9909         portid_t port_id;
9910         cmdline_fixed_string_t cmd;
9911         cmdline_fixed_string_t region;
9912         uint8_t  region_id;
9913         cmdline_fixed_string_t flowtype;
9914         uint8_t  flowtype_id;
9915 };
9916
9917 static void
9918 cmd_region_flowtype_parsed(void *parsed_result,
9919                         __rte_unused struct cmdline *cl,
9920                         __rte_unused void *data)
9921 {
9922         struct cmd_region_flowtype_result *res = parsed_result;
9923         int ret = -ENOTSUP;
9924 #ifdef RTE_LIBRTE_I40E_PMD
9925         struct rte_pmd_i40e_queue_region_conf region_conf;
9926         enum rte_pmd_i40e_queue_region_op op_type;
9927 #endif
9928
9929         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9930                 return;
9931
9932 #ifdef RTE_LIBRTE_I40E_PMD
9933         memset(&region_conf, 0, sizeof(region_conf));
9934
9935         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9936         region_conf.region_id = res->region_id;
9937         region_conf.hw_flowtype = res->flowtype_id;
9938
9939         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9940                         op_type, &region_conf);
9941 #endif
9942
9943         switch (ret) {
9944         case 0:
9945                 break;
9946         case -ENOTSUP:
9947                 printf("function not implemented or supported\n");
9948                 break;
9949         default:
9950                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9951         }
9952 }
9953
9954 cmdline_parse_token_string_t cmd_region_flowtype_set =
9955 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9956                                 set, "set");
9957 cmdline_parse_token_string_t cmd_region_flowtype_port =
9958         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9959                                 port, "port");
9960 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9961         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9962                                 port_id, UINT16);
9963 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9964         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9965                                 cmd, "queue-region");
9966 cmdline_parse_token_string_t cmd_region_flowtype_index =
9967         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9968                                 region, "region_id");
9969 cmdline_parse_token_num_t cmd_region_flowtype_id =
9970         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9971                                 region_id, UINT8);
9972 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9973         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9974                                 flowtype, "flowtype");
9975 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9976         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9977                                 flowtype_id, UINT8);
9978 cmdline_parse_inst_t cmd_region_flowtype = {
9979         .f = cmd_region_flowtype_parsed,
9980         .data = NULL,
9981         .help_str = "set port <port_id> queue-region region_id <value> "
9982                 "flowtype <value>: Set a flowtype region index",
9983         .tokens = {
9984                 (void *)&cmd_region_flowtype_set,
9985                 (void *)&cmd_region_flowtype_port,
9986                 (void *)&cmd_region_flowtype_port_index,
9987                 (void *)&cmd_region_flowtype_cmd,
9988                 (void *)&cmd_region_flowtype_index,
9989                 (void *)&cmd_region_flowtype_id,
9990                 (void *)&cmd_region_flowtype_flow_index,
9991                 (void *)&cmd_region_flowtype_flow_id,
9992                 NULL,
9993         },
9994 };
9995
9996 /* *** User Priority (UP) to queue region (region_id) set *** */
9997 struct cmd_user_priority_region_result {
9998         cmdline_fixed_string_t set;
9999         cmdline_fixed_string_t port;
10000         portid_t port_id;
10001         cmdline_fixed_string_t cmd;
10002         cmdline_fixed_string_t user_priority;
10003         uint8_t  user_priority_id;
10004         cmdline_fixed_string_t region;
10005         uint8_t  region_id;
10006 };
10007
10008 static void
10009 cmd_user_priority_region_parsed(void *parsed_result,
10010                         __rte_unused struct cmdline *cl,
10011                         __rte_unused void *data)
10012 {
10013         struct cmd_user_priority_region_result *res = parsed_result;
10014         int ret = -ENOTSUP;
10015 #ifdef RTE_LIBRTE_I40E_PMD
10016         struct rte_pmd_i40e_queue_region_conf region_conf;
10017         enum rte_pmd_i40e_queue_region_op op_type;
10018 #endif
10019
10020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10021                 return;
10022
10023 #ifdef RTE_LIBRTE_I40E_PMD
10024         memset(&region_conf, 0, sizeof(region_conf));
10025         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10026         region_conf.user_priority = res->user_priority_id;
10027         region_conf.region_id = res->region_id;
10028
10029         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10030                                 op_type, &region_conf);
10031 #endif
10032
10033         switch (ret) {
10034         case 0:
10035                 break;
10036         case -ENOTSUP:
10037                 printf("function not implemented or supported\n");
10038                 break;
10039         default:
10040                 printf("user_priority region config error: (%s)\n",
10041                                 strerror(-ret));
10042         }
10043 }
10044
10045 cmdline_parse_token_string_t cmd_user_priority_region_set =
10046         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10047                                 set, "set");
10048 cmdline_parse_token_string_t cmd_user_priority_region_port =
10049         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10050                                 port, "port");
10051 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10052         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10053                                 port_id, UINT16);
10054 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10055         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10056                                 cmd, "queue-region");
10057 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10058         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10059                                 user_priority, "UP");
10060 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10061         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10062                                 user_priority_id, UINT8);
10063 cmdline_parse_token_string_t cmd_user_priority_region_region =
10064         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10065                                 region, "region_id");
10066 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10067         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10068                                 region_id, UINT8);
10069
10070 cmdline_parse_inst_t cmd_user_priority_region = {
10071         .f = cmd_user_priority_region_parsed,
10072         .data = NULL,
10073         .help_str = "set port <port_id> queue-region UP <value> "
10074                 "region_id <value>: Set the mapping of User Priority (UP) "
10075                 "to queue region (region_id) ",
10076         .tokens = {
10077                 (void *)&cmd_user_priority_region_set,
10078                 (void *)&cmd_user_priority_region_port,
10079                 (void *)&cmd_user_priority_region_port_index,
10080                 (void *)&cmd_user_priority_region_cmd,
10081                 (void *)&cmd_user_priority_region_UP,
10082                 (void *)&cmd_user_priority_region_UP_id,
10083                 (void *)&cmd_user_priority_region_region,
10084                 (void *)&cmd_user_priority_region_region_id,
10085                 NULL,
10086         },
10087 };
10088
10089 /* *** flush all queue region related configuration *** */
10090 struct cmd_flush_queue_region_result {
10091         cmdline_fixed_string_t set;
10092         cmdline_fixed_string_t port;
10093         portid_t port_id;
10094         cmdline_fixed_string_t cmd;
10095         cmdline_fixed_string_t flush;
10096         cmdline_fixed_string_t what;
10097 };
10098
10099 static void
10100 cmd_flush_queue_region_parsed(void *parsed_result,
10101                         __rte_unused struct cmdline *cl,
10102                         __rte_unused void *data)
10103 {
10104         struct cmd_flush_queue_region_result *res = parsed_result;
10105         int ret = -ENOTSUP;
10106 #ifdef RTE_LIBRTE_I40E_PMD
10107         struct rte_pmd_i40e_queue_region_conf region_conf;
10108         enum rte_pmd_i40e_queue_region_op op_type;
10109 #endif
10110
10111         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10112                 return;
10113
10114 #ifdef RTE_LIBRTE_I40E_PMD
10115         memset(&region_conf, 0, sizeof(region_conf));
10116
10117         if (strcmp(res->what, "on") == 0)
10118                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10119         else
10120                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10121
10122         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10123                                 op_type, &region_conf);
10124 #endif
10125
10126         switch (ret) {
10127         case 0:
10128                 break;
10129         case -ENOTSUP:
10130                 printf("function not implemented or supported\n");
10131                 break;
10132         default:
10133                 printf("queue region config flush error: (%s)\n",
10134                                 strerror(-ret));
10135         }
10136 }
10137
10138 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10139         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10140                                 set, "set");
10141 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10142         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10143                                 port, "port");
10144 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10145         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10146                                 port_id, UINT16);
10147 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10148         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10149                                 cmd, "queue-region");
10150 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10151         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10152                                 flush, "flush");
10153 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10154         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10155                                 what, "on#off");
10156
10157 cmdline_parse_inst_t cmd_flush_queue_region = {
10158         .f = cmd_flush_queue_region_parsed,
10159         .data = NULL,
10160         .help_str = "set port <port_id> queue-region flush on|off"
10161                 ": flush all queue region related configuration",
10162         .tokens = {
10163                 (void *)&cmd_flush_queue_region_set,
10164                 (void *)&cmd_flush_queue_region_port,
10165                 (void *)&cmd_flush_queue_region_port_index,
10166                 (void *)&cmd_flush_queue_region_cmd,
10167                 (void *)&cmd_flush_queue_region_flush,
10168                 (void *)&cmd_flush_queue_region_what,
10169                 NULL,
10170         },
10171 };
10172
10173 /* *** get all queue region related configuration info *** */
10174 struct cmd_show_queue_region_info {
10175         cmdline_fixed_string_t show;
10176         cmdline_fixed_string_t port;
10177         portid_t port_id;
10178         cmdline_fixed_string_t cmd;
10179 };
10180
10181 static void
10182 cmd_show_queue_region_info_parsed(void *parsed_result,
10183                         __rte_unused struct cmdline *cl,
10184                         __rte_unused void *data)
10185 {
10186         struct cmd_show_queue_region_info *res = parsed_result;
10187         int ret = -ENOTSUP;
10188 #ifdef RTE_LIBRTE_I40E_PMD
10189         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10190         enum rte_pmd_i40e_queue_region_op op_type;
10191 #endif
10192
10193         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10194                 return;
10195
10196 #ifdef RTE_LIBRTE_I40E_PMD
10197         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10198
10199         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10200
10201         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10202                                         op_type, &rte_pmd_regions);
10203
10204         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10205 #endif
10206
10207         switch (ret) {
10208         case 0:
10209                 break;
10210         case -ENOTSUP:
10211                 printf("function not implemented or supported\n");
10212                 break;
10213         default:
10214                 printf("queue region config info show error: (%s)\n",
10215                                 strerror(-ret));
10216         }
10217 }
10218
10219 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10220 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10221                                 show, "show");
10222 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10223         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10224                                 port, "port");
10225 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10226         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10227                                 port_id, UINT16);
10228 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10229         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10230                                 cmd, "queue-region");
10231
10232 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10233         .f = cmd_show_queue_region_info_parsed,
10234         .data = NULL,
10235         .help_str = "show port <port_id> queue-region"
10236                 ": show all queue region related configuration info",
10237         .tokens = {
10238                 (void *)&cmd_show_queue_region_info_get,
10239                 (void *)&cmd_show_queue_region_info_port,
10240                 (void *)&cmd_show_queue_region_info_port_index,
10241                 (void *)&cmd_show_queue_region_info_cmd,
10242                 NULL,
10243         },
10244 };
10245
10246 /* *** ADD/REMOVE A 2tuple FILTER *** */
10247 struct cmd_2tuple_filter_result {
10248         cmdline_fixed_string_t filter;
10249         portid_t port_id;
10250         cmdline_fixed_string_t ops;
10251         cmdline_fixed_string_t dst_port;
10252         uint16_t dst_port_value;
10253         cmdline_fixed_string_t protocol;
10254         uint8_t protocol_value;
10255         cmdline_fixed_string_t mask;
10256         uint8_t  mask_value;
10257         cmdline_fixed_string_t tcp_flags;
10258         uint8_t tcp_flags_value;
10259         cmdline_fixed_string_t priority;
10260         uint8_t  priority_value;
10261         cmdline_fixed_string_t queue;
10262         uint16_t  queue_id;
10263 };
10264
10265 static void
10266 cmd_2tuple_filter_parsed(void *parsed_result,
10267                         __rte_unused struct cmdline *cl,
10268                         __rte_unused void *data)
10269 {
10270         struct rte_eth_ntuple_filter filter;
10271         struct cmd_2tuple_filter_result *res = parsed_result;
10272         int ret = 0;
10273
10274         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10275         if (ret < 0) {
10276                 printf("ntuple filter is not supported on port %u.\n",
10277                         res->port_id);
10278                 return;
10279         }
10280
10281         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10282
10283         filter.flags = RTE_2TUPLE_FLAGS;
10284         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10285         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10286         filter.proto = res->protocol_value;
10287         filter.priority = res->priority_value;
10288         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10289                 printf("nonzero tcp_flags is only meaningful"
10290                         " when protocol is TCP.\n");
10291                 return;
10292         }
10293         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10294                 printf("invalid TCP flags.\n");
10295                 return;
10296         }
10297
10298         if (res->tcp_flags_value != 0) {
10299                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10300                 filter.tcp_flags = res->tcp_flags_value;
10301         }
10302
10303         /* need convert to big endian. */
10304         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10305         filter.queue = res->queue_id;
10306
10307         if (!strcmp(res->ops, "add"))
10308                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10309                                 RTE_ETH_FILTER_NTUPLE,
10310                                 RTE_ETH_FILTER_ADD,
10311                                 &filter);
10312         else
10313                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10314                                 RTE_ETH_FILTER_NTUPLE,
10315                                 RTE_ETH_FILTER_DELETE,
10316                                 &filter);
10317         if (ret < 0)
10318                 printf("2tuple filter programming error: (%s)\n",
10319                         strerror(-ret));
10320
10321 }
10322
10323 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10324         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10325                                  filter, "2tuple_filter");
10326 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10327         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10328                                 port_id, UINT16);
10329 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10330         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10331                                  ops, "add#del");
10332 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10333         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10334                                 dst_port, "dst_port");
10335 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10336         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10337                                 dst_port_value, UINT16);
10338 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10339         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10340                                 protocol, "protocol");
10341 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10342         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10343                                 protocol_value, UINT8);
10344 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10345         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10346                                 mask, "mask");
10347 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10348         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10349                                 mask_value, INT8);
10350 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10351         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10352                                 tcp_flags, "tcp_flags");
10353 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10354         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10355                                 tcp_flags_value, UINT8);
10356 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10357         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10358                                 priority, "priority");
10359 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10360         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10361                                 priority_value, UINT8);
10362 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10363         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10364                                 queue, "queue");
10365 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10366         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10367                                 queue_id, UINT16);
10368
10369 cmdline_parse_inst_t cmd_2tuple_filter = {
10370         .f = cmd_2tuple_filter_parsed,
10371         .data = NULL,
10372         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10373                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10374                 "<queue_id>: Add a 2tuple filter",
10375         .tokens = {
10376                 (void *)&cmd_2tuple_filter_filter,
10377                 (void *)&cmd_2tuple_filter_port_id,
10378                 (void *)&cmd_2tuple_filter_ops,
10379                 (void *)&cmd_2tuple_filter_dst_port,
10380                 (void *)&cmd_2tuple_filter_dst_port_value,
10381                 (void *)&cmd_2tuple_filter_protocol,
10382                 (void *)&cmd_2tuple_filter_protocol_value,
10383                 (void *)&cmd_2tuple_filter_mask,
10384                 (void *)&cmd_2tuple_filter_mask_value,
10385                 (void *)&cmd_2tuple_filter_tcp_flags,
10386                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10387                 (void *)&cmd_2tuple_filter_priority,
10388                 (void *)&cmd_2tuple_filter_priority_value,
10389                 (void *)&cmd_2tuple_filter_queue,
10390                 (void *)&cmd_2tuple_filter_queue_id,
10391                 NULL,
10392         },
10393 };
10394
10395 /* *** ADD/REMOVE A 5tuple FILTER *** */
10396 struct cmd_5tuple_filter_result {
10397         cmdline_fixed_string_t filter;
10398         portid_t port_id;
10399         cmdline_fixed_string_t ops;
10400         cmdline_fixed_string_t dst_ip;
10401         cmdline_ipaddr_t dst_ip_value;
10402         cmdline_fixed_string_t src_ip;
10403         cmdline_ipaddr_t src_ip_value;
10404         cmdline_fixed_string_t dst_port;
10405         uint16_t dst_port_value;
10406         cmdline_fixed_string_t src_port;
10407         uint16_t src_port_value;
10408         cmdline_fixed_string_t protocol;
10409         uint8_t protocol_value;
10410         cmdline_fixed_string_t mask;
10411         uint8_t  mask_value;
10412         cmdline_fixed_string_t tcp_flags;
10413         uint8_t tcp_flags_value;
10414         cmdline_fixed_string_t priority;
10415         uint8_t  priority_value;
10416         cmdline_fixed_string_t queue;
10417         uint16_t  queue_id;
10418 };
10419
10420 static void
10421 cmd_5tuple_filter_parsed(void *parsed_result,
10422                         __rte_unused struct cmdline *cl,
10423                         __rte_unused void *data)
10424 {
10425         struct rte_eth_ntuple_filter filter;
10426         struct cmd_5tuple_filter_result *res = parsed_result;
10427         int ret = 0;
10428
10429         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10430         if (ret < 0) {
10431                 printf("ntuple filter is not supported on port %u.\n",
10432                         res->port_id);
10433                 return;
10434         }
10435
10436         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10437
10438         filter.flags = RTE_5TUPLE_FLAGS;
10439         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10440         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10441         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10442         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10443         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10444         filter.proto = res->protocol_value;
10445         filter.priority = res->priority_value;
10446         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10447                 printf("nonzero tcp_flags is only meaningful"
10448                         " when protocol is TCP.\n");
10449                 return;
10450         }
10451         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10452                 printf("invalid TCP flags.\n");
10453                 return;
10454         }
10455
10456         if (res->tcp_flags_value != 0) {
10457                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10458                 filter.tcp_flags = res->tcp_flags_value;
10459         }
10460
10461         if (res->dst_ip_value.family == AF_INET)
10462                 /* no need to convert, already big endian. */
10463                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10464         else {
10465                 if (filter.dst_ip_mask == 0) {
10466                         printf("can not support ipv6 involved compare.\n");
10467                         return;
10468                 }
10469                 filter.dst_ip = 0;
10470         }
10471
10472         if (res->src_ip_value.family == AF_INET)
10473                 /* no need to convert, already big endian. */
10474                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10475         else {
10476                 if (filter.src_ip_mask == 0) {
10477                         printf("can not support ipv6 involved compare.\n");
10478                         return;
10479                 }
10480                 filter.src_ip = 0;
10481         }
10482         /* need convert to big endian. */
10483         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10484         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10485         filter.queue = res->queue_id;
10486
10487         if (!strcmp(res->ops, "add"))
10488                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10489                                 RTE_ETH_FILTER_NTUPLE,
10490                                 RTE_ETH_FILTER_ADD,
10491                                 &filter);
10492         else
10493                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10494                                 RTE_ETH_FILTER_NTUPLE,
10495                                 RTE_ETH_FILTER_DELETE,
10496                                 &filter);
10497         if (ret < 0)
10498                 printf("5tuple filter programming error: (%s)\n",
10499                         strerror(-ret));
10500 }
10501
10502 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10503         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10504                                  filter, "5tuple_filter");
10505 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10506         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10507                                 port_id, UINT16);
10508 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10509         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10510                                  ops, "add#del");
10511 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10512         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10513                                 dst_ip, "dst_ip");
10514 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10515         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10516                                 dst_ip_value);
10517 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10518         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10519                                 src_ip, "src_ip");
10520 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10521         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10522                                 src_ip_value);
10523 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10524         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10525                                 dst_port, "dst_port");
10526 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10527         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10528                                 dst_port_value, UINT16);
10529 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10530         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10531                                 src_port, "src_port");
10532 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10533         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10534                                 src_port_value, UINT16);
10535 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10536         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10537                                 protocol, "protocol");
10538 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10539         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10540                                 protocol_value, UINT8);
10541 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10542         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10543                                 mask, "mask");
10544 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10545         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10546                                 mask_value, INT8);
10547 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10548         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10549                                 tcp_flags, "tcp_flags");
10550 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10551         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10552                                 tcp_flags_value, UINT8);
10553 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10554         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10555                                 priority, "priority");
10556 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10557         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10558                                 priority_value, UINT8);
10559 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10560         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10561                                 queue, "queue");
10562 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10563         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10564                                 queue_id, UINT16);
10565
10566 cmdline_parse_inst_t cmd_5tuple_filter = {
10567         .f = cmd_5tuple_filter_parsed,
10568         .data = NULL,
10569         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10570                 "src_ip <value> dst_port <value> src_port <value> "
10571                 "protocol <value>  mask <value> tcp_flags <value> "
10572                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10573         .tokens = {
10574                 (void *)&cmd_5tuple_filter_filter,
10575                 (void *)&cmd_5tuple_filter_port_id,
10576                 (void *)&cmd_5tuple_filter_ops,
10577                 (void *)&cmd_5tuple_filter_dst_ip,
10578                 (void *)&cmd_5tuple_filter_dst_ip_value,
10579                 (void *)&cmd_5tuple_filter_src_ip,
10580                 (void *)&cmd_5tuple_filter_src_ip_value,
10581                 (void *)&cmd_5tuple_filter_dst_port,
10582                 (void *)&cmd_5tuple_filter_dst_port_value,
10583                 (void *)&cmd_5tuple_filter_src_port,
10584                 (void *)&cmd_5tuple_filter_src_port_value,
10585                 (void *)&cmd_5tuple_filter_protocol,
10586                 (void *)&cmd_5tuple_filter_protocol_value,
10587                 (void *)&cmd_5tuple_filter_mask,
10588                 (void *)&cmd_5tuple_filter_mask_value,
10589                 (void *)&cmd_5tuple_filter_tcp_flags,
10590                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10591                 (void *)&cmd_5tuple_filter_priority,
10592                 (void *)&cmd_5tuple_filter_priority_value,
10593                 (void *)&cmd_5tuple_filter_queue,
10594                 (void *)&cmd_5tuple_filter_queue_id,
10595                 NULL,
10596         },
10597 };
10598
10599 /* *** ADD/REMOVE A flex FILTER *** */
10600 struct cmd_flex_filter_result {
10601         cmdline_fixed_string_t filter;
10602         cmdline_fixed_string_t ops;
10603         portid_t port_id;
10604         cmdline_fixed_string_t len;
10605         uint8_t len_value;
10606         cmdline_fixed_string_t bytes;
10607         cmdline_fixed_string_t bytes_value;
10608         cmdline_fixed_string_t mask;
10609         cmdline_fixed_string_t mask_value;
10610         cmdline_fixed_string_t priority;
10611         uint8_t priority_value;
10612         cmdline_fixed_string_t queue;
10613         uint16_t queue_id;
10614 };
10615
10616 static int xdigit2val(unsigned char c)
10617 {
10618         int val;
10619         if (isdigit(c))
10620                 val = c - '0';
10621         else if (isupper(c))
10622                 val = c - 'A' + 10;
10623         else
10624                 val = c - 'a' + 10;
10625         return val;
10626 }
10627
10628 static void
10629 cmd_flex_filter_parsed(void *parsed_result,
10630                           __rte_unused struct cmdline *cl,
10631                           __rte_unused void *data)
10632 {
10633         int ret = 0;
10634         struct rte_eth_flex_filter filter;
10635         struct cmd_flex_filter_result *res = parsed_result;
10636         char *bytes_ptr, *mask_ptr;
10637         uint16_t len, i, j = 0;
10638         char c;
10639         int val;
10640         uint8_t byte = 0;
10641
10642         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10643                 printf("the len exceed the max length 128\n");
10644                 return;
10645         }
10646         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10647         filter.len = res->len_value;
10648         filter.priority = res->priority_value;
10649         filter.queue = res->queue_id;
10650         bytes_ptr = res->bytes_value;
10651         mask_ptr = res->mask_value;
10652
10653          /* translate bytes string to array. */
10654         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10655                 (bytes_ptr[1] == 'X')))
10656                 bytes_ptr += 2;
10657         len = strnlen(bytes_ptr, res->len_value * 2);
10658         if (len == 0 || (len % 8 != 0)) {
10659                 printf("please check len and bytes input\n");
10660                 return;
10661         }
10662         for (i = 0; i < len; i++) {
10663                 c = bytes_ptr[i];
10664                 if (isxdigit(c) == 0) {
10665                         /* invalid characters. */
10666                         printf("invalid input\n");
10667                         return;
10668                 }
10669                 val = xdigit2val(c);
10670                 if (i % 2) {
10671                         byte |= val;
10672                         filter.bytes[j] = byte;
10673                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10674                         j++;
10675                         byte = 0;
10676                 } else
10677                         byte |= val << 4;
10678         }
10679         printf("\n");
10680          /* translate mask string to uint8_t array. */
10681         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10682                 (mask_ptr[1] == 'X')))
10683                 mask_ptr += 2;
10684         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10685         if (len == 0) {
10686                 printf("invalid input\n");
10687                 return;
10688         }
10689         j = 0;
10690         byte = 0;
10691         for (i = 0; i < len; i++) {
10692                 c = mask_ptr[i];
10693                 if (isxdigit(c) == 0) {
10694                         /* invalid characters. */
10695                         printf("invalid input\n");
10696                         return;
10697                 }
10698                 val = xdigit2val(c);
10699                 if (i % 2) {
10700                         byte |= val;
10701                         filter.mask[j] = byte;
10702                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10703                         j++;
10704                         byte = 0;
10705                 } else
10706                         byte |= val << 4;
10707         }
10708         printf("\n");
10709
10710         if (!strcmp(res->ops, "add"))
10711                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10712                                 RTE_ETH_FILTER_FLEXIBLE,
10713                                 RTE_ETH_FILTER_ADD,
10714                                 &filter);
10715         else
10716                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10717                                 RTE_ETH_FILTER_FLEXIBLE,
10718                                 RTE_ETH_FILTER_DELETE,
10719                                 &filter);
10720
10721         if (ret < 0)
10722                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10723 }
10724
10725 cmdline_parse_token_string_t cmd_flex_filter_filter =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10727                                 filter, "flex_filter");
10728 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10729         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10730                                 port_id, UINT16);
10731 cmdline_parse_token_string_t cmd_flex_filter_ops =
10732         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10733                                 ops, "add#del");
10734 cmdline_parse_token_string_t cmd_flex_filter_len =
10735         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10736                                 len, "len");
10737 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10738         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10739                                 len_value, UINT8);
10740 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10741         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10742                                 bytes, "bytes");
10743 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10744         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10745                                 bytes_value, NULL);
10746 cmdline_parse_token_string_t cmd_flex_filter_mask =
10747         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10748                                 mask, "mask");
10749 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10750         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10751                                 mask_value, NULL);
10752 cmdline_parse_token_string_t cmd_flex_filter_priority =
10753         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10754                                 priority, "priority");
10755 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10756         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10757                                 priority_value, UINT8);
10758 cmdline_parse_token_string_t cmd_flex_filter_queue =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10760                                 queue, "queue");
10761 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10762         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10763                                 queue_id, UINT16);
10764 cmdline_parse_inst_t cmd_flex_filter = {
10765         .f = cmd_flex_filter_parsed,
10766         .data = NULL,
10767         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10768                 "<value> mask <value> priority <value> queue <queue_id>: "
10769                 "Add/Del a flex filter",
10770         .tokens = {
10771                 (void *)&cmd_flex_filter_filter,
10772                 (void *)&cmd_flex_filter_port_id,
10773                 (void *)&cmd_flex_filter_ops,
10774                 (void *)&cmd_flex_filter_len,
10775                 (void *)&cmd_flex_filter_len_value,
10776                 (void *)&cmd_flex_filter_bytes,
10777                 (void *)&cmd_flex_filter_bytes_value,
10778                 (void *)&cmd_flex_filter_mask,
10779                 (void *)&cmd_flex_filter_mask_value,
10780                 (void *)&cmd_flex_filter_priority,
10781                 (void *)&cmd_flex_filter_priority_value,
10782                 (void *)&cmd_flex_filter_queue,
10783                 (void *)&cmd_flex_filter_queue_id,
10784                 NULL,
10785         },
10786 };
10787
10788 /* *** Filters Control *** */
10789
10790 /* *** deal with ethertype filter *** */
10791 struct cmd_ethertype_filter_result {
10792         cmdline_fixed_string_t filter;
10793         portid_t port_id;
10794         cmdline_fixed_string_t ops;
10795         cmdline_fixed_string_t mac;
10796         struct rte_ether_addr mac_addr;
10797         cmdline_fixed_string_t ethertype;
10798         uint16_t ethertype_value;
10799         cmdline_fixed_string_t drop;
10800         cmdline_fixed_string_t queue;
10801         uint16_t  queue_id;
10802 };
10803
10804 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10805         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10806                                  filter, "ethertype_filter");
10807 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10808         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10809                               port_id, UINT16);
10810 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10811         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10812                                  ops, "add#del");
10813 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10814         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10815                                  mac, "mac_addr#mac_ignr");
10816 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10817         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10818                                      mac_addr);
10819 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10820         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10821                                  ethertype, "ethertype");
10822 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10823         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10824                               ethertype_value, UINT16);
10825 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10826         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10827                                  drop, "drop#fwd");
10828 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10829         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10830                                  queue, "queue");
10831 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10832         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10833                               queue_id, UINT16);
10834
10835 static void
10836 cmd_ethertype_filter_parsed(void *parsed_result,
10837                           __rte_unused struct cmdline *cl,
10838                           __rte_unused void *data)
10839 {
10840         struct cmd_ethertype_filter_result *res = parsed_result;
10841         struct rte_eth_ethertype_filter filter;
10842         int ret = 0;
10843
10844         ret = rte_eth_dev_filter_supported(res->port_id,
10845                         RTE_ETH_FILTER_ETHERTYPE);
10846         if (ret < 0) {
10847                 printf("ethertype filter is not supported on port %u.\n",
10848                         res->port_id);
10849                 return;
10850         }
10851
10852         memset(&filter, 0, sizeof(filter));
10853         if (!strcmp(res->mac, "mac_addr")) {
10854                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10855                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10856                         sizeof(struct rte_ether_addr));
10857         }
10858         if (!strcmp(res->drop, "drop"))
10859                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10860         filter.ether_type = res->ethertype_value;
10861         filter.queue = res->queue_id;
10862
10863         if (!strcmp(res->ops, "add"))
10864                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10865                                 RTE_ETH_FILTER_ETHERTYPE,
10866                                 RTE_ETH_FILTER_ADD,
10867                                 &filter);
10868         else
10869                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10870                                 RTE_ETH_FILTER_ETHERTYPE,
10871                                 RTE_ETH_FILTER_DELETE,
10872                                 &filter);
10873         if (ret < 0)
10874                 printf("ethertype filter programming error: (%s)\n",
10875                         strerror(-ret));
10876 }
10877
10878 cmdline_parse_inst_t cmd_ethertype_filter = {
10879         .f = cmd_ethertype_filter_parsed,
10880         .data = NULL,
10881         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10882                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10883                 "Add or delete an ethertype filter entry",
10884         .tokens = {
10885                 (void *)&cmd_ethertype_filter_filter,
10886                 (void *)&cmd_ethertype_filter_port_id,
10887                 (void *)&cmd_ethertype_filter_ops,
10888                 (void *)&cmd_ethertype_filter_mac,
10889                 (void *)&cmd_ethertype_filter_mac_addr,
10890                 (void *)&cmd_ethertype_filter_ethertype,
10891                 (void *)&cmd_ethertype_filter_ethertype_value,
10892                 (void *)&cmd_ethertype_filter_drop,
10893                 (void *)&cmd_ethertype_filter_queue,
10894                 (void *)&cmd_ethertype_filter_queue_id,
10895                 NULL,
10896         },
10897 };
10898
10899 /* *** deal with flow director filter *** */
10900 struct cmd_flow_director_result {
10901         cmdline_fixed_string_t flow_director_filter;
10902         portid_t port_id;
10903         cmdline_fixed_string_t mode;
10904         cmdline_fixed_string_t mode_value;
10905         cmdline_fixed_string_t ops;
10906         cmdline_fixed_string_t flow;
10907         cmdline_fixed_string_t flow_type;
10908         cmdline_fixed_string_t ether;
10909         uint16_t ether_type;
10910         cmdline_fixed_string_t src;
10911         cmdline_ipaddr_t ip_src;
10912         uint16_t port_src;
10913         cmdline_fixed_string_t dst;
10914         cmdline_ipaddr_t ip_dst;
10915         uint16_t port_dst;
10916         cmdline_fixed_string_t verify_tag;
10917         uint32_t verify_tag_value;
10918         cmdline_fixed_string_t tos;
10919         uint8_t tos_value;
10920         cmdline_fixed_string_t proto;
10921         uint8_t proto_value;
10922         cmdline_fixed_string_t ttl;
10923         uint8_t ttl_value;
10924         cmdline_fixed_string_t vlan;
10925         uint16_t vlan_value;
10926         cmdline_fixed_string_t flexbytes;
10927         cmdline_fixed_string_t flexbytes_value;
10928         cmdline_fixed_string_t pf_vf;
10929         cmdline_fixed_string_t drop;
10930         cmdline_fixed_string_t queue;
10931         uint16_t  queue_id;
10932         cmdline_fixed_string_t fd_id;
10933         uint32_t  fd_id_value;
10934         cmdline_fixed_string_t mac;
10935         struct rte_ether_addr mac_addr;
10936         cmdline_fixed_string_t tunnel;
10937         cmdline_fixed_string_t tunnel_type;
10938         cmdline_fixed_string_t tunnel_id;
10939         uint32_t tunnel_id_value;
10940         cmdline_fixed_string_t packet;
10941         char filepath[];
10942 };
10943
10944 static inline int
10945 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10946 {
10947         char s[256];
10948         const char *p, *p0 = q_arg;
10949         char *end;
10950         unsigned long int_fld;
10951         char *str_fld[max_num];
10952         int i;
10953         unsigned size;
10954         int ret = -1;
10955
10956         p = strchr(p0, '(');
10957         if (p == NULL)
10958                 return -1;
10959         ++p;
10960         p0 = strchr(p, ')');
10961         if (p0 == NULL)
10962                 return -1;
10963
10964         size = p0 - p;
10965         if (size >= sizeof(s))
10966                 return -1;
10967
10968         snprintf(s, sizeof(s), "%.*s", size, p);
10969         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10970         if (ret < 0 || ret > max_num)
10971                 return -1;
10972         for (i = 0; i < ret; i++) {
10973                 errno = 0;
10974                 int_fld = strtoul(str_fld[i], &end, 0);
10975                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10976                         return -1;
10977                 flexbytes[i] = (uint8_t)int_fld;
10978         }
10979         return ret;
10980 }
10981
10982 static uint16_t
10983 str2flowtype(char *string)
10984 {
10985         uint8_t i = 0;
10986         static const struct {
10987                 char str[32];
10988                 uint16_t type;
10989         } flowtype_str[] = {
10990                 {"raw", RTE_ETH_FLOW_RAW},
10991                 {"ipv4", RTE_ETH_FLOW_IPV4},
10992                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10993                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10994                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10995                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10996                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10997                 {"ipv6", RTE_ETH_FLOW_IPV6},
10998                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10999                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11000                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11001                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11002                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11003                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11004         };
11005
11006         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11007                 if (!strcmp(flowtype_str[i].str, string))
11008                         return flowtype_str[i].type;
11009         }
11010
11011         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11012                 return (uint16_t)atoi(string);
11013
11014         return RTE_ETH_FLOW_UNKNOWN;
11015 }
11016
11017 static enum rte_eth_fdir_tunnel_type
11018 str2fdir_tunneltype(char *string)
11019 {
11020         uint8_t i = 0;
11021
11022         static const struct {
11023                 char str[32];
11024                 enum rte_eth_fdir_tunnel_type type;
11025         } tunneltype_str[] = {
11026                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11027                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11028         };
11029
11030         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11031                 if (!strcmp(tunneltype_str[i].str, string))
11032                         return tunneltype_str[i].type;
11033         }
11034         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11035 }
11036
11037 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11038 do { \
11039         if ((ip_addr).family == AF_INET) \
11040                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11041         else { \
11042                 printf("invalid parameter.\n"); \
11043                 return; \
11044         } \
11045 } while (0)
11046
11047 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11048 do { \
11049         if ((ip_addr).family == AF_INET6) \
11050                 rte_memcpy(&(ip), \
11051                                  &((ip_addr).addr.ipv6), \
11052                                  sizeof(struct in6_addr)); \
11053         else { \
11054                 printf("invalid parameter.\n"); \
11055                 return; \
11056         } \
11057 } while (0)
11058
11059 static void
11060 cmd_flow_director_filter_parsed(void *parsed_result,
11061                           __rte_unused struct cmdline *cl,
11062                           __rte_unused void *data)
11063 {
11064         struct cmd_flow_director_result *res = parsed_result;
11065         struct rte_eth_fdir_filter entry;
11066         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11067         char *end;
11068         unsigned long vf_id;
11069         int ret = 0;
11070
11071         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11072         if (ret < 0) {
11073                 printf("flow director is not supported on port %u.\n",
11074                         res->port_id);
11075                 return;
11076         }
11077         memset(flexbytes, 0, sizeof(flexbytes));
11078         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11079
11080         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11081                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11082                         printf("Please set mode to MAC-VLAN.\n");
11083                         return;
11084                 }
11085         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11086                 if (strcmp(res->mode_value, "Tunnel")) {
11087                         printf("Please set mode to Tunnel.\n");
11088                         return;
11089                 }
11090         } else {
11091                 if (!strcmp(res->mode_value, "raw")) {
11092 #ifdef RTE_LIBRTE_I40E_PMD
11093                         struct rte_pmd_i40e_flow_type_mapping
11094                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11095                         struct rte_pmd_i40e_pkt_template_conf conf;
11096                         uint16_t flow_type = str2flowtype(res->flow_type);
11097                         uint16_t i, port = res->port_id;
11098                         uint8_t add;
11099
11100                         memset(&conf, 0, sizeof(conf));
11101
11102                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11103                                 printf("Invalid flow type specified.\n");
11104                                 return;
11105                         }
11106                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11107                                                                  mapping);
11108                         if (ret)
11109                                 return;
11110                         if (mapping[flow_type].pctype == 0ULL) {
11111                                 printf("Invalid flow type specified.\n");
11112                                 return;
11113                         }
11114                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11115                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11116                                         conf.input.pctype = i;
11117                                         break;
11118                                 }
11119                         }
11120
11121                         conf.input.packet = open_file(res->filepath,
11122                                                 &conf.input.length);
11123                         if (!conf.input.packet)
11124                                 return;
11125                         if (!strcmp(res->drop, "drop"))
11126                                 conf.action.behavior =
11127                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11128                         else
11129                                 conf.action.behavior =
11130                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11131                         conf.action.report_status =
11132                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11133                         conf.action.rx_queue = res->queue_id;
11134                         conf.soft_id = res->fd_id_value;
11135                         add  = strcmp(res->ops, "del") ? 1 : 0;
11136                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11137                                                                         &conf,
11138                                                                         add);
11139                         if (ret < 0)
11140                                 printf("flow director config error: (%s)\n",
11141                                        strerror(-ret));
11142                         close_file(conf.input.packet);
11143 #endif
11144                         return;
11145                 } else if (strcmp(res->mode_value, "IP")) {
11146                         printf("Please set mode to IP or raw.\n");
11147                         return;
11148                 }
11149                 entry.input.flow_type = str2flowtype(res->flow_type);
11150         }
11151
11152         ret = parse_flexbytes(res->flexbytes_value,
11153                                         flexbytes,
11154                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11155         if (ret < 0) {
11156                 printf("error: Cannot parse flexbytes input.\n");
11157                 return;
11158         }
11159
11160         switch (entry.input.flow_type) {
11161         case RTE_ETH_FLOW_FRAG_IPV4:
11162         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11163                 entry.input.flow.ip4_flow.proto = res->proto_value;
11164                 /* fall-through */
11165         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11166         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11167                 IPV4_ADDR_TO_UINT(res->ip_dst,
11168                         entry.input.flow.ip4_flow.dst_ip);
11169                 IPV4_ADDR_TO_UINT(res->ip_src,
11170                         entry.input.flow.ip4_flow.src_ip);
11171                 entry.input.flow.ip4_flow.tos = res->tos_value;
11172                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11173                 /* need convert to big endian. */
11174                 entry.input.flow.udp4_flow.dst_port =
11175                                 rte_cpu_to_be_16(res->port_dst);
11176                 entry.input.flow.udp4_flow.src_port =
11177                                 rte_cpu_to_be_16(res->port_src);
11178                 break;
11179         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11180                 IPV4_ADDR_TO_UINT(res->ip_dst,
11181                         entry.input.flow.sctp4_flow.ip.dst_ip);
11182                 IPV4_ADDR_TO_UINT(res->ip_src,
11183                         entry.input.flow.sctp4_flow.ip.src_ip);
11184                 entry.input.flow.ip4_flow.tos = res->tos_value;
11185                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11186                 /* need convert to big endian. */
11187                 entry.input.flow.sctp4_flow.dst_port =
11188                                 rte_cpu_to_be_16(res->port_dst);
11189                 entry.input.flow.sctp4_flow.src_port =
11190                                 rte_cpu_to_be_16(res->port_src);
11191                 entry.input.flow.sctp4_flow.verify_tag =
11192                                 rte_cpu_to_be_32(res->verify_tag_value);
11193                 break;
11194         case RTE_ETH_FLOW_FRAG_IPV6:
11195         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11196                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11197                 /* fall-through */
11198         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11199         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11200                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11201                         entry.input.flow.ipv6_flow.dst_ip);
11202                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11203                         entry.input.flow.ipv6_flow.src_ip);
11204                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11205                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11206                 /* need convert to big endian. */
11207                 entry.input.flow.udp6_flow.dst_port =
11208                                 rte_cpu_to_be_16(res->port_dst);
11209                 entry.input.flow.udp6_flow.src_port =
11210                                 rte_cpu_to_be_16(res->port_src);
11211                 break;
11212         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11213                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11214                         entry.input.flow.sctp6_flow.ip.dst_ip);
11215                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11216                         entry.input.flow.sctp6_flow.ip.src_ip);
11217                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11218                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11219                 /* need convert to big endian. */
11220                 entry.input.flow.sctp6_flow.dst_port =
11221                                 rte_cpu_to_be_16(res->port_dst);
11222                 entry.input.flow.sctp6_flow.src_port =
11223                                 rte_cpu_to_be_16(res->port_src);
11224                 entry.input.flow.sctp6_flow.verify_tag =
11225                                 rte_cpu_to_be_32(res->verify_tag_value);
11226                 break;
11227         case RTE_ETH_FLOW_L2_PAYLOAD:
11228                 entry.input.flow.l2_flow.ether_type =
11229                         rte_cpu_to_be_16(res->ether_type);
11230                 break;
11231         default:
11232                 break;
11233         }
11234
11235         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11236                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11237                                  &res->mac_addr,
11238                                  sizeof(struct rte_ether_addr));
11239
11240         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11241                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11242                                  &res->mac_addr,
11243                                  sizeof(struct rte_ether_addr));
11244                 entry.input.flow.tunnel_flow.tunnel_type =
11245                         str2fdir_tunneltype(res->tunnel_type);
11246                 entry.input.flow.tunnel_flow.tunnel_id =
11247                         rte_cpu_to_be_32(res->tunnel_id_value);
11248         }
11249
11250         rte_memcpy(entry.input.flow_ext.flexbytes,
11251                    flexbytes,
11252                    RTE_ETH_FDIR_MAX_FLEXLEN);
11253
11254         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11255
11256         entry.action.flex_off = 0;  /*use 0 by default */
11257         if (!strcmp(res->drop, "drop"))
11258                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11259         else
11260                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11261
11262         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11263             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11264                 if (!strcmp(res->pf_vf, "pf"))
11265                         entry.input.flow_ext.is_vf = 0;
11266                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11267                         struct rte_eth_dev_info dev_info;
11268
11269                         ret = eth_dev_info_get_print_err(res->port_id,
11270                                                 &dev_info);
11271                         if (ret != 0)
11272                                 return;
11273
11274                         errno = 0;
11275                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11276                         if (errno != 0 || *end != '\0' ||
11277                             vf_id >= dev_info.max_vfs) {
11278                                 printf("invalid parameter %s.\n", res->pf_vf);
11279                                 return;
11280                         }
11281                         entry.input.flow_ext.is_vf = 1;
11282                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11283                 } else {
11284                         printf("invalid parameter %s.\n", res->pf_vf);
11285                         return;
11286                 }
11287         }
11288
11289         /* set to report FD ID by default */
11290         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11291         entry.action.rx_queue = res->queue_id;
11292         entry.soft_id = res->fd_id_value;
11293         if (!strcmp(res->ops, "add"))
11294                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11295                                              RTE_ETH_FILTER_ADD, &entry);
11296         else if (!strcmp(res->ops, "del"))
11297                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11298                                              RTE_ETH_FILTER_DELETE, &entry);
11299         else
11300                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11301                                              RTE_ETH_FILTER_UPDATE, &entry);
11302         if (ret < 0)
11303                 printf("flow director programming error: (%s)\n",
11304                         strerror(-ret));
11305 }
11306
11307 cmdline_parse_token_string_t cmd_flow_director_filter =
11308         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11309                                  flow_director_filter, "flow_director_filter");
11310 cmdline_parse_token_num_t cmd_flow_director_port_id =
11311         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11312                               port_id, UINT16);
11313 cmdline_parse_token_string_t cmd_flow_director_ops =
11314         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11315                                  ops, "add#del#update");
11316 cmdline_parse_token_string_t cmd_flow_director_flow =
11317         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11318                                  flow, "flow");
11319 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11320         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11321                 flow_type, NULL);
11322 cmdline_parse_token_string_t cmd_flow_director_ether =
11323         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11324                                  ether, "ether");
11325 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11326         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11327                               ether_type, UINT16);
11328 cmdline_parse_token_string_t cmd_flow_director_src =
11329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11330                                  src, "src");
11331 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11332         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11333                                  ip_src);
11334 cmdline_parse_token_num_t cmd_flow_director_port_src =
11335         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11336                               port_src, UINT16);
11337 cmdline_parse_token_string_t cmd_flow_director_dst =
11338         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11339                                  dst, "dst");
11340 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11341         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11342                                  ip_dst);
11343 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11344         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11345                               port_dst, UINT16);
11346 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348                                   verify_tag, "verify_tag");
11349 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11350         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11351                               verify_tag_value, UINT32);
11352 cmdline_parse_token_string_t cmd_flow_director_tos =
11353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354                                  tos, "tos");
11355 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11356         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11357                               tos_value, UINT8);
11358 cmdline_parse_token_string_t cmd_flow_director_proto =
11359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11360                                  proto, "proto");
11361 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11362         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11363                               proto_value, UINT8);
11364 cmdline_parse_token_string_t cmd_flow_director_ttl =
11365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11366                                  ttl, "ttl");
11367 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11368         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11369                               ttl_value, UINT8);
11370 cmdline_parse_token_string_t cmd_flow_director_vlan =
11371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11372                                  vlan, "vlan");
11373 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11374         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11375                               vlan_value, UINT16);
11376 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11377         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11378                                  flexbytes, "flexbytes");
11379 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11381                               flexbytes_value, NULL);
11382 cmdline_parse_token_string_t cmd_flow_director_drop =
11383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11384                                  drop, "drop#fwd");
11385 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11387                               pf_vf, NULL);
11388 cmdline_parse_token_string_t cmd_flow_director_queue =
11389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11390                                  queue, "queue");
11391 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11392         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11393                               queue_id, UINT16);
11394 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11395         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11396                                  fd_id, "fd_id");
11397 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11398         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11399                               fd_id_value, UINT32);
11400
11401 cmdline_parse_token_string_t cmd_flow_director_mode =
11402         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11403                                  mode, "mode");
11404 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11406                                  mode_value, "IP");
11407 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11408         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11409                                  mode_value, "MAC-VLAN");
11410 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11411         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11412                                  mode_value, "Tunnel");
11413 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11415                                  mode_value, "raw");
11416 cmdline_parse_token_string_t cmd_flow_director_mac =
11417         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11418                                  mac, "mac");
11419 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11420         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11421                                     mac_addr);
11422 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11423         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11424                                  tunnel, "tunnel");
11425 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11426         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11427                                  tunnel_type, "NVGRE#VxLAN");
11428 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11429         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11430                                  tunnel_id, "tunnel-id");
11431 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11432         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11433                               tunnel_id_value, UINT32);
11434 cmdline_parse_token_string_t cmd_flow_director_packet =
11435         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11436                                  packet, "packet");
11437 cmdline_parse_token_string_t cmd_flow_director_filepath =
11438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11439                                  filepath, NULL);
11440
11441 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11442         .f = cmd_flow_director_filter_parsed,
11443         .data = NULL,
11444         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11445                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11446                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11447                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11448                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11449                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11450                 "fd_id <fd_id_value>: "
11451                 "Add or delete an ip flow director entry on NIC",
11452         .tokens = {
11453                 (void *)&cmd_flow_director_filter,
11454                 (void *)&cmd_flow_director_port_id,
11455                 (void *)&cmd_flow_director_mode,
11456                 (void *)&cmd_flow_director_mode_ip,
11457                 (void *)&cmd_flow_director_ops,
11458                 (void *)&cmd_flow_director_flow,
11459                 (void *)&cmd_flow_director_flow_type,
11460                 (void *)&cmd_flow_director_src,
11461                 (void *)&cmd_flow_director_ip_src,
11462                 (void *)&cmd_flow_director_dst,
11463                 (void *)&cmd_flow_director_ip_dst,
11464                 (void *)&cmd_flow_director_tos,
11465                 (void *)&cmd_flow_director_tos_value,
11466                 (void *)&cmd_flow_director_proto,
11467                 (void *)&cmd_flow_director_proto_value,
11468                 (void *)&cmd_flow_director_ttl,
11469                 (void *)&cmd_flow_director_ttl_value,
11470                 (void *)&cmd_flow_director_vlan,
11471                 (void *)&cmd_flow_director_vlan_value,
11472                 (void *)&cmd_flow_director_flexbytes,
11473                 (void *)&cmd_flow_director_flexbytes_value,
11474                 (void *)&cmd_flow_director_drop,
11475                 (void *)&cmd_flow_director_pf_vf,
11476                 (void *)&cmd_flow_director_queue,
11477                 (void *)&cmd_flow_director_queue_id,
11478                 (void *)&cmd_flow_director_fd_id,
11479                 (void *)&cmd_flow_director_fd_id_value,
11480                 NULL,
11481         },
11482 };
11483
11484 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11485         .f = cmd_flow_director_filter_parsed,
11486         .data = NULL,
11487         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11488                 "director entry on NIC",
11489         .tokens = {
11490                 (void *)&cmd_flow_director_filter,
11491                 (void *)&cmd_flow_director_port_id,
11492                 (void *)&cmd_flow_director_mode,
11493                 (void *)&cmd_flow_director_mode_ip,
11494                 (void *)&cmd_flow_director_ops,
11495                 (void *)&cmd_flow_director_flow,
11496                 (void *)&cmd_flow_director_flow_type,
11497                 (void *)&cmd_flow_director_src,
11498                 (void *)&cmd_flow_director_ip_src,
11499                 (void *)&cmd_flow_director_port_src,
11500                 (void *)&cmd_flow_director_dst,
11501                 (void *)&cmd_flow_director_ip_dst,
11502                 (void *)&cmd_flow_director_port_dst,
11503                 (void *)&cmd_flow_director_tos,
11504                 (void *)&cmd_flow_director_tos_value,
11505                 (void *)&cmd_flow_director_ttl,
11506                 (void *)&cmd_flow_director_ttl_value,
11507                 (void *)&cmd_flow_director_vlan,
11508                 (void *)&cmd_flow_director_vlan_value,
11509                 (void *)&cmd_flow_director_flexbytes,
11510                 (void *)&cmd_flow_director_flexbytes_value,
11511                 (void *)&cmd_flow_director_drop,
11512                 (void *)&cmd_flow_director_pf_vf,
11513                 (void *)&cmd_flow_director_queue,
11514                 (void *)&cmd_flow_director_queue_id,
11515                 (void *)&cmd_flow_director_fd_id,
11516                 (void *)&cmd_flow_director_fd_id_value,
11517                 NULL,
11518         },
11519 };
11520
11521 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11522         .f = cmd_flow_director_filter_parsed,
11523         .data = NULL,
11524         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11525                 "director entry on NIC",
11526         .tokens = {
11527                 (void *)&cmd_flow_director_filter,
11528                 (void *)&cmd_flow_director_port_id,
11529                 (void *)&cmd_flow_director_mode,
11530                 (void *)&cmd_flow_director_mode_ip,
11531                 (void *)&cmd_flow_director_ops,
11532                 (void *)&cmd_flow_director_flow,
11533                 (void *)&cmd_flow_director_flow_type,
11534                 (void *)&cmd_flow_director_src,
11535                 (void *)&cmd_flow_director_ip_src,
11536                 (void *)&cmd_flow_director_port_src,
11537                 (void *)&cmd_flow_director_dst,
11538                 (void *)&cmd_flow_director_ip_dst,
11539                 (void *)&cmd_flow_director_port_dst,
11540                 (void *)&cmd_flow_director_verify_tag,
11541                 (void *)&cmd_flow_director_verify_tag_value,
11542                 (void *)&cmd_flow_director_tos,
11543                 (void *)&cmd_flow_director_tos_value,
11544                 (void *)&cmd_flow_director_ttl,
11545                 (void *)&cmd_flow_director_ttl_value,
11546                 (void *)&cmd_flow_director_vlan,
11547                 (void *)&cmd_flow_director_vlan_value,
11548                 (void *)&cmd_flow_director_flexbytes,
11549                 (void *)&cmd_flow_director_flexbytes_value,
11550                 (void *)&cmd_flow_director_drop,
11551                 (void *)&cmd_flow_director_pf_vf,
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_l2_flow_director = {
11561         .f = cmd_flow_director_filter_parsed,
11562         .data = NULL,
11563         .help_str = "flow_director_filter ... : Add or delete a L2 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_ip,
11570                 (void *)&cmd_flow_director_ops,
11571                 (void *)&cmd_flow_director_flow,
11572                 (void *)&cmd_flow_director_flow_type,
11573                 (void *)&cmd_flow_director_ether,
11574                 (void *)&cmd_flow_director_ether_type,
11575                 (void *)&cmd_flow_director_flexbytes,
11576                 (void *)&cmd_flow_director_flexbytes_value,
11577                 (void *)&cmd_flow_director_drop,
11578                 (void *)&cmd_flow_director_pf_vf,
11579                 (void *)&cmd_flow_director_queue,
11580                 (void *)&cmd_flow_director_queue_id,
11581                 (void *)&cmd_flow_director_fd_id,
11582                 (void *)&cmd_flow_director_fd_id_value,
11583                 NULL,
11584         },
11585 };
11586
11587 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11588         .f = cmd_flow_director_filter_parsed,
11589         .data = NULL,
11590         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11591                 "director entry on NIC",
11592         .tokens = {
11593                 (void *)&cmd_flow_director_filter,
11594                 (void *)&cmd_flow_director_port_id,
11595                 (void *)&cmd_flow_director_mode,
11596                 (void *)&cmd_flow_director_mode_mac_vlan,
11597                 (void *)&cmd_flow_director_ops,
11598                 (void *)&cmd_flow_director_mac,
11599                 (void *)&cmd_flow_director_mac_addr,
11600                 (void *)&cmd_flow_director_vlan,
11601                 (void *)&cmd_flow_director_vlan_value,
11602                 (void *)&cmd_flow_director_flexbytes,
11603                 (void *)&cmd_flow_director_flexbytes_value,
11604                 (void *)&cmd_flow_director_drop,
11605                 (void *)&cmd_flow_director_queue,
11606                 (void *)&cmd_flow_director_queue_id,
11607                 (void *)&cmd_flow_director_fd_id,
11608                 (void *)&cmd_flow_director_fd_id_value,
11609                 NULL,
11610         },
11611 };
11612
11613 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11614         .f = cmd_flow_director_filter_parsed,
11615         .data = NULL,
11616         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11617                 "director entry on NIC",
11618         .tokens = {
11619                 (void *)&cmd_flow_director_filter,
11620                 (void *)&cmd_flow_director_port_id,
11621                 (void *)&cmd_flow_director_mode,
11622                 (void *)&cmd_flow_director_mode_tunnel,
11623                 (void *)&cmd_flow_director_ops,
11624                 (void *)&cmd_flow_director_mac,
11625                 (void *)&cmd_flow_director_mac_addr,
11626                 (void *)&cmd_flow_director_vlan,
11627                 (void *)&cmd_flow_director_vlan_value,
11628                 (void *)&cmd_flow_director_tunnel,
11629                 (void *)&cmd_flow_director_tunnel_type,
11630                 (void *)&cmd_flow_director_tunnel_id,
11631                 (void *)&cmd_flow_director_tunnel_id_value,
11632                 (void *)&cmd_flow_director_flexbytes,
11633                 (void *)&cmd_flow_director_flexbytes_value,
11634                 (void *)&cmd_flow_director_drop,
11635                 (void *)&cmd_flow_director_queue,
11636                 (void *)&cmd_flow_director_queue_id,
11637                 (void *)&cmd_flow_director_fd_id,
11638                 (void *)&cmd_flow_director_fd_id_value,
11639                 NULL,
11640         },
11641 };
11642
11643 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11644         .f = cmd_flow_director_filter_parsed,
11645         .data = NULL,
11646         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11647                 "director entry on NIC",
11648         .tokens = {
11649                 (void *)&cmd_flow_director_filter,
11650                 (void *)&cmd_flow_director_port_id,
11651                 (void *)&cmd_flow_director_mode,
11652                 (void *)&cmd_flow_director_mode_raw,
11653                 (void *)&cmd_flow_director_ops,
11654                 (void *)&cmd_flow_director_flow,
11655                 (void *)&cmd_flow_director_flow_type,
11656                 (void *)&cmd_flow_director_drop,
11657                 (void *)&cmd_flow_director_queue,
11658                 (void *)&cmd_flow_director_queue_id,
11659                 (void *)&cmd_flow_director_fd_id,
11660                 (void *)&cmd_flow_director_fd_id_value,
11661                 (void *)&cmd_flow_director_packet,
11662                 (void *)&cmd_flow_director_filepath,
11663                 NULL,
11664         },
11665 };
11666
11667 struct cmd_flush_flow_director_result {
11668         cmdline_fixed_string_t flush_flow_director;
11669         portid_t port_id;
11670 };
11671
11672 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11673         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11674                                  flush_flow_director, "flush_flow_director");
11675 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11676         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11677                               port_id, UINT16);
11678
11679 static void
11680 cmd_flush_flow_director_parsed(void *parsed_result,
11681                           __rte_unused struct cmdline *cl,
11682                           __rte_unused void *data)
11683 {
11684         struct cmd_flow_director_result *res = parsed_result;
11685         int ret = 0;
11686
11687         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11688         if (ret < 0) {
11689                 printf("flow director is not supported on port %u.\n",
11690                         res->port_id);
11691                 return;
11692         }
11693
11694         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11695                         RTE_ETH_FILTER_FLUSH, NULL);
11696         if (ret < 0)
11697                 printf("flow director table flushing error: (%s)\n",
11698                         strerror(-ret));
11699 }
11700
11701 cmdline_parse_inst_t cmd_flush_flow_director = {
11702         .f = cmd_flush_flow_director_parsed,
11703         .data = NULL,
11704         .help_str = "flush_flow_director <port_id>: "
11705                 "Flush all flow director entries of a device on NIC",
11706         .tokens = {
11707                 (void *)&cmd_flush_flow_director_flush,
11708                 (void *)&cmd_flush_flow_director_port_id,
11709                 NULL,
11710         },
11711 };
11712
11713 /* *** deal with flow director mask *** */
11714 struct cmd_flow_director_mask_result {
11715         cmdline_fixed_string_t flow_director_mask;
11716         portid_t port_id;
11717         cmdline_fixed_string_t mode;
11718         cmdline_fixed_string_t mode_value;
11719         cmdline_fixed_string_t vlan;
11720         uint16_t vlan_mask;
11721         cmdline_fixed_string_t src_mask;
11722         cmdline_ipaddr_t ipv4_src;
11723         cmdline_ipaddr_t ipv6_src;
11724         uint16_t port_src;
11725         cmdline_fixed_string_t dst_mask;
11726         cmdline_ipaddr_t ipv4_dst;
11727         cmdline_ipaddr_t ipv6_dst;
11728         uint16_t port_dst;
11729         cmdline_fixed_string_t mac;
11730         uint8_t mac_addr_byte_mask;
11731         cmdline_fixed_string_t tunnel_id;
11732         uint32_t tunnel_id_mask;
11733         cmdline_fixed_string_t tunnel_type;
11734         uint8_t tunnel_type_mask;
11735 };
11736
11737 static void
11738 cmd_flow_director_mask_parsed(void *parsed_result,
11739                           __rte_unused struct cmdline *cl,
11740                           __rte_unused void *data)
11741 {
11742         struct cmd_flow_director_mask_result *res = parsed_result;
11743         struct rte_eth_fdir_masks *mask;
11744         struct rte_port *port;
11745
11746         port = &ports[res->port_id];
11747         /** Check if the port is not started **/
11748         if (port->port_status != RTE_PORT_STOPPED) {
11749                 printf("Please stop port %d first\n", res->port_id);
11750                 return;
11751         }
11752
11753         mask = &port->dev_conf.fdir_conf.mask;
11754
11755         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11756                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11757                         printf("Please set mode to MAC-VLAN.\n");
11758                         return;
11759                 }
11760
11761                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11762         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11763                 if (strcmp(res->mode_value, "Tunnel")) {
11764                         printf("Please set mode to Tunnel.\n");
11765                         return;
11766                 }
11767
11768                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11769                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11770                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11771                 mask->tunnel_type_mask = res->tunnel_type_mask;
11772         } else {
11773                 if (strcmp(res->mode_value, "IP")) {
11774                         printf("Please set mode to IP.\n");
11775                         return;
11776                 }
11777
11778                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11779                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11780                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11781                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11782                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11783                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11784                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11785         }
11786
11787         cmd_reconfig_device_queue(res->port_id, 1, 1);
11788 }
11789
11790 cmdline_parse_token_string_t cmd_flow_director_mask =
11791         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11792                                  flow_director_mask, "flow_director_mask");
11793 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11794         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11795                               port_id, UINT16);
11796 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11797         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11798                                  vlan, "vlan");
11799 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11800         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11801                               vlan_mask, UINT16);
11802 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11803         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11804                                  src_mask, "src_mask");
11805 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11806         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11807                                  ipv4_src);
11808 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11809         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11810                                  ipv6_src);
11811 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11812         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11813                               port_src, UINT16);
11814 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11815         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11816                                  dst_mask, "dst_mask");
11817 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11818         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11819                                  ipv4_dst);
11820 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11821         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11822                                  ipv6_dst);
11823 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11824         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11825                               port_dst, UINT16);
11826
11827 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11829                                  mode, "mode");
11830 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11831         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11832                                  mode_value, "IP");
11833 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11834         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11835                                  mode_value, "MAC-VLAN");
11836 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11837         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11838                                  mode_value, "Tunnel");
11839 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11840         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11841                                  mac, "mac");
11842 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11843         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11844                               mac_addr_byte_mask, UINT8);
11845 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11846         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11847                                  tunnel_type, "tunnel-type");
11848 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11849         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11850                               tunnel_type_mask, UINT8);
11851 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11853                                  tunnel_id, "tunnel-id");
11854 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11855         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11856                               tunnel_id_mask, UINT32);
11857
11858 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11859         .f = cmd_flow_director_mask_parsed,
11860         .data = NULL,
11861         .help_str = "flow_director_mask ... : "
11862                 "Set IP mode flow director's mask on NIC",
11863         .tokens = {
11864                 (void *)&cmd_flow_director_mask,
11865                 (void *)&cmd_flow_director_mask_port_id,
11866                 (void *)&cmd_flow_director_mask_mode,
11867                 (void *)&cmd_flow_director_mask_mode_ip,
11868                 (void *)&cmd_flow_director_mask_vlan,
11869                 (void *)&cmd_flow_director_mask_vlan_value,
11870                 (void *)&cmd_flow_director_mask_src,
11871                 (void *)&cmd_flow_director_mask_ipv4_src,
11872                 (void *)&cmd_flow_director_mask_ipv6_src,
11873                 (void *)&cmd_flow_director_mask_port_src,
11874                 (void *)&cmd_flow_director_mask_dst,
11875                 (void *)&cmd_flow_director_mask_ipv4_dst,
11876                 (void *)&cmd_flow_director_mask_ipv6_dst,
11877                 (void *)&cmd_flow_director_mask_port_dst,
11878                 NULL,
11879         },
11880 };
11881
11882 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11883         .f = cmd_flow_director_mask_parsed,
11884         .data = NULL,
11885         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11886                 "flow director's mask on NIC",
11887         .tokens = {
11888                 (void *)&cmd_flow_director_mask,
11889                 (void *)&cmd_flow_director_mask_port_id,
11890                 (void *)&cmd_flow_director_mask_mode,
11891                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11892                 (void *)&cmd_flow_director_mask_vlan,
11893                 (void *)&cmd_flow_director_mask_vlan_value,
11894                 NULL,
11895         },
11896 };
11897
11898 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11899         .f = cmd_flow_director_mask_parsed,
11900         .data = NULL,
11901         .help_str = "flow_director_mask ... : Set tunnel mode "
11902                 "flow director's mask on NIC",
11903         .tokens = {
11904                 (void *)&cmd_flow_director_mask,
11905                 (void *)&cmd_flow_director_mask_port_id,
11906                 (void *)&cmd_flow_director_mask_mode,
11907                 (void *)&cmd_flow_director_mask_mode_tunnel,
11908                 (void *)&cmd_flow_director_mask_vlan,
11909                 (void *)&cmd_flow_director_mask_vlan_value,
11910                 (void *)&cmd_flow_director_mask_mac,
11911                 (void *)&cmd_flow_director_mask_mac_value,
11912                 (void *)&cmd_flow_director_mask_tunnel_type,
11913                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11914                 (void *)&cmd_flow_director_mask_tunnel_id,
11915                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11916                 NULL,
11917         },
11918 };
11919
11920 /* *** deal with flow director mask on flexible payload *** */
11921 struct cmd_flow_director_flex_mask_result {
11922         cmdline_fixed_string_t flow_director_flexmask;
11923         portid_t port_id;
11924         cmdline_fixed_string_t flow;
11925         cmdline_fixed_string_t flow_type;
11926         cmdline_fixed_string_t mask;
11927 };
11928
11929 static void
11930 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11931                           __rte_unused struct cmdline *cl,
11932                           __rte_unused void *data)
11933 {
11934         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11935         struct rte_eth_fdir_info fdir_info;
11936         struct rte_eth_fdir_flex_mask flex_mask;
11937         struct rte_port *port;
11938         uint64_t flow_type_mask;
11939         uint16_t i;
11940         int ret;
11941
11942         port = &ports[res->port_id];
11943         /** Check if the port is not started **/
11944         if (port->port_status != RTE_PORT_STOPPED) {
11945                 printf("Please stop port %d first\n", res->port_id);
11946                 return;
11947         }
11948
11949         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11950         ret = parse_flexbytes(res->mask,
11951                         flex_mask.mask,
11952                         RTE_ETH_FDIR_MAX_FLEXLEN);
11953         if (ret < 0) {
11954                 printf("error: Cannot parse mask input.\n");
11955                 return;
11956         }
11957
11958         memset(&fdir_info, 0, sizeof(fdir_info));
11959         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11960                                 RTE_ETH_FILTER_INFO, &fdir_info);
11961         if (ret < 0) {
11962                 printf("Cannot get FDir filter info\n");
11963                 return;
11964         }
11965
11966         if (!strcmp(res->flow_type, "none")) {
11967                 /* means don't specify the flow type */
11968                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11969                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11970                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11971                                0, sizeof(struct rte_eth_fdir_flex_mask));
11972                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11973                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11974                                  &flex_mask,
11975                                  sizeof(struct rte_eth_fdir_flex_mask));
11976                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11977                 return;
11978         }
11979         flow_type_mask = fdir_info.flow_types_mask[0];
11980         if (!strcmp(res->flow_type, "all")) {
11981                 if (!flow_type_mask) {
11982                         printf("No flow type supported\n");
11983                         return;
11984                 }
11985                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11986                         if (flow_type_mask & (1ULL << i)) {
11987                                 flex_mask.flow_type = i;
11988                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11989                         }
11990                 }
11991                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11992                 return;
11993         }
11994         flex_mask.flow_type = str2flowtype(res->flow_type);
11995         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11996                 printf("Flow type %s not supported on port %d\n",
11997                                 res->flow_type, res->port_id);
11998                 return;
11999         }
12000         fdir_set_flex_mask(res->port_id, &flex_mask);
12001         cmd_reconfig_device_queue(res->port_id, 1, 1);
12002 }
12003
12004 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12005         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12006                                  flow_director_flexmask,
12007                                  "flow_director_flex_mask");
12008 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12009         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12010                               port_id, UINT16);
12011 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12012         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12013                                  flow, "flow");
12014 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12015         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12016                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12017                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12018 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12019         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12020                                  mask, NULL);
12021
12022 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12023         .f = cmd_flow_director_flex_mask_parsed,
12024         .data = NULL,
12025         .help_str = "flow_director_flex_mask ... : "
12026                 "Set flow director's flex mask on NIC",
12027         .tokens = {
12028                 (void *)&cmd_flow_director_flexmask,
12029                 (void *)&cmd_flow_director_flexmask_port_id,
12030                 (void *)&cmd_flow_director_flexmask_flow,
12031                 (void *)&cmd_flow_director_flexmask_flow_type,
12032                 (void *)&cmd_flow_director_flexmask_mask,
12033                 NULL,
12034         },
12035 };
12036
12037 /* *** deal with flow director flexible payload configuration *** */
12038 struct cmd_flow_director_flexpayload_result {
12039         cmdline_fixed_string_t flow_director_flexpayload;
12040         portid_t port_id;
12041         cmdline_fixed_string_t payload_layer;
12042         cmdline_fixed_string_t payload_cfg;
12043 };
12044
12045 static inline int
12046 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12047 {
12048         char s[256];
12049         const char *p, *p0 = q_arg;
12050         char *end;
12051         unsigned long int_fld;
12052         char *str_fld[max_num];
12053         int i;
12054         unsigned size;
12055         int ret = -1;
12056
12057         p = strchr(p0, '(');
12058         if (p == NULL)
12059                 return -1;
12060         ++p;
12061         p0 = strchr(p, ')');
12062         if (p0 == NULL)
12063                 return -1;
12064
12065         size = p0 - p;
12066         if (size >= sizeof(s))
12067                 return -1;
12068
12069         snprintf(s, sizeof(s), "%.*s", size, p);
12070         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12071         if (ret < 0 || ret > max_num)
12072                 return -1;
12073         for (i = 0; i < ret; i++) {
12074                 errno = 0;
12075                 int_fld = strtoul(str_fld[i], &end, 0);
12076                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12077                         return -1;
12078                 offsets[i] = (uint16_t)int_fld;
12079         }
12080         return ret;
12081 }
12082
12083 static void
12084 cmd_flow_director_flxpld_parsed(void *parsed_result,
12085                           __rte_unused struct cmdline *cl,
12086                           __rte_unused void *data)
12087 {
12088         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12089         struct rte_eth_flex_payload_cfg flex_cfg;
12090         struct rte_port *port;
12091         int ret = 0;
12092
12093         port = &ports[res->port_id];
12094         /** Check if the port is not started **/
12095         if (port->port_status != RTE_PORT_STOPPED) {
12096                 printf("Please stop port %d first\n", res->port_id);
12097                 return;
12098         }
12099
12100         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12101
12102         if (!strcmp(res->payload_layer, "raw"))
12103                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12104         else if (!strcmp(res->payload_layer, "l2"))
12105                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12106         else if (!strcmp(res->payload_layer, "l3"))
12107                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12108         else if (!strcmp(res->payload_layer, "l4"))
12109                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12110
12111         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12112                             RTE_ETH_FDIR_MAX_FLEXLEN);
12113         if (ret < 0) {
12114                 printf("error: Cannot parse flex payload input.\n");
12115                 return;
12116         }
12117
12118         fdir_set_flex_payload(res->port_id, &flex_cfg);
12119         cmd_reconfig_device_queue(res->port_id, 1, 1);
12120 }
12121
12122 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12124                                  flow_director_flexpayload,
12125                                  "flow_director_flex_payload");
12126 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12127         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12128                               port_id, UINT16);
12129 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12130         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12131                                  payload_layer, "raw#l2#l3#l4");
12132 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12133         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12134                                  payload_cfg, NULL);
12135
12136 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12137         .f = cmd_flow_director_flxpld_parsed,
12138         .data = NULL,
12139         .help_str = "flow_director_flexpayload ... : "
12140                 "Set flow director's flex payload on NIC",
12141         .tokens = {
12142                 (void *)&cmd_flow_director_flexpayload,
12143                 (void *)&cmd_flow_director_flexpayload_port_id,
12144                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12145                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12146                 NULL,
12147         },
12148 };
12149
12150 /* Generic flow interface command. */
12151 extern cmdline_parse_inst_t cmd_flow;
12152
12153 /* *** Classification Filters Control *** */
12154 /* *** Get symmetric hash enable per port *** */
12155 struct cmd_get_sym_hash_ena_per_port_result {
12156         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12157         portid_t port_id;
12158 };
12159
12160 static void
12161 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12162                                  __rte_unused struct cmdline *cl,
12163                                  __rte_unused void *data)
12164 {
12165         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12166         struct rte_eth_hash_filter_info info;
12167         int ret;
12168
12169         if (rte_eth_dev_filter_supported(res->port_id,
12170                                 RTE_ETH_FILTER_HASH) < 0) {
12171                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12172                                                         res->port_id);
12173                 return;
12174         }
12175
12176         memset(&info, 0, sizeof(info));
12177         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12178         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12179                                                 RTE_ETH_FILTER_GET, &info);
12180
12181         if (ret < 0) {
12182                 printf("Cannot get symmetric hash enable per port "
12183                                         "on port %u\n", res->port_id);
12184                 return;
12185         }
12186
12187         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12188                                 "enabled" : "disabled", res->port_id);
12189 }
12190
12191 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12192         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12193                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12194 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12195         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12196                 port_id, UINT16);
12197
12198 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12199         .f = cmd_get_sym_hash_per_port_parsed,
12200         .data = NULL,
12201         .help_str = "get_sym_hash_ena_per_port <port_id>",
12202         .tokens = {
12203                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12204                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12205                 NULL,
12206         },
12207 };
12208
12209 /* *** Set symmetric hash enable per port *** */
12210 struct cmd_set_sym_hash_ena_per_port_result {
12211         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12212         cmdline_fixed_string_t enable;
12213         portid_t port_id;
12214 };
12215
12216 static void
12217 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12218                                  __rte_unused struct cmdline *cl,
12219                                  __rte_unused void *data)
12220 {
12221         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12222         struct rte_eth_hash_filter_info info;
12223         int ret;
12224
12225         if (rte_eth_dev_filter_supported(res->port_id,
12226                                 RTE_ETH_FILTER_HASH) < 0) {
12227                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12228                                                         res->port_id);
12229                 return;
12230         }
12231
12232         memset(&info, 0, sizeof(info));
12233         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12234         if (!strcmp(res->enable, "enable"))
12235                 info.info.enable = 1;
12236         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12237                                         RTE_ETH_FILTER_SET, &info);
12238         if (ret < 0) {
12239                 printf("Cannot set symmetric hash enable per port on "
12240                                         "port %u\n", res->port_id);
12241                 return;
12242         }
12243         printf("Symmetric hash has been set to %s on port %u\n",
12244                                         res->enable, res->port_id);
12245 }
12246
12247 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12248         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12249                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12250 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12251         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12252                 port_id, UINT16);
12253 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12254         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12255                 enable, "enable#disable");
12256
12257 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12258         .f = cmd_set_sym_hash_per_port_parsed,
12259         .data = NULL,
12260         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12261         .tokens = {
12262                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12263                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12264                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12265                 NULL,
12266         },
12267 };
12268
12269 /* Get global config of hash function */
12270 struct cmd_get_hash_global_config_result {
12271         cmdline_fixed_string_t get_hash_global_config;
12272         portid_t port_id;
12273 };
12274
12275 static char *
12276 flowtype_to_str(uint16_t ftype)
12277 {
12278         uint16_t i;
12279         static struct {
12280                 char str[16];
12281                 uint16_t ftype;
12282         } ftype_table[] = {
12283                 {"ipv4", RTE_ETH_FLOW_IPV4},
12284                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12285                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12286                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12287                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12288                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12289                 {"ipv6", RTE_ETH_FLOW_IPV6},
12290                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12291                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12292                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12293                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12294                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12295                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12296                 {"port", RTE_ETH_FLOW_PORT},
12297                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12298                 {"geneve", RTE_ETH_FLOW_GENEVE},
12299                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12300                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12301         };
12302
12303         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12304                 if (ftype_table[i].ftype == ftype)
12305                         return ftype_table[i].str;
12306         }
12307
12308         return NULL;
12309 }
12310
12311 static void
12312 cmd_get_hash_global_config_parsed(void *parsed_result,
12313                                   __rte_unused struct cmdline *cl,
12314                                   __rte_unused void *data)
12315 {
12316         struct cmd_get_hash_global_config_result *res = parsed_result;
12317         struct rte_eth_hash_filter_info info;
12318         uint32_t idx, offset;
12319         uint16_t i;
12320         char *str;
12321         int ret;
12322
12323         if (rte_eth_dev_filter_supported(res->port_id,
12324                         RTE_ETH_FILTER_HASH) < 0) {
12325                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12326                                                         res->port_id);
12327                 return;
12328         }
12329
12330         memset(&info, 0, sizeof(info));
12331         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12332         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12333                                         RTE_ETH_FILTER_GET, &info);
12334         if (ret < 0) {
12335                 printf("Cannot get hash global configurations by port %d\n",
12336                                                         res->port_id);
12337                 return;
12338         }
12339
12340         switch (info.info.global_conf.hash_func) {
12341         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12342                 printf("Hash function is Toeplitz\n");
12343                 break;
12344         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12345                 printf("Hash function is Simple XOR\n");
12346                 break;
12347         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12348                 printf("Hash function is Symmetric Toeplitz\n");
12349                 break;
12350         default:
12351                 printf("Unknown hash function\n");
12352                 break;
12353         }
12354
12355         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12356                 idx = i / UINT64_BIT;
12357                 offset = i % UINT64_BIT;
12358                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12359                                                 (1ULL << offset)))
12360                         continue;
12361                 str = flowtype_to_str(i);
12362                 if (!str)
12363                         continue;
12364                 printf("Symmetric hash is %s globally for flow type %s "
12365                                                         "by port %d\n",
12366                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12367                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12368                                                         res->port_id);
12369         }
12370 }
12371
12372 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12373         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12374                 get_hash_global_config, "get_hash_global_config");
12375 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12376         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12377                 port_id, UINT16);
12378
12379 cmdline_parse_inst_t cmd_get_hash_global_config = {
12380         .f = cmd_get_hash_global_config_parsed,
12381         .data = NULL,
12382         .help_str = "get_hash_global_config <port_id>",
12383         .tokens = {
12384                 (void *)&cmd_get_hash_global_config_all,
12385                 (void *)&cmd_get_hash_global_config_port_id,
12386                 NULL,
12387         },
12388 };
12389
12390 /* Set global config of hash function */
12391 struct cmd_set_hash_global_config_result {
12392         cmdline_fixed_string_t set_hash_global_config;
12393         portid_t port_id;
12394         cmdline_fixed_string_t hash_func;
12395         cmdline_fixed_string_t flow_type;
12396         cmdline_fixed_string_t enable;
12397 };
12398
12399 static void
12400 cmd_set_hash_global_config_parsed(void *parsed_result,
12401                                   __rte_unused struct cmdline *cl,
12402                                   __rte_unused void *data)
12403 {
12404         struct cmd_set_hash_global_config_result *res = parsed_result;
12405         struct rte_eth_hash_filter_info info;
12406         uint32_t ftype, idx, offset;
12407         int ret;
12408
12409         if (rte_eth_dev_filter_supported(res->port_id,
12410                                 RTE_ETH_FILTER_HASH) < 0) {
12411                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12412                                                         res->port_id);
12413                 return;
12414         }
12415         memset(&info, 0, sizeof(info));
12416         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12417         if (!strcmp(res->hash_func, "toeplitz"))
12418                 info.info.global_conf.hash_func =
12419                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12420         else if (!strcmp(res->hash_func, "simple_xor"))
12421                 info.info.global_conf.hash_func =
12422                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12423         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12424                 info.info.global_conf.hash_func =
12425                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12426         else if (!strcmp(res->hash_func, "default"))
12427                 info.info.global_conf.hash_func =
12428                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12429
12430         ftype = str2flowtype(res->flow_type);
12431         idx = ftype / UINT64_BIT;
12432         offset = ftype % UINT64_BIT;
12433         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12434         if (!strcmp(res->enable, "enable"))
12435                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12436                                                 (1ULL << offset);
12437         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12438                                         RTE_ETH_FILTER_SET, &info);
12439         if (ret < 0)
12440                 printf("Cannot set global hash configurations by port %d\n",
12441                                                         res->port_id);
12442         else
12443                 printf("Global hash configurations have been set "
12444                         "successfully by port %d\n", res->port_id);
12445 }
12446
12447 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12448         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12449                 set_hash_global_config, "set_hash_global_config");
12450 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12451         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12452                 port_id, UINT16);
12453 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12454         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12455                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12456 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12457         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12458                 flow_type,
12459                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12460                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12461 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12462         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12463                 enable, "enable#disable");
12464
12465 cmdline_parse_inst_t cmd_set_hash_global_config = {
12466         .f = cmd_set_hash_global_config_parsed,
12467         .data = NULL,
12468         .help_str = "set_hash_global_config <port_id> "
12469                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12470                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12471                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12472                 "l2_payload enable|disable",
12473         .tokens = {
12474                 (void *)&cmd_set_hash_global_config_all,
12475                 (void *)&cmd_set_hash_global_config_port_id,
12476                 (void *)&cmd_set_hash_global_config_hash_func,
12477                 (void *)&cmd_set_hash_global_config_flow_type,
12478                 (void *)&cmd_set_hash_global_config_enable,
12479                 NULL,
12480         },
12481 };
12482
12483 /* Set hash input set */
12484 struct cmd_set_hash_input_set_result {
12485         cmdline_fixed_string_t set_hash_input_set;
12486         portid_t port_id;
12487         cmdline_fixed_string_t flow_type;
12488         cmdline_fixed_string_t inset_field;
12489         cmdline_fixed_string_t select;
12490 };
12491
12492 static enum rte_eth_input_set_field
12493 str2inset(char *string)
12494 {
12495         uint16_t i;
12496
12497         static const struct {
12498                 char str[32];
12499                 enum rte_eth_input_set_field inset;
12500         } inset_table[] = {
12501                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12502                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12503                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12504                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12505                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12506                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12507                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12508                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12509                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12510                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12511                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12512                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12513                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12514                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12515                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12516                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12517                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12518                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12519                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12520                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12521                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12522                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12523                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12524                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12525                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12526                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12527                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12528                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12529                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12530                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12531                 {"none", RTE_ETH_INPUT_SET_NONE},
12532         };
12533
12534         for (i = 0; i < RTE_DIM(inset_table); i++) {
12535                 if (!strcmp(string, inset_table[i].str))
12536                         return inset_table[i].inset;
12537         }
12538
12539         return RTE_ETH_INPUT_SET_UNKNOWN;
12540 }
12541
12542 static void
12543 cmd_set_hash_input_set_parsed(void *parsed_result,
12544                               __rte_unused struct cmdline *cl,
12545                               __rte_unused void *data)
12546 {
12547         struct cmd_set_hash_input_set_result *res = parsed_result;
12548         struct rte_eth_hash_filter_info info;
12549
12550         memset(&info, 0, sizeof(info));
12551         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12552         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12553         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12554         info.info.input_set_conf.inset_size = 1;
12555         if (!strcmp(res->select, "select"))
12556                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12557         else if (!strcmp(res->select, "add"))
12558                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12559         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12560                                 RTE_ETH_FILTER_SET, &info);
12561 }
12562
12563 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12564         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12565                 set_hash_input_set, "set_hash_input_set");
12566 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12567         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12568                 port_id, UINT16);
12569 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12570         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12571                 flow_type, NULL);
12572 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12573         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12574                 inset_field,
12575                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12576                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12577                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12578                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12579                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12580                 "fld-8th#none");
12581 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12582         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12583                 select, "select#add");
12584
12585 cmdline_parse_inst_t cmd_set_hash_input_set = {
12586         .f = cmd_set_hash_input_set_parsed,
12587         .data = NULL,
12588         .help_str = "set_hash_input_set <port_id> "
12589         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12590         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12591         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12592         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12593         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12594         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12595         "fld-7th|fld-8th|none select|add",
12596         .tokens = {
12597                 (void *)&cmd_set_hash_input_set_cmd,
12598                 (void *)&cmd_set_hash_input_set_port_id,
12599                 (void *)&cmd_set_hash_input_set_flow_type,
12600                 (void *)&cmd_set_hash_input_set_field,
12601                 (void *)&cmd_set_hash_input_set_select,
12602                 NULL,
12603         },
12604 };
12605
12606 /* Set flow director input set */
12607 struct cmd_set_fdir_input_set_result {
12608         cmdline_fixed_string_t set_fdir_input_set;
12609         portid_t port_id;
12610         cmdline_fixed_string_t flow_type;
12611         cmdline_fixed_string_t inset_field;
12612         cmdline_fixed_string_t select;
12613 };
12614
12615 static void
12616 cmd_set_fdir_input_set_parsed(void *parsed_result,
12617         __rte_unused struct cmdline *cl,
12618         __rte_unused void *data)
12619 {
12620         struct cmd_set_fdir_input_set_result *res = parsed_result;
12621         struct rte_eth_fdir_filter_info info;
12622
12623         memset(&info, 0, sizeof(info));
12624         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12625         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12626         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12627         info.info.input_set_conf.inset_size = 1;
12628         if (!strcmp(res->select, "select"))
12629                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12630         else if (!strcmp(res->select, "add"))
12631                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12632         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12633                 RTE_ETH_FILTER_SET, &info);
12634 }
12635
12636 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12637         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12638         set_fdir_input_set, "set_fdir_input_set");
12639 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12640         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12641         port_id, UINT16);
12642 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12643         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12644         flow_type,
12645         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12646         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12647 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12648         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12649         inset_field,
12650         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12651         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12652         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12653         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12654         "sctp-veri-tag#none");
12655 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12656         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12657         select, "select#add");
12658
12659 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12660         .f = cmd_set_fdir_input_set_parsed,
12661         .data = NULL,
12662         .help_str = "set_fdir_input_set <port_id> "
12663         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12664         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12665         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12666         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12667         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12668         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12669         "sctp-veri-tag|none select|add",
12670         .tokens = {
12671                 (void *)&cmd_set_fdir_input_set_cmd,
12672                 (void *)&cmd_set_fdir_input_set_port_id,
12673                 (void *)&cmd_set_fdir_input_set_flow_type,
12674                 (void *)&cmd_set_fdir_input_set_field,
12675                 (void *)&cmd_set_fdir_input_set_select,
12676                 NULL,
12677         },
12678 };
12679
12680 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12681 struct cmd_mcast_addr_result {
12682         cmdline_fixed_string_t mcast_addr_cmd;
12683         cmdline_fixed_string_t what;
12684         uint16_t port_num;
12685         struct rte_ether_addr mc_addr;
12686 };
12687
12688 static void cmd_mcast_addr_parsed(void *parsed_result,
12689                 __rte_unused struct cmdline *cl,
12690                 __rte_unused void *data)
12691 {
12692         struct cmd_mcast_addr_result *res = parsed_result;
12693
12694         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12695                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12696                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12697                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12698                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12699                 return;
12700         }
12701         if (strcmp(res->what, "add") == 0)
12702                 mcast_addr_add(res->port_num, &res->mc_addr);
12703         else
12704                 mcast_addr_remove(res->port_num, &res->mc_addr);
12705 }
12706
12707 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12708         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12709                                  mcast_addr_cmd, "mcast_addr");
12710 cmdline_parse_token_string_t cmd_mcast_addr_what =
12711         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12712                                  "add#remove");
12713 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12714         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12715 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12716         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12717
12718 cmdline_parse_inst_t cmd_mcast_addr = {
12719         .f = cmd_mcast_addr_parsed,
12720         .data = (void *)0,
12721         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12722                 "Add/Remove multicast MAC address on port_id",
12723         .tokens = {
12724                 (void *)&cmd_mcast_addr_cmd,
12725                 (void *)&cmd_mcast_addr_what,
12726                 (void *)&cmd_mcast_addr_portnum,
12727                 (void *)&cmd_mcast_addr_addr,
12728                 NULL,
12729         },
12730 };
12731
12732 /* l2 tunnel config
12733  * only support E-tag now.
12734  */
12735
12736 /* Ether type config */
12737 struct cmd_config_l2_tunnel_eth_type_result {
12738         cmdline_fixed_string_t port;
12739         cmdline_fixed_string_t config;
12740         cmdline_fixed_string_t all;
12741         portid_t id;
12742         cmdline_fixed_string_t l2_tunnel;
12743         cmdline_fixed_string_t l2_tunnel_type;
12744         cmdline_fixed_string_t eth_type;
12745         uint16_t eth_type_val;
12746 };
12747
12748 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_config_l2_tunnel_eth_type_result,
12751                  port, "port");
12752 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_config_l2_tunnel_eth_type_result,
12755                  config, "config");
12756 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_config_l2_tunnel_eth_type_result,
12759                  all, "all");
12760 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12761         TOKEN_NUM_INITIALIZER
12762                 (struct cmd_config_l2_tunnel_eth_type_result,
12763                  id, UINT16);
12764 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_config_l2_tunnel_eth_type_result,
12767                  l2_tunnel, "l2-tunnel");
12768 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_config_l2_tunnel_eth_type_result,
12771                  l2_tunnel_type, "E-tag");
12772 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_config_l2_tunnel_eth_type_result,
12775                  eth_type, "ether-type");
12776 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12777         TOKEN_NUM_INITIALIZER
12778                 (struct cmd_config_l2_tunnel_eth_type_result,
12779                  eth_type_val, UINT16);
12780
12781 static enum rte_eth_tunnel_type
12782 str2fdir_l2_tunnel_type(char *string)
12783 {
12784         uint32_t i = 0;
12785
12786         static const struct {
12787                 char str[32];
12788                 enum rte_eth_tunnel_type type;
12789         } l2_tunnel_type_str[] = {
12790                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12791         };
12792
12793         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12794                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12795                         return l2_tunnel_type_str[i].type;
12796         }
12797         return RTE_TUNNEL_TYPE_NONE;
12798 }
12799
12800 /* ether type config for all ports */
12801 static void
12802 cmd_config_l2_tunnel_eth_type_all_parsed
12803         (void *parsed_result,
12804          __rte_unused struct cmdline *cl,
12805          __rte_unused void *data)
12806 {
12807         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12808         struct rte_eth_l2_tunnel_conf entry;
12809         portid_t pid;
12810
12811         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12812         entry.ether_type = res->eth_type_val;
12813
12814         RTE_ETH_FOREACH_DEV(pid) {
12815                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12816         }
12817 }
12818
12819 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12820         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12821         .data = NULL,
12822         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12823         .tokens = {
12824                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12825                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12826                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12827                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12828                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12829                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12830                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12831                 NULL,
12832         },
12833 };
12834
12835 /* ether type config for a specific port */
12836 static void
12837 cmd_config_l2_tunnel_eth_type_specific_parsed(
12838         void *parsed_result,
12839         __rte_unused struct cmdline *cl,
12840         __rte_unused void *data)
12841 {
12842         struct cmd_config_l2_tunnel_eth_type_result *res =
12843                  parsed_result;
12844         struct rte_eth_l2_tunnel_conf entry;
12845
12846         if (port_id_is_invalid(res->id, ENABLED_WARN))
12847                 return;
12848
12849         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12850         entry.ether_type = res->eth_type_val;
12851
12852         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12853 }
12854
12855 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12856         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12857         .data = NULL,
12858         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12859         .tokens = {
12860                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12861                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12862                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12863                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12864                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12865                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12866                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12867                 NULL,
12868         },
12869 };
12870
12871 /* Enable/disable l2 tunnel */
12872 struct cmd_config_l2_tunnel_en_dis_result {
12873         cmdline_fixed_string_t port;
12874         cmdline_fixed_string_t config;
12875         cmdline_fixed_string_t all;
12876         portid_t id;
12877         cmdline_fixed_string_t l2_tunnel;
12878         cmdline_fixed_string_t l2_tunnel_type;
12879         cmdline_fixed_string_t en_dis;
12880 };
12881
12882 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12883         TOKEN_STRING_INITIALIZER
12884                 (struct cmd_config_l2_tunnel_en_dis_result,
12885                  port, "port");
12886 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12887         TOKEN_STRING_INITIALIZER
12888                 (struct cmd_config_l2_tunnel_en_dis_result,
12889                  config, "config");
12890 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12891         TOKEN_STRING_INITIALIZER
12892                 (struct cmd_config_l2_tunnel_en_dis_result,
12893                  all, "all");
12894 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12895         TOKEN_NUM_INITIALIZER
12896                 (struct cmd_config_l2_tunnel_en_dis_result,
12897                  id, UINT16);
12898 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12899         TOKEN_STRING_INITIALIZER
12900                 (struct cmd_config_l2_tunnel_en_dis_result,
12901                  l2_tunnel, "l2-tunnel");
12902 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12903         TOKEN_STRING_INITIALIZER
12904                 (struct cmd_config_l2_tunnel_en_dis_result,
12905                  l2_tunnel_type, "E-tag");
12906 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12907         TOKEN_STRING_INITIALIZER
12908                 (struct cmd_config_l2_tunnel_en_dis_result,
12909                  en_dis, "enable#disable");
12910
12911 /* enable/disable l2 tunnel for all ports */
12912 static void
12913 cmd_config_l2_tunnel_en_dis_all_parsed(
12914         void *parsed_result,
12915         __rte_unused struct cmdline *cl,
12916         __rte_unused void *data)
12917 {
12918         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12919         struct rte_eth_l2_tunnel_conf entry;
12920         portid_t pid;
12921         uint8_t en;
12922
12923         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12924
12925         if (!strcmp("enable", res->en_dis))
12926                 en = 1;
12927         else
12928                 en = 0;
12929
12930         RTE_ETH_FOREACH_DEV(pid) {
12931                 rte_eth_dev_l2_tunnel_offload_set(pid,
12932                                                   &entry,
12933                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12934                                                   en);
12935         }
12936 }
12937
12938 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12939         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12940         .data = NULL,
12941         .help_str = "port config all l2-tunnel E-tag enable|disable",
12942         .tokens = {
12943                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12944                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12945                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12946                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12947                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12948                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12949                 NULL,
12950         },
12951 };
12952
12953 /* enable/disable l2 tunnel for a port */
12954 static void
12955 cmd_config_l2_tunnel_en_dis_specific_parsed(
12956         void *parsed_result,
12957         __rte_unused struct cmdline *cl,
12958         __rte_unused void *data)
12959 {
12960         struct cmd_config_l2_tunnel_en_dis_result *res =
12961                 parsed_result;
12962         struct rte_eth_l2_tunnel_conf entry;
12963
12964         if (port_id_is_invalid(res->id, ENABLED_WARN))
12965                 return;
12966
12967         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12968
12969         if (!strcmp("enable", res->en_dis))
12970                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12971                                                   &entry,
12972                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12973                                                   1);
12974         else
12975                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12976                                                   &entry,
12977                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12978                                                   0);
12979 }
12980
12981 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12982         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12983         .data = NULL,
12984         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12985         .tokens = {
12986                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12987                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12988                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12989                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12990                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12991                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12992                 NULL,
12993         },
12994 };
12995
12996 /* E-tag configuration */
12997
12998 /* Common result structure for all E-tag configuration */
12999 struct cmd_config_e_tag_result {
13000         cmdline_fixed_string_t e_tag;
13001         cmdline_fixed_string_t set;
13002         cmdline_fixed_string_t insertion;
13003         cmdline_fixed_string_t stripping;
13004         cmdline_fixed_string_t forwarding;
13005         cmdline_fixed_string_t filter;
13006         cmdline_fixed_string_t add;
13007         cmdline_fixed_string_t del;
13008         cmdline_fixed_string_t on;
13009         cmdline_fixed_string_t off;
13010         cmdline_fixed_string_t on_off;
13011         cmdline_fixed_string_t port_tag_id;
13012         uint32_t port_tag_id_val;
13013         cmdline_fixed_string_t e_tag_id;
13014         uint16_t e_tag_id_val;
13015         cmdline_fixed_string_t dst_pool;
13016         uint8_t dst_pool_val;
13017         cmdline_fixed_string_t port;
13018         portid_t port_id;
13019         cmdline_fixed_string_t vf;
13020         uint8_t vf_id;
13021 };
13022
13023 /* Common CLI fields for all E-tag configuration */
13024 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13025         TOKEN_STRING_INITIALIZER
13026                 (struct cmd_config_e_tag_result,
13027                  e_tag, "E-tag");
13028 cmdline_parse_token_string_t cmd_config_e_tag_set =
13029         TOKEN_STRING_INITIALIZER
13030                 (struct cmd_config_e_tag_result,
13031                  set, "set");
13032 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13033         TOKEN_STRING_INITIALIZER
13034                 (struct cmd_config_e_tag_result,
13035                  insertion, "insertion");
13036 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_config_e_tag_result,
13039                  stripping, "stripping");
13040 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_config_e_tag_result,
13043                  forwarding, "forwarding");
13044 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_config_e_tag_result,
13047                  filter, "filter");
13048 cmdline_parse_token_string_t cmd_config_e_tag_add =
13049         TOKEN_STRING_INITIALIZER
13050                 (struct cmd_config_e_tag_result,
13051                  add, "add");
13052 cmdline_parse_token_string_t cmd_config_e_tag_del =
13053         TOKEN_STRING_INITIALIZER
13054                 (struct cmd_config_e_tag_result,
13055                  del, "del");
13056 cmdline_parse_token_string_t cmd_config_e_tag_on =
13057         TOKEN_STRING_INITIALIZER
13058                 (struct cmd_config_e_tag_result,
13059                  on, "on");
13060 cmdline_parse_token_string_t cmd_config_e_tag_off =
13061         TOKEN_STRING_INITIALIZER
13062                 (struct cmd_config_e_tag_result,
13063                  off, "off");
13064 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13065         TOKEN_STRING_INITIALIZER
13066                 (struct cmd_config_e_tag_result,
13067                  on_off, "on#off");
13068 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_config_e_tag_result,
13071                  port_tag_id, "port-tag-id");
13072 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13073         TOKEN_NUM_INITIALIZER
13074                 (struct cmd_config_e_tag_result,
13075                  port_tag_id_val, UINT32);
13076 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_config_e_tag_result,
13079                  e_tag_id, "e-tag-id");
13080 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13081         TOKEN_NUM_INITIALIZER
13082                 (struct cmd_config_e_tag_result,
13083                  e_tag_id_val, UINT16);
13084 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_config_e_tag_result,
13087                  dst_pool, "dst-pool");
13088 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13089         TOKEN_NUM_INITIALIZER
13090                 (struct cmd_config_e_tag_result,
13091                  dst_pool_val, UINT8);
13092 cmdline_parse_token_string_t cmd_config_e_tag_port =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_config_e_tag_result,
13095                  port, "port");
13096 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13097         TOKEN_NUM_INITIALIZER
13098                 (struct cmd_config_e_tag_result,
13099                  port_id, UINT16);
13100 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13101         TOKEN_STRING_INITIALIZER
13102                 (struct cmd_config_e_tag_result,
13103                  vf, "vf");
13104 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13105         TOKEN_NUM_INITIALIZER
13106                 (struct cmd_config_e_tag_result,
13107                  vf_id, UINT8);
13108
13109 /* E-tag insertion configuration */
13110 static void
13111 cmd_config_e_tag_insertion_en_parsed(
13112         void *parsed_result,
13113         __rte_unused struct cmdline *cl,
13114         __rte_unused void *data)
13115 {
13116         struct cmd_config_e_tag_result *res =
13117                 parsed_result;
13118         struct rte_eth_l2_tunnel_conf entry;
13119
13120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13121                 return;
13122
13123         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13124         entry.tunnel_id = res->port_tag_id_val;
13125         entry.vf_id = res->vf_id;
13126         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13127                                           &entry,
13128                                           ETH_L2_TUNNEL_INSERTION_MASK,
13129                                           1);
13130 }
13131
13132 static void
13133 cmd_config_e_tag_insertion_dis_parsed(
13134         void *parsed_result,
13135         __rte_unused struct cmdline *cl,
13136         __rte_unused void *data)
13137 {
13138         struct cmd_config_e_tag_result *res =
13139                 parsed_result;
13140         struct rte_eth_l2_tunnel_conf entry;
13141
13142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13143                 return;
13144
13145         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13146         entry.vf_id = res->vf_id;
13147
13148         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13149                                           &entry,
13150                                           ETH_L2_TUNNEL_INSERTION_MASK,
13151                                           0);
13152 }
13153
13154 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13155         .f = cmd_config_e_tag_insertion_en_parsed,
13156         .data = NULL,
13157         .help_str = "E-tag ... : E-tag insertion enable",
13158         .tokens = {
13159                 (void *)&cmd_config_e_tag_e_tag,
13160                 (void *)&cmd_config_e_tag_set,
13161                 (void *)&cmd_config_e_tag_insertion,
13162                 (void *)&cmd_config_e_tag_on,
13163                 (void *)&cmd_config_e_tag_port_tag_id,
13164                 (void *)&cmd_config_e_tag_port_tag_id_val,
13165                 (void *)&cmd_config_e_tag_port,
13166                 (void *)&cmd_config_e_tag_port_id,
13167                 (void *)&cmd_config_e_tag_vf,
13168                 (void *)&cmd_config_e_tag_vf_id,
13169                 NULL,
13170         },
13171 };
13172
13173 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13174         .f = cmd_config_e_tag_insertion_dis_parsed,
13175         .data = NULL,
13176         .help_str = "E-tag ... : E-tag insertion disable",
13177         .tokens = {
13178                 (void *)&cmd_config_e_tag_e_tag,
13179                 (void *)&cmd_config_e_tag_set,
13180                 (void *)&cmd_config_e_tag_insertion,
13181                 (void *)&cmd_config_e_tag_off,
13182                 (void *)&cmd_config_e_tag_port,
13183                 (void *)&cmd_config_e_tag_port_id,
13184                 (void *)&cmd_config_e_tag_vf,
13185                 (void *)&cmd_config_e_tag_vf_id,
13186                 NULL,
13187         },
13188 };
13189
13190 /* E-tag stripping configuration */
13191 static void
13192 cmd_config_e_tag_stripping_parsed(
13193         void *parsed_result,
13194         __rte_unused struct cmdline *cl,
13195         __rte_unused void *data)
13196 {
13197         struct cmd_config_e_tag_result *res =
13198                 parsed_result;
13199         struct rte_eth_l2_tunnel_conf entry;
13200
13201         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13202                 return;
13203
13204         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13205
13206         if (!strcmp(res->on_off, "on"))
13207                 rte_eth_dev_l2_tunnel_offload_set
13208                         (res->port_id,
13209                          &entry,
13210                          ETH_L2_TUNNEL_STRIPPING_MASK,
13211                          1);
13212         else
13213                 rte_eth_dev_l2_tunnel_offload_set
13214                         (res->port_id,
13215                          &entry,
13216                          ETH_L2_TUNNEL_STRIPPING_MASK,
13217                          0);
13218 }
13219
13220 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13221         .f = cmd_config_e_tag_stripping_parsed,
13222         .data = NULL,
13223         .help_str = "E-tag ... : E-tag stripping enable/disable",
13224         .tokens = {
13225                 (void *)&cmd_config_e_tag_e_tag,
13226                 (void *)&cmd_config_e_tag_set,
13227                 (void *)&cmd_config_e_tag_stripping,
13228                 (void *)&cmd_config_e_tag_on_off,
13229                 (void *)&cmd_config_e_tag_port,
13230                 (void *)&cmd_config_e_tag_port_id,
13231                 NULL,
13232         },
13233 };
13234
13235 /* E-tag forwarding configuration */
13236 static void
13237 cmd_config_e_tag_forwarding_parsed(
13238         void *parsed_result,
13239         __rte_unused struct cmdline *cl,
13240         __rte_unused void *data)
13241 {
13242         struct cmd_config_e_tag_result *res = parsed_result;
13243         struct rte_eth_l2_tunnel_conf entry;
13244
13245         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13246                 return;
13247
13248         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13249
13250         if (!strcmp(res->on_off, "on"))
13251                 rte_eth_dev_l2_tunnel_offload_set
13252                         (res->port_id,
13253                          &entry,
13254                          ETH_L2_TUNNEL_FORWARDING_MASK,
13255                          1);
13256         else
13257                 rte_eth_dev_l2_tunnel_offload_set
13258                         (res->port_id,
13259                          &entry,
13260                          ETH_L2_TUNNEL_FORWARDING_MASK,
13261                          0);
13262 }
13263
13264 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13265         .f = cmd_config_e_tag_forwarding_parsed,
13266         .data = NULL,
13267         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13268         .tokens = {
13269                 (void *)&cmd_config_e_tag_e_tag,
13270                 (void *)&cmd_config_e_tag_set,
13271                 (void *)&cmd_config_e_tag_forwarding,
13272                 (void *)&cmd_config_e_tag_on_off,
13273                 (void *)&cmd_config_e_tag_port,
13274                 (void *)&cmd_config_e_tag_port_id,
13275                 NULL,
13276         },
13277 };
13278
13279 /* E-tag filter configuration */
13280 static void
13281 cmd_config_e_tag_filter_add_parsed(
13282         void *parsed_result,
13283         __rte_unused struct cmdline *cl,
13284         __rte_unused void *data)
13285 {
13286         struct cmd_config_e_tag_result *res = parsed_result;
13287         struct rte_eth_l2_tunnel_conf entry;
13288         int ret = 0;
13289
13290         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13291                 return;
13292
13293         if (res->e_tag_id_val > 0x3fff) {
13294                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13295                 return;
13296         }
13297
13298         ret = rte_eth_dev_filter_supported(res->port_id,
13299                                            RTE_ETH_FILTER_L2_TUNNEL);
13300         if (ret < 0) {
13301                 printf("E-tag filter is not supported on port %u.\n",
13302                        res->port_id);
13303                 return;
13304         }
13305
13306         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13307         entry.tunnel_id = res->e_tag_id_val;
13308         entry.pool = res->dst_pool_val;
13309
13310         ret = rte_eth_dev_filter_ctrl(res->port_id,
13311                                       RTE_ETH_FILTER_L2_TUNNEL,
13312                                       RTE_ETH_FILTER_ADD,
13313                                       &entry);
13314         if (ret < 0)
13315                 printf("E-tag filter programming error: (%s)\n",
13316                        strerror(-ret));
13317 }
13318
13319 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13320         .f = cmd_config_e_tag_filter_add_parsed,
13321         .data = NULL,
13322         .help_str = "E-tag ... : E-tag filter add",
13323         .tokens = {
13324                 (void *)&cmd_config_e_tag_e_tag,
13325                 (void *)&cmd_config_e_tag_set,
13326                 (void *)&cmd_config_e_tag_filter,
13327                 (void *)&cmd_config_e_tag_add,
13328                 (void *)&cmd_config_e_tag_e_tag_id,
13329                 (void *)&cmd_config_e_tag_e_tag_id_val,
13330                 (void *)&cmd_config_e_tag_dst_pool,
13331                 (void *)&cmd_config_e_tag_dst_pool_val,
13332                 (void *)&cmd_config_e_tag_port,
13333                 (void *)&cmd_config_e_tag_port_id,
13334                 NULL,
13335         },
13336 };
13337
13338 static void
13339 cmd_config_e_tag_filter_del_parsed(
13340         void *parsed_result,
13341         __rte_unused struct cmdline *cl,
13342         __rte_unused void *data)
13343 {
13344         struct cmd_config_e_tag_result *res = parsed_result;
13345         struct rte_eth_l2_tunnel_conf entry;
13346         int ret = 0;
13347
13348         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13349                 return;
13350
13351         if (res->e_tag_id_val > 0x3fff) {
13352                 printf("e-tag-id must be less than 0x3fff.\n");
13353                 return;
13354         }
13355
13356         ret = rte_eth_dev_filter_supported(res->port_id,
13357                                            RTE_ETH_FILTER_L2_TUNNEL);
13358         if (ret < 0) {
13359                 printf("E-tag filter is not supported on port %u.\n",
13360                        res->port_id);
13361                 return;
13362         }
13363
13364         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13365         entry.tunnel_id = res->e_tag_id_val;
13366
13367         ret = rte_eth_dev_filter_ctrl(res->port_id,
13368                                       RTE_ETH_FILTER_L2_TUNNEL,
13369                                       RTE_ETH_FILTER_DELETE,
13370                                       &entry);
13371         if (ret < 0)
13372                 printf("E-tag filter programming error: (%s)\n",
13373                        strerror(-ret));
13374 }
13375
13376 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13377         .f = cmd_config_e_tag_filter_del_parsed,
13378         .data = NULL,
13379         .help_str = "E-tag ... : E-tag filter delete",
13380         .tokens = {
13381                 (void *)&cmd_config_e_tag_e_tag,
13382                 (void *)&cmd_config_e_tag_set,
13383                 (void *)&cmd_config_e_tag_filter,
13384                 (void *)&cmd_config_e_tag_del,
13385                 (void *)&cmd_config_e_tag_e_tag_id,
13386                 (void *)&cmd_config_e_tag_e_tag_id_val,
13387                 (void *)&cmd_config_e_tag_port,
13388                 (void *)&cmd_config_e_tag_port_id,
13389                 NULL,
13390         },
13391 };
13392
13393 /* vf vlan anti spoof configuration */
13394
13395 /* Common result structure for vf vlan anti spoof */
13396 struct cmd_vf_vlan_anti_spoof_result {
13397         cmdline_fixed_string_t set;
13398         cmdline_fixed_string_t vf;
13399         cmdline_fixed_string_t vlan;
13400         cmdline_fixed_string_t antispoof;
13401         portid_t port_id;
13402         uint32_t vf_id;
13403         cmdline_fixed_string_t on_off;
13404 };
13405
13406 /* Common CLI fields for vf vlan anti spoof enable disable */
13407 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13408         TOKEN_STRING_INITIALIZER
13409                 (struct cmd_vf_vlan_anti_spoof_result,
13410                  set, "set");
13411 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13412         TOKEN_STRING_INITIALIZER
13413                 (struct cmd_vf_vlan_anti_spoof_result,
13414                  vf, "vf");
13415 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13416         TOKEN_STRING_INITIALIZER
13417                 (struct cmd_vf_vlan_anti_spoof_result,
13418                  vlan, "vlan");
13419 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13420         TOKEN_STRING_INITIALIZER
13421                 (struct cmd_vf_vlan_anti_spoof_result,
13422                  antispoof, "antispoof");
13423 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13424         TOKEN_NUM_INITIALIZER
13425                 (struct cmd_vf_vlan_anti_spoof_result,
13426                  port_id, UINT16);
13427 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13428         TOKEN_NUM_INITIALIZER
13429                 (struct cmd_vf_vlan_anti_spoof_result,
13430                  vf_id, UINT32);
13431 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_vf_vlan_anti_spoof_result,
13434                  on_off, "on#off");
13435
13436 static void
13437 cmd_set_vf_vlan_anti_spoof_parsed(
13438         void *parsed_result,
13439         __rte_unused struct cmdline *cl,
13440         __rte_unused void *data)
13441 {
13442         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13443         int ret = -ENOTSUP;
13444
13445         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13446
13447         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13448                 return;
13449
13450 #ifdef RTE_LIBRTE_IXGBE_PMD
13451         if (ret == -ENOTSUP)
13452                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13453                                 res->vf_id, is_on);
13454 #endif
13455 #ifdef RTE_LIBRTE_I40E_PMD
13456         if (ret == -ENOTSUP)
13457                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13458                                 res->vf_id, is_on);
13459 #endif
13460 #ifdef RTE_LIBRTE_BNXT_PMD
13461         if (ret == -ENOTSUP)
13462                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13463                                 res->vf_id, is_on);
13464 #endif
13465
13466         switch (ret) {
13467         case 0:
13468                 break;
13469         case -EINVAL:
13470                 printf("invalid vf_id %d\n", res->vf_id);
13471                 break;
13472         case -ENODEV:
13473                 printf("invalid port_id %d\n", res->port_id);
13474                 break;
13475         case -ENOTSUP:
13476                 printf("function not implemented\n");
13477                 break;
13478         default:
13479                 printf("programming error: (%s)\n", strerror(-ret));
13480         }
13481 }
13482
13483 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13484         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13485         .data = NULL,
13486         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13487         .tokens = {
13488                 (void *)&cmd_vf_vlan_anti_spoof_set,
13489                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13490                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13491                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13492                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13493                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13494                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13495                 NULL,
13496         },
13497 };
13498
13499 /* vf mac anti spoof configuration */
13500
13501 /* Common result structure for vf mac anti spoof */
13502 struct cmd_vf_mac_anti_spoof_result {
13503         cmdline_fixed_string_t set;
13504         cmdline_fixed_string_t vf;
13505         cmdline_fixed_string_t mac;
13506         cmdline_fixed_string_t antispoof;
13507         portid_t port_id;
13508         uint32_t vf_id;
13509         cmdline_fixed_string_t on_off;
13510 };
13511
13512 /* Common CLI fields for vf mac anti spoof enable disable */
13513 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13514         TOKEN_STRING_INITIALIZER
13515                 (struct cmd_vf_mac_anti_spoof_result,
13516                  set, "set");
13517 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13518         TOKEN_STRING_INITIALIZER
13519                 (struct cmd_vf_mac_anti_spoof_result,
13520                  vf, "vf");
13521 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13522         TOKEN_STRING_INITIALIZER
13523                 (struct cmd_vf_mac_anti_spoof_result,
13524                  mac, "mac");
13525 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13526         TOKEN_STRING_INITIALIZER
13527                 (struct cmd_vf_mac_anti_spoof_result,
13528                  antispoof, "antispoof");
13529 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13530         TOKEN_NUM_INITIALIZER
13531                 (struct cmd_vf_mac_anti_spoof_result,
13532                  port_id, UINT16);
13533 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13534         TOKEN_NUM_INITIALIZER
13535                 (struct cmd_vf_mac_anti_spoof_result,
13536                  vf_id, UINT32);
13537 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_vf_mac_anti_spoof_result,
13540                  on_off, "on#off");
13541
13542 static void
13543 cmd_set_vf_mac_anti_spoof_parsed(
13544         void *parsed_result,
13545         __rte_unused struct cmdline *cl,
13546         __rte_unused void *data)
13547 {
13548         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13549         int ret = -ENOTSUP;
13550
13551         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13552
13553         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13554                 return;
13555
13556 #ifdef RTE_LIBRTE_IXGBE_PMD
13557         if (ret == -ENOTSUP)
13558                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13559                         res->vf_id, is_on);
13560 #endif
13561 #ifdef RTE_LIBRTE_I40E_PMD
13562         if (ret == -ENOTSUP)
13563                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13564                         res->vf_id, is_on);
13565 #endif
13566 #ifdef RTE_LIBRTE_BNXT_PMD
13567         if (ret == -ENOTSUP)
13568                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13569                         res->vf_id, is_on);
13570 #endif
13571
13572         switch (ret) {
13573         case 0:
13574                 break;
13575         case -EINVAL:
13576                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13577                 break;
13578         case -ENODEV:
13579                 printf("invalid port_id %d\n", res->port_id);
13580                 break;
13581         case -ENOTSUP:
13582                 printf("function not implemented\n");
13583                 break;
13584         default:
13585                 printf("programming error: (%s)\n", strerror(-ret));
13586         }
13587 }
13588
13589 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13590         .f = cmd_set_vf_mac_anti_spoof_parsed,
13591         .data = NULL,
13592         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13593         .tokens = {
13594                 (void *)&cmd_vf_mac_anti_spoof_set,
13595                 (void *)&cmd_vf_mac_anti_spoof_vf,
13596                 (void *)&cmd_vf_mac_anti_spoof_mac,
13597                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13598                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13599                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13600                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13601                 NULL,
13602         },
13603 };
13604
13605 /* vf vlan strip queue configuration */
13606
13607 /* Common result structure for vf mac anti spoof */
13608 struct cmd_vf_vlan_stripq_result {
13609         cmdline_fixed_string_t set;
13610         cmdline_fixed_string_t vf;
13611         cmdline_fixed_string_t vlan;
13612         cmdline_fixed_string_t stripq;
13613         portid_t port_id;
13614         uint16_t vf_id;
13615         cmdline_fixed_string_t on_off;
13616 };
13617
13618 /* Common CLI fields for vf vlan strip enable disable */
13619 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13620         TOKEN_STRING_INITIALIZER
13621                 (struct cmd_vf_vlan_stripq_result,
13622                  set, "set");
13623 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13624         TOKEN_STRING_INITIALIZER
13625                 (struct cmd_vf_vlan_stripq_result,
13626                  vf, "vf");
13627 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13628         TOKEN_STRING_INITIALIZER
13629                 (struct cmd_vf_vlan_stripq_result,
13630                  vlan, "vlan");
13631 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13632         TOKEN_STRING_INITIALIZER
13633                 (struct cmd_vf_vlan_stripq_result,
13634                  stripq, "stripq");
13635 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13636         TOKEN_NUM_INITIALIZER
13637                 (struct cmd_vf_vlan_stripq_result,
13638                  port_id, UINT16);
13639 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13640         TOKEN_NUM_INITIALIZER
13641                 (struct cmd_vf_vlan_stripq_result,
13642                  vf_id, UINT16);
13643 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_vf_vlan_stripq_result,
13646                  on_off, "on#off");
13647
13648 static void
13649 cmd_set_vf_vlan_stripq_parsed(
13650         void *parsed_result,
13651         __rte_unused struct cmdline *cl,
13652         __rte_unused void *data)
13653 {
13654         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13655         int ret = -ENOTSUP;
13656
13657         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13658
13659         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13660                 return;
13661
13662 #ifdef RTE_LIBRTE_IXGBE_PMD
13663         if (ret == -ENOTSUP)
13664                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13665                         res->vf_id, is_on);
13666 #endif
13667 #ifdef RTE_LIBRTE_I40E_PMD
13668         if (ret == -ENOTSUP)
13669                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13670                         res->vf_id, is_on);
13671 #endif
13672 #ifdef RTE_LIBRTE_BNXT_PMD
13673         if (ret == -ENOTSUP)
13674                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13675                         res->vf_id, is_on);
13676 #endif
13677
13678         switch (ret) {
13679         case 0:
13680                 break;
13681         case -EINVAL:
13682                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13683                 break;
13684         case -ENODEV:
13685                 printf("invalid port_id %d\n", res->port_id);
13686                 break;
13687         case -ENOTSUP:
13688                 printf("function not implemented\n");
13689                 break;
13690         default:
13691                 printf("programming error: (%s)\n", strerror(-ret));
13692         }
13693 }
13694
13695 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13696         .f = cmd_set_vf_vlan_stripq_parsed,
13697         .data = NULL,
13698         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13699         .tokens = {
13700                 (void *)&cmd_vf_vlan_stripq_set,
13701                 (void *)&cmd_vf_vlan_stripq_vf,
13702                 (void *)&cmd_vf_vlan_stripq_vlan,
13703                 (void *)&cmd_vf_vlan_stripq_stripq,
13704                 (void *)&cmd_vf_vlan_stripq_port_id,
13705                 (void *)&cmd_vf_vlan_stripq_vf_id,
13706                 (void *)&cmd_vf_vlan_stripq_on_off,
13707                 NULL,
13708         },
13709 };
13710
13711 /* vf vlan insert configuration */
13712
13713 /* Common result structure for vf vlan insert */
13714 struct cmd_vf_vlan_insert_result {
13715         cmdline_fixed_string_t set;
13716         cmdline_fixed_string_t vf;
13717         cmdline_fixed_string_t vlan;
13718         cmdline_fixed_string_t insert;
13719         portid_t port_id;
13720         uint16_t vf_id;
13721         uint16_t vlan_id;
13722 };
13723
13724 /* Common CLI fields for vf vlan insert enable disable */
13725 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13726         TOKEN_STRING_INITIALIZER
13727                 (struct cmd_vf_vlan_insert_result,
13728                  set, "set");
13729 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13730         TOKEN_STRING_INITIALIZER
13731                 (struct cmd_vf_vlan_insert_result,
13732                  vf, "vf");
13733 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13734         TOKEN_STRING_INITIALIZER
13735                 (struct cmd_vf_vlan_insert_result,
13736                  vlan, "vlan");
13737 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13738         TOKEN_STRING_INITIALIZER
13739                 (struct cmd_vf_vlan_insert_result,
13740                  insert, "insert");
13741 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13742         TOKEN_NUM_INITIALIZER
13743                 (struct cmd_vf_vlan_insert_result,
13744                  port_id, UINT16);
13745 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13746         TOKEN_NUM_INITIALIZER
13747                 (struct cmd_vf_vlan_insert_result,
13748                  vf_id, UINT16);
13749 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13750         TOKEN_NUM_INITIALIZER
13751                 (struct cmd_vf_vlan_insert_result,
13752                  vlan_id, UINT16);
13753
13754 static void
13755 cmd_set_vf_vlan_insert_parsed(
13756         void *parsed_result,
13757         __rte_unused struct cmdline *cl,
13758         __rte_unused void *data)
13759 {
13760         struct cmd_vf_vlan_insert_result *res = parsed_result;
13761         int ret = -ENOTSUP;
13762
13763         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13764                 return;
13765
13766 #ifdef RTE_LIBRTE_IXGBE_PMD
13767         if (ret == -ENOTSUP)
13768                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13769                         res->vlan_id);
13770 #endif
13771 #ifdef RTE_LIBRTE_I40E_PMD
13772         if (ret == -ENOTSUP)
13773                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13774                         res->vlan_id);
13775 #endif
13776 #ifdef RTE_LIBRTE_BNXT_PMD
13777         if (ret == -ENOTSUP)
13778                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13779                         res->vlan_id);
13780 #endif
13781
13782         switch (ret) {
13783         case 0:
13784                 break;
13785         case -EINVAL:
13786                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13787                 break;
13788         case -ENODEV:
13789                 printf("invalid port_id %d\n", res->port_id);
13790                 break;
13791         case -ENOTSUP:
13792                 printf("function not implemented\n");
13793                 break;
13794         default:
13795                 printf("programming error: (%s)\n", strerror(-ret));
13796         }
13797 }
13798
13799 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13800         .f = cmd_set_vf_vlan_insert_parsed,
13801         .data = NULL,
13802         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13803         .tokens = {
13804                 (void *)&cmd_vf_vlan_insert_set,
13805                 (void *)&cmd_vf_vlan_insert_vf,
13806                 (void *)&cmd_vf_vlan_insert_vlan,
13807                 (void *)&cmd_vf_vlan_insert_insert,
13808                 (void *)&cmd_vf_vlan_insert_port_id,
13809                 (void *)&cmd_vf_vlan_insert_vf_id,
13810                 (void *)&cmd_vf_vlan_insert_vlan_id,
13811                 NULL,
13812         },
13813 };
13814
13815 /* tx loopback configuration */
13816
13817 /* Common result structure for tx loopback */
13818 struct cmd_tx_loopback_result {
13819         cmdline_fixed_string_t set;
13820         cmdline_fixed_string_t tx;
13821         cmdline_fixed_string_t loopback;
13822         portid_t port_id;
13823         cmdline_fixed_string_t on_off;
13824 };
13825
13826 /* Common CLI fields for tx loopback enable disable */
13827 cmdline_parse_token_string_t cmd_tx_loopback_set =
13828         TOKEN_STRING_INITIALIZER
13829                 (struct cmd_tx_loopback_result,
13830                  set, "set");
13831 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13832         TOKEN_STRING_INITIALIZER
13833                 (struct cmd_tx_loopback_result,
13834                  tx, "tx");
13835 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13836         TOKEN_STRING_INITIALIZER
13837                 (struct cmd_tx_loopback_result,
13838                  loopback, "loopback");
13839 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13840         TOKEN_NUM_INITIALIZER
13841                 (struct cmd_tx_loopback_result,
13842                  port_id, UINT16);
13843 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13844         TOKEN_STRING_INITIALIZER
13845                 (struct cmd_tx_loopback_result,
13846                  on_off, "on#off");
13847
13848 static void
13849 cmd_set_tx_loopback_parsed(
13850         void *parsed_result,
13851         __rte_unused struct cmdline *cl,
13852         __rte_unused void *data)
13853 {
13854         struct cmd_tx_loopback_result *res = parsed_result;
13855         int ret = -ENOTSUP;
13856
13857         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13858
13859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13860                 return;
13861
13862 #ifdef RTE_LIBRTE_IXGBE_PMD
13863         if (ret == -ENOTSUP)
13864                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13865 #endif
13866 #ifdef RTE_LIBRTE_I40E_PMD
13867         if (ret == -ENOTSUP)
13868                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13869 #endif
13870 #ifdef RTE_LIBRTE_BNXT_PMD
13871         if (ret == -ENOTSUP)
13872                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13873 #endif
13874 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13875         if (ret == -ENOTSUP)
13876                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13877 #endif
13878
13879         switch (ret) {
13880         case 0:
13881                 break;
13882         case -EINVAL:
13883                 printf("invalid is_on %d\n", is_on);
13884                 break;
13885         case -ENODEV:
13886                 printf("invalid port_id %d\n", res->port_id);
13887                 break;
13888         case -ENOTSUP:
13889                 printf("function not implemented\n");
13890                 break;
13891         default:
13892                 printf("programming error: (%s)\n", strerror(-ret));
13893         }
13894 }
13895
13896 cmdline_parse_inst_t cmd_set_tx_loopback = {
13897         .f = cmd_set_tx_loopback_parsed,
13898         .data = NULL,
13899         .help_str = "set tx loopback <port_id> on|off",
13900         .tokens = {
13901                 (void *)&cmd_tx_loopback_set,
13902                 (void *)&cmd_tx_loopback_tx,
13903                 (void *)&cmd_tx_loopback_loopback,
13904                 (void *)&cmd_tx_loopback_port_id,
13905                 (void *)&cmd_tx_loopback_on_off,
13906                 NULL,
13907         },
13908 };
13909
13910 /* all queues drop enable configuration */
13911
13912 /* Common result structure for all queues drop enable */
13913 struct cmd_all_queues_drop_en_result {
13914         cmdline_fixed_string_t set;
13915         cmdline_fixed_string_t all;
13916         cmdline_fixed_string_t queues;
13917         cmdline_fixed_string_t drop;
13918         portid_t port_id;
13919         cmdline_fixed_string_t on_off;
13920 };
13921
13922 /* Common CLI fields for tx loopback enable disable */
13923 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13924         TOKEN_STRING_INITIALIZER
13925                 (struct cmd_all_queues_drop_en_result,
13926                  set, "set");
13927 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13928         TOKEN_STRING_INITIALIZER
13929                 (struct cmd_all_queues_drop_en_result,
13930                  all, "all");
13931 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13932         TOKEN_STRING_INITIALIZER
13933                 (struct cmd_all_queues_drop_en_result,
13934                  queues, "queues");
13935 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13936         TOKEN_STRING_INITIALIZER
13937                 (struct cmd_all_queues_drop_en_result,
13938                  drop, "drop");
13939 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13940         TOKEN_NUM_INITIALIZER
13941                 (struct cmd_all_queues_drop_en_result,
13942                  port_id, UINT16);
13943 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13944         TOKEN_STRING_INITIALIZER
13945                 (struct cmd_all_queues_drop_en_result,
13946                  on_off, "on#off");
13947
13948 static void
13949 cmd_set_all_queues_drop_en_parsed(
13950         void *parsed_result,
13951         __rte_unused struct cmdline *cl,
13952         __rte_unused void *data)
13953 {
13954         struct cmd_all_queues_drop_en_result *res = parsed_result;
13955         int ret = -ENOTSUP;
13956         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13957
13958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13959                 return;
13960
13961 #ifdef RTE_LIBRTE_IXGBE_PMD
13962         if (ret == -ENOTSUP)
13963                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13964 #endif
13965 #ifdef RTE_LIBRTE_BNXT_PMD
13966         if (ret == -ENOTSUP)
13967                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13968 #endif
13969         switch (ret) {
13970         case 0:
13971                 break;
13972         case -EINVAL:
13973                 printf("invalid is_on %d\n", is_on);
13974                 break;
13975         case -ENODEV:
13976                 printf("invalid port_id %d\n", res->port_id);
13977                 break;
13978         case -ENOTSUP:
13979                 printf("function not implemented\n");
13980                 break;
13981         default:
13982                 printf("programming error: (%s)\n", strerror(-ret));
13983         }
13984 }
13985
13986 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13987         .f = cmd_set_all_queues_drop_en_parsed,
13988         .data = NULL,
13989         .help_str = "set all queues drop <port_id> on|off",
13990         .tokens = {
13991                 (void *)&cmd_all_queues_drop_en_set,
13992                 (void *)&cmd_all_queues_drop_en_all,
13993                 (void *)&cmd_all_queues_drop_en_queues,
13994                 (void *)&cmd_all_queues_drop_en_drop,
13995                 (void *)&cmd_all_queues_drop_en_port_id,
13996                 (void *)&cmd_all_queues_drop_en_on_off,
13997                 NULL,
13998         },
13999 };
14000
14001 /* vf split drop enable configuration */
14002
14003 /* Common result structure for vf split drop enable */
14004 struct cmd_vf_split_drop_en_result {
14005         cmdline_fixed_string_t set;
14006         cmdline_fixed_string_t vf;
14007         cmdline_fixed_string_t split;
14008         cmdline_fixed_string_t drop;
14009         portid_t port_id;
14010         uint16_t vf_id;
14011         cmdline_fixed_string_t on_off;
14012 };
14013
14014 /* Common CLI fields for vf split drop enable disable */
14015 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_vf_split_drop_en_result,
14018                  set, "set");
14019 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_vf_split_drop_en_result,
14022                  vf, "vf");
14023 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14024         TOKEN_STRING_INITIALIZER
14025                 (struct cmd_vf_split_drop_en_result,
14026                  split, "split");
14027 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14028         TOKEN_STRING_INITIALIZER
14029                 (struct cmd_vf_split_drop_en_result,
14030                  drop, "drop");
14031 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14032         TOKEN_NUM_INITIALIZER
14033                 (struct cmd_vf_split_drop_en_result,
14034                  port_id, UINT16);
14035 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14036         TOKEN_NUM_INITIALIZER
14037                 (struct cmd_vf_split_drop_en_result,
14038                  vf_id, UINT16);
14039 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14040         TOKEN_STRING_INITIALIZER
14041                 (struct cmd_vf_split_drop_en_result,
14042                  on_off, "on#off");
14043
14044 static void
14045 cmd_set_vf_split_drop_en_parsed(
14046         void *parsed_result,
14047         __rte_unused struct cmdline *cl,
14048         __rte_unused void *data)
14049 {
14050         struct cmd_vf_split_drop_en_result *res = parsed_result;
14051         int ret = -ENOTSUP;
14052         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14053
14054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14055                 return;
14056
14057 #ifdef RTE_LIBRTE_IXGBE_PMD
14058         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14059                         is_on);
14060 #endif
14061         switch (ret) {
14062         case 0:
14063                 break;
14064         case -EINVAL:
14065                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14066                 break;
14067         case -ENODEV:
14068                 printf("invalid port_id %d\n", res->port_id);
14069                 break;
14070         case -ENOTSUP:
14071                 printf("not supported on port %d\n", res->port_id);
14072                 break;
14073         default:
14074                 printf("programming error: (%s)\n", strerror(-ret));
14075         }
14076 }
14077
14078 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14079         .f = cmd_set_vf_split_drop_en_parsed,
14080         .data = NULL,
14081         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14082         .tokens = {
14083                 (void *)&cmd_vf_split_drop_en_set,
14084                 (void *)&cmd_vf_split_drop_en_vf,
14085                 (void *)&cmd_vf_split_drop_en_split,
14086                 (void *)&cmd_vf_split_drop_en_drop,
14087                 (void *)&cmd_vf_split_drop_en_port_id,
14088                 (void *)&cmd_vf_split_drop_en_vf_id,
14089                 (void *)&cmd_vf_split_drop_en_on_off,
14090                 NULL,
14091         },
14092 };
14093
14094 /* vf mac address configuration */
14095
14096 /* Common result structure for vf mac address */
14097 struct cmd_set_vf_mac_addr_result {
14098         cmdline_fixed_string_t set;
14099         cmdline_fixed_string_t vf;
14100         cmdline_fixed_string_t mac;
14101         cmdline_fixed_string_t addr;
14102         portid_t port_id;
14103         uint16_t vf_id;
14104         struct rte_ether_addr mac_addr;
14105
14106 };
14107
14108 /* Common CLI fields for vf split drop enable disable */
14109 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_set_vf_mac_addr_result,
14112                  set, "set");
14113 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14114         TOKEN_STRING_INITIALIZER
14115                 (struct cmd_set_vf_mac_addr_result,
14116                  vf, "vf");
14117 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14118         TOKEN_STRING_INITIALIZER
14119                 (struct cmd_set_vf_mac_addr_result,
14120                  mac, "mac");
14121 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14122         TOKEN_STRING_INITIALIZER
14123                 (struct cmd_set_vf_mac_addr_result,
14124                  addr, "addr");
14125 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14126         TOKEN_NUM_INITIALIZER
14127                 (struct cmd_set_vf_mac_addr_result,
14128                  port_id, UINT16);
14129 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14130         TOKEN_NUM_INITIALIZER
14131                 (struct cmd_set_vf_mac_addr_result,
14132                  vf_id, UINT16);
14133 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14134         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14135                  mac_addr);
14136
14137 static void
14138 cmd_set_vf_mac_addr_parsed(
14139         void *parsed_result,
14140         __rte_unused struct cmdline *cl,
14141         __rte_unused void *data)
14142 {
14143         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14144         int ret = -ENOTSUP;
14145
14146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14147                 return;
14148
14149 #ifdef RTE_LIBRTE_IXGBE_PMD
14150         if (ret == -ENOTSUP)
14151                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14152                                 &res->mac_addr);
14153 #endif
14154 #ifdef RTE_LIBRTE_I40E_PMD
14155         if (ret == -ENOTSUP)
14156                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14157                                 &res->mac_addr);
14158 #endif
14159 #ifdef RTE_LIBRTE_BNXT_PMD
14160         if (ret == -ENOTSUP)
14161                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14162                                 &res->mac_addr);
14163 #endif
14164
14165         switch (ret) {
14166         case 0:
14167                 break;
14168         case -EINVAL:
14169                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14170                 break;
14171         case -ENODEV:
14172                 printf("invalid port_id %d\n", res->port_id);
14173                 break;
14174         case -ENOTSUP:
14175                 printf("function not implemented\n");
14176                 break;
14177         default:
14178                 printf("programming error: (%s)\n", strerror(-ret));
14179         }
14180 }
14181
14182 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14183         .f = cmd_set_vf_mac_addr_parsed,
14184         .data = NULL,
14185         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14186         .tokens = {
14187                 (void *)&cmd_set_vf_mac_addr_set,
14188                 (void *)&cmd_set_vf_mac_addr_vf,
14189                 (void *)&cmd_set_vf_mac_addr_mac,
14190                 (void *)&cmd_set_vf_mac_addr_addr,
14191                 (void *)&cmd_set_vf_mac_addr_port_id,
14192                 (void *)&cmd_set_vf_mac_addr_vf_id,
14193                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14194                 NULL,
14195         },
14196 };
14197
14198 /* MACsec configuration */
14199
14200 /* Common result structure for MACsec offload enable */
14201 struct cmd_macsec_offload_on_result {
14202         cmdline_fixed_string_t set;
14203         cmdline_fixed_string_t macsec;
14204         cmdline_fixed_string_t offload;
14205         portid_t port_id;
14206         cmdline_fixed_string_t on;
14207         cmdline_fixed_string_t encrypt;
14208         cmdline_fixed_string_t en_on_off;
14209         cmdline_fixed_string_t replay_protect;
14210         cmdline_fixed_string_t rp_on_off;
14211 };
14212
14213 /* Common CLI fields for MACsec offload disable */
14214 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14215         TOKEN_STRING_INITIALIZER
14216                 (struct cmd_macsec_offload_on_result,
14217                  set, "set");
14218 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14219         TOKEN_STRING_INITIALIZER
14220                 (struct cmd_macsec_offload_on_result,
14221                  macsec, "macsec");
14222 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14223         TOKEN_STRING_INITIALIZER
14224                 (struct cmd_macsec_offload_on_result,
14225                  offload, "offload");
14226 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14227         TOKEN_NUM_INITIALIZER
14228                 (struct cmd_macsec_offload_on_result,
14229                  port_id, UINT16);
14230 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14231         TOKEN_STRING_INITIALIZER
14232                 (struct cmd_macsec_offload_on_result,
14233                  on, "on");
14234 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14235         TOKEN_STRING_INITIALIZER
14236                 (struct cmd_macsec_offload_on_result,
14237                  encrypt, "encrypt");
14238 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14239         TOKEN_STRING_INITIALIZER
14240                 (struct cmd_macsec_offload_on_result,
14241                  en_on_off, "on#off");
14242 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14243         TOKEN_STRING_INITIALIZER
14244                 (struct cmd_macsec_offload_on_result,
14245                  replay_protect, "replay-protect");
14246 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14247         TOKEN_STRING_INITIALIZER
14248                 (struct cmd_macsec_offload_on_result,
14249                  rp_on_off, "on#off");
14250
14251 static void
14252 cmd_set_macsec_offload_on_parsed(
14253         void *parsed_result,
14254         __rte_unused struct cmdline *cl,
14255         __rte_unused void *data)
14256 {
14257         struct cmd_macsec_offload_on_result *res = parsed_result;
14258         int ret = -ENOTSUP;
14259         portid_t port_id = res->port_id;
14260         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14261         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14262         struct rte_eth_dev_info dev_info;
14263
14264         if (port_id_is_invalid(port_id, ENABLED_WARN))
14265                 return;
14266         if (!port_is_stopped(port_id)) {
14267                 printf("Please stop port %d first\n", port_id);
14268                 return;
14269         }
14270
14271         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14272         if (ret != 0)
14273                 return;
14274
14275         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14276 #ifdef RTE_LIBRTE_IXGBE_PMD
14277                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14278 #endif
14279         }
14280         RTE_SET_USED(en);
14281         RTE_SET_USED(rp);
14282
14283         switch (ret) {
14284         case 0:
14285                 ports[port_id].dev_conf.txmode.offloads |=
14286                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14287                 cmd_reconfig_device_queue(port_id, 1, 1);
14288                 break;
14289         case -ENODEV:
14290                 printf("invalid port_id %d\n", port_id);
14291                 break;
14292         case -ENOTSUP:
14293                 printf("not supported on port %d\n", port_id);
14294                 break;
14295         default:
14296                 printf("programming error: (%s)\n", strerror(-ret));
14297         }
14298 }
14299
14300 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14301         .f = cmd_set_macsec_offload_on_parsed,
14302         .data = NULL,
14303         .help_str = "set macsec offload <port_id> on "
14304                 "encrypt on|off replay-protect on|off",
14305         .tokens = {
14306                 (void *)&cmd_macsec_offload_on_set,
14307                 (void *)&cmd_macsec_offload_on_macsec,
14308                 (void *)&cmd_macsec_offload_on_offload,
14309                 (void *)&cmd_macsec_offload_on_port_id,
14310                 (void *)&cmd_macsec_offload_on_on,
14311                 (void *)&cmd_macsec_offload_on_encrypt,
14312                 (void *)&cmd_macsec_offload_on_en_on_off,
14313                 (void *)&cmd_macsec_offload_on_replay_protect,
14314                 (void *)&cmd_macsec_offload_on_rp_on_off,
14315                 NULL,
14316         },
14317 };
14318
14319 /* Common result structure for MACsec offload disable */
14320 struct cmd_macsec_offload_off_result {
14321         cmdline_fixed_string_t set;
14322         cmdline_fixed_string_t macsec;
14323         cmdline_fixed_string_t offload;
14324         portid_t port_id;
14325         cmdline_fixed_string_t off;
14326 };
14327
14328 /* Common CLI fields for MACsec offload disable */
14329 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14330         TOKEN_STRING_INITIALIZER
14331                 (struct cmd_macsec_offload_off_result,
14332                  set, "set");
14333 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14334         TOKEN_STRING_INITIALIZER
14335                 (struct cmd_macsec_offload_off_result,
14336                  macsec, "macsec");
14337 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14338         TOKEN_STRING_INITIALIZER
14339                 (struct cmd_macsec_offload_off_result,
14340                  offload, "offload");
14341 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14342         TOKEN_NUM_INITIALIZER
14343                 (struct cmd_macsec_offload_off_result,
14344                  port_id, UINT16);
14345 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14346         TOKEN_STRING_INITIALIZER
14347                 (struct cmd_macsec_offload_off_result,
14348                  off, "off");
14349
14350 static void
14351 cmd_set_macsec_offload_off_parsed(
14352         void *parsed_result,
14353         __rte_unused struct cmdline *cl,
14354         __rte_unused void *data)
14355 {
14356         struct cmd_macsec_offload_off_result *res = parsed_result;
14357         int ret = -ENOTSUP;
14358         struct rte_eth_dev_info dev_info;
14359         portid_t port_id = res->port_id;
14360
14361         if (port_id_is_invalid(port_id, ENABLED_WARN))
14362                 return;
14363         if (!port_is_stopped(port_id)) {
14364                 printf("Please stop port %d first\n", port_id);
14365                 return;
14366         }
14367
14368         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14369         if (ret != 0)
14370                 return;
14371
14372         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14373 #ifdef RTE_LIBRTE_IXGBE_PMD
14374                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14375 #endif
14376         }
14377         switch (ret) {
14378         case 0:
14379                 ports[port_id].dev_conf.txmode.offloads &=
14380                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14381                 cmd_reconfig_device_queue(port_id, 1, 1);
14382                 break;
14383         case -ENODEV:
14384                 printf("invalid port_id %d\n", port_id);
14385                 break;
14386         case -ENOTSUP:
14387                 printf("not supported on port %d\n", port_id);
14388                 break;
14389         default:
14390                 printf("programming error: (%s)\n", strerror(-ret));
14391         }
14392 }
14393
14394 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14395         .f = cmd_set_macsec_offload_off_parsed,
14396         .data = NULL,
14397         .help_str = "set macsec offload <port_id> off",
14398         .tokens = {
14399                 (void *)&cmd_macsec_offload_off_set,
14400                 (void *)&cmd_macsec_offload_off_macsec,
14401                 (void *)&cmd_macsec_offload_off_offload,
14402                 (void *)&cmd_macsec_offload_off_port_id,
14403                 (void *)&cmd_macsec_offload_off_off,
14404                 NULL,
14405         },
14406 };
14407
14408 /* Common result structure for MACsec secure connection configure */
14409 struct cmd_macsec_sc_result {
14410         cmdline_fixed_string_t set;
14411         cmdline_fixed_string_t macsec;
14412         cmdline_fixed_string_t sc;
14413         cmdline_fixed_string_t tx_rx;
14414         portid_t port_id;
14415         struct rte_ether_addr mac;
14416         uint16_t pi;
14417 };
14418
14419 /* Common CLI fields for MACsec secure connection configure */
14420 cmdline_parse_token_string_t cmd_macsec_sc_set =
14421         TOKEN_STRING_INITIALIZER
14422                 (struct cmd_macsec_sc_result,
14423                  set, "set");
14424 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14425         TOKEN_STRING_INITIALIZER
14426                 (struct cmd_macsec_sc_result,
14427                  macsec, "macsec");
14428 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14429         TOKEN_STRING_INITIALIZER
14430                 (struct cmd_macsec_sc_result,
14431                  sc, "sc");
14432 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14433         TOKEN_STRING_INITIALIZER
14434                 (struct cmd_macsec_sc_result,
14435                  tx_rx, "tx#rx");
14436 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14437         TOKEN_NUM_INITIALIZER
14438                 (struct cmd_macsec_sc_result,
14439                  port_id, UINT16);
14440 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14441         TOKEN_ETHERADDR_INITIALIZER
14442                 (struct cmd_macsec_sc_result,
14443                  mac);
14444 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14445         TOKEN_NUM_INITIALIZER
14446                 (struct cmd_macsec_sc_result,
14447                  pi, UINT16);
14448
14449 static void
14450 cmd_set_macsec_sc_parsed(
14451         void *parsed_result,
14452         __rte_unused struct cmdline *cl,
14453         __rte_unused void *data)
14454 {
14455         struct cmd_macsec_sc_result *res = parsed_result;
14456         int ret = -ENOTSUP;
14457         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14458
14459 #ifdef RTE_LIBRTE_IXGBE_PMD
14460         ret = is_tx ?
14461                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14462                                 res->mac.addr_bytes) :
14463                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14464                                 res->mac.addr_bytes, res->pi);
14465 #endif
14466         RTE_SET_USED(is_tx);
14467
14468         switch (ret) {
14469         case 0:
14470                 break;
14471         case -ENODEV:
14472                 printf("invalid port_id %d\n", res->port_id);
14473                 break;
14474         case -ENOTSUP:
14475                 printf("not supported on port %d\n", res->port_id);
14476                 break;
14477         default:
14478                 printf("programming error: (%s)\n", strerror(-ret));
14479         }
14480 }
14481
14482 cmdline_parse_inst_t cmd_set_macsec_sc = {
14483         .f = cmd_set_macsec_sc_parsed,
14484         .data = NULL,
14485         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14486         .tokens = {
14487                 (void *)&cmd_macsec_sc_set,
14488                 (void *)&cmd_macsec_sc_macsec,
14489                 (void *)&cmd_macsec_sc_sc,
14490                 (void *)&cmd_macsec_sc_tx_rx,
14491                 (void *)&cmd_macsec_sc_port_id,
14492                 (void *)&cmd_macsec_sc_mac,
14493                 (void *)&cmd_macsec_sc_pi,
14494                 NULL,
14495         },
14496 };
14497
14498 /* Common result structure for MACsec secure connection configure */
14499 struct cmd_macsec_sa_result {
14500         cmdline_fixed_string_t set;
14501         cmdline_fixed_string_t macsec;
14502         cmdline_fixed_string_t sa;
14503         cmdline_fixed_string_t tx_rx;
14504         portid_t port_id;
14505         uint8_t idx;
14506         uint8_t an;
14507         uint32_t pn;
14508         cmdline_fixed_string_t key;
14509 };
14510
14511 /* Common CLI fields for MACsec secure connection configure */
14512 cmdline_parse_token_string_t cmd_macsec_sa_set =
14513         TOKEN_STRING_INITIALIZER
14514                 (struct cmd_macsec_sa_result,
14515                  set, "set");
14516 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14517         TOKEN_STRING_INITIALIZER
14518                 (struct cmd_macsec_sa_result,
14519                  macsec, "macsec");
14520 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14521         TOKEN_STRING_INITIALIZER
14522                 (struct cmd_macsec_sa_result,
14523                  sa, "sa");
14524 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14525         TOKEN_STRING_INITIALIZER
14526                 (struct cmd_macsec_sa_result,
14527                  tx_rx, "tx#rx");
14528 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14529         TOKEN_NUM_INITIALIZER
14530                 (struct cmd_macsec_sa_result,
14531                  port_id, UINT16);
14532 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14533         TOKEN_NUM_INITIALIZER
14534                 (struct cmd_macsec_sa_result,
14535                  idx, UINT8);
14536 cmdline_parse_token_num_t cmd_macsec_sa_an =
14537         TOKEN_NUM_INITIALIZER
14538                 (struct cmd_macsec_sa_result,
14539                  an, UINT8);
14540 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14541         TOKEN_NUM_INITIALIZER
14542                 (struct cmd_macsec_sa_result,
14543                  pn, UINT32);
14544 cmdline_parse_token_string_t cmd_macsec_sa_key =
14545         TOKEN_STRING_INITIALIZER
14546                 (struct cmd_macsec_sa_result,
14547                  key, NULL);
14548
14549 static void
14550 cmd_set_macsec_sa_parsed(
14551         void *parsed_result,
14552         __rte_unused struct cmdline *cl,
14553         __rte_unused void *data)
14554 {
14555         struct cmd_macsec_sa_result *res = parsed_result;
14556         int ret = -ENOTSUP;
14557         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14558         uint8_t key[16] = { 0 };
14559         uint8_t xdgt0;
14560         uint8_t xdgt1;
14561         int key_len;
14562         int i;
14563
14564         key_len = strlen(res->key) / 2;
14565         if (key_len > 16)
14566                 key_len = 16;
14567
14568         for (i = 0; i < key_len; i++) {
14569                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14570                 if (xdgt0 == 0xFF)
14571                         return;
14572                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14573                 if (xdgt1 == 0xFF)
14574                         return;
14575                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14576         }
14577
14578 #ifdef RTE_LIBRTE_IXGBE_PMD
14579         ret = is_tx ?
14580                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14581                         res->idx, res->an, res->pn, key) :
14582                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14583                         res->idx, res->an, res->pn, key);
14584 #endif
14585         RTE_SET_USED(is_tx);
14586         RTE_SET_USED(key);
14587
14588         switch (ret) {
14589         case 0:
14590                 break;
14591         case -EINVAL:
14592                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14593                 break;
14594         case -ENODEV:
14595                 printf("invalid port_id %d\n", res->port_id);
14596                 break;
14597         case -ENOTSUP:
14598                 printf("not supported on port %d\n", res->port_id);
14599                 break;
14600         default:
14601                 printf("programming error: (%s)\n", strerror(-ret));
14602         }
14603 }
14604
14605 cmdline_parse_inst_t cmd_set_macsec_sa = {
14606         .f = cmd_set_macsec_sa_parsed,
14607         .data = NULL,
14608         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14609         .tokens = {
14610                 (void *)&cmd_macsec_sa_set,
14611                 (void *)&cmd_macsec_sa_macsec,
14612                 (void *)&cmd_macsec_sa_sa,
14613                 (void *)&cmd_macsec_sa_tx_rx,
14614                 (void *)&cmd_macsec_sa_port_id,
14615                 (void *)&cmd_macsec_sa_idx,
14616                 (void *)&cmd_macsec_sa_an,
14617                 (void *)&cmd_macsec_sa_pn,
14618                 (void *)&cmd_macsec_sa_key,
14619                 NULL,
14620         },
14621 };
14622
14623 /* VF unicast promiscuous mode configuration */
14624
14625 /* Common result structure for VF unicast promiscuous mode */
14626 struct cmd_vf_promisc_result {
14627         cmdline_fixed_string_t set;
14628         cmdline_fixed_string_t vf;
14629         cmdline_fixed_string_t promisc;
14630         portid_t port_id;
14631         uint32_t vf_id;
14632         cmdline_fixed_string_t on_off;
14633 };
14634
14635 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14636 cmdline_parse_token_string_t cmd_vf_promisc_set =
14637         TOKEN_STRING_INITIALIZER
14638                 (struct cmd_vf_promisc_result,
14639                  set, "set");
14640 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14641         TOKEN_STRING_INITIALIZER
14642                 (struct cmd_vf_promisc_result,
14643                  vf, "vf");
14644 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14645         TOKEN_STRING_INITIALIZER
14646                 (struct cmd_vf_promisc_result,
14647                  promisc, "promisc");
14648 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14649         TOKEN_NUM_INITIALIZER
14650                 (struct cmd_vf_promisc_result,
14651                  port_id, UINT16);
14652 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14653         TOKEN_NUM_INITIALIZER
14654                 (struct cmd_vf_promisc_result,
14655                  vf_id, UINT32);
14656 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14657         TOKEN_STRING_INITIALIZER
14658                 (struct cmd_vf_promisc_result,
14659                  on_off, "on#off");
14660
14661 static void
14662 cmd_set_vf_promisc_parsed(
14663         void *parsed_result,
14664         __rte_unused struct cmdline *cl,
14665         __rte_unused void *data)
14666 {
14667         struct cmd_vf_promisc_result *res = parsed_result;
14668         int ret = -ENOTSUP;
14669
14670         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14671
14672         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14673                 return;
14674
14675 #ifdef RTE_LIBRTE_I40E_PMD
14676         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14677                                                   res->vf_id, is_on);
14678 #endif
14679
14680         switch (ret) {
14681         case 0:
14682                 break;
14683         case -EINVAL:
14684                 printf("invalid vf_id %d\n", res->vf_id);
14685                 break;
14686         case -ENODEV:
14687                 printf("invalid port_id %d\n", res->port_id);
14688                 break;
14689         case -ENOTSUP:
14690                 printf("function not implemented\n");
14691                 break;
14692         default:
14693                 printf("programming error: (%s)\n", strerror(-ret));
14694         }
14695 }
14696
14697 cmdline_parse_inst_t cmd_set_vf_promisc = {
14698         .f = cmd_set_vf_promisc_parsed,
14699         .data = NULL,
14700         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14701                 "Set unicast promiscuous mode for a VF from the PF",
14702         .tokens = {
14703                 (void *)&cmd_vf_promisc_set,
14704                 (void *)&cmd_vf_promisc_vf,
14705                 (void *)&cmd_vf_promisc_promisc,
14706                 (void *)&cmd_vf_promisc_port_id,
14707                 (void *)&cmd_vf_promisc_vf_id,
14708                 (void *)&cmd_vf_promisc_on_off,
14709                 NULL,
14710         },
14711 };
14712
14713 /* VF multicast promiscuous mode configuration */
14714
14715 /* Common result structure for VF multicast promiscuous mode */
14716 struct cmd_vf_allmulti_result {
14717         cmdline_fixed_string_t set;
14718         cmdline_fixed_string_t vf;
14719         cmdline_fixed_string_t allmulti;
14720         portid_t port_id;
14721         uint32_t vf_id;
14722         cmdline_fixed_string_t on_off;
14723 };
14724
14725 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14726 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14727         TOKEN_STRING_INITIALIZER
14728                 (struct cmd_vf_allmulti_result,
14729                  set, "set");
14730 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14731         TOKEN_STRING_INITIALIZER
14732                 (struct cmd_vf_allmulti_result,
14733                  vf, "vf");
14734 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14735         TOKEN_STRING_INITIALIZER
14736                 (struct cmd_vf_allmulti_result,
14737                  allmulti, "allmulti");
14738 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14739         TOKEN_NUM_INITIALIZER
14740                 (struct cmd_vf_allmulti_result,
14741                  port_id, UINT16);
14742 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14743         TOKEN_NUM_INITIALIZER
14744                 (struct cmd_vf_allmulti_result,
14745                  vf_id, UINT32);
14746 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14747         TOKEN_STRING_INITIALIZER
14748                 (struct cmd_vf_allmulti_result,
14749                  on_off, "on#off");
14750
14751 static void
14752 cmd_set_vf_allmulti_parsed(
14753         void *parsed_result,
14754         __rte_unused struct cmdline *cl,
14755         __rte_unused void *data)
14756 {
14757         struct cmd_vf_allmulti_result *res = parsed_result;
14758         int ret = -ENOTSUP;
14759
14760         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14761
14762         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14763                 return;
14764
14765 #ifdef RTE_LIBRTE_I40E_PMD
14766         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14767                                                     res->vf_id, is_on);
14768 #endif
14769
14770         switch (ret) {
14771         case 0:
14772                 break;
14773         case -EINVAL:
14774                 printf("invalid vf_id %d\n", res->vf_id);
14775                 break;
14776         case -ENODEV:
14777                 printf("invalid port_id %d\n", res->port_id);
14778                 break;
14779         case -ENOTSUP:
14780                 printf("function not implemented\n");
14781                 break;
14782         default:
14783                 printf("programming error: (%s)\n", strerror(-ret));
14784         }
14785 }
14786
14787 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14788         .f = cmd_set_vf_allmulti_parsed,
14789         .data = NULL,
14790         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14791                 "Set multicast promiscuous mode for a VF from the PF",
14792         .tokens = {
14793                 (void *)&cmd_vf_allmulti_set,
14794                 (void *)&cmd_vf_allmulti_vf,
14795                 (void *)&cmd_vf_allmulti_allmulti,
14796                 (void *)&cmd_vf_allmulti_port_id,
14797                 (void *)&cmd_vf_allmulti_vf_id,
14798                 (void *)&cmd_vf_allmulti_on_off,
14799                 NULL,
14800         },
14801 };
14802
14803 /* vf broadcast mode configuration */
14804
14805 /* Common result structure for vf broadcast */
14806 struct cmd_set_vf_broadcast_result {
14807         cmdline_fixed_string_t set;
14808         cmdline_fixed_string_t vf;
14809         cmdline_fixed_string_t broadcast;
14810         portid_t port_id;
14811         uint16_t vf_id;
14812         cmdline_fixed_string_t on_off;
14813 };
14814
14815 /* Common CLI fields for vf broadcast enable disable */
14816 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14817         TOKEN_STRING_INITIALIZER
14818                 (struct cmd_set_vf_broadcast_result,
14819                  set, "set");
14820 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14821         TOKEN_STRING_INITIALIZER
14822                 (struct cmd_set_vf_broadcast_result,
14823                  vf, "vf");
14824 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14825         TOKEN_STRING_INITIALIZER
14826                 (struct cmd_set_vf_broadcast_result,
14827                  broadcast, "broadcast");
14828 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14829         TOKEN_NUM_INITIALIZER
14830                 (struct cmd_set_vf_broadcast_result,
14831                  port_id, UINT16);
14832 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14833         TOKEN_NUM_INITIALIZER
14834                 (struct cmd_set_vf_broadcast_result,
14835                  vf_id, UINT16);
14836 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14837         TOKEN_STRING_INITIALIZER
14838                 (struct cmd_set_vf_broadcast_result,
14839                  on_off, "on#off");
14840
14841 static void
14842 cmd_set_vf_broadcast_parsed(
14843         void *parsed_result,
14844         __rte_unused struct cmdline *cl,
14845         __rte_unused void *data)
14846 {
14847         struct cmd_set_vf_broadcast_result *res = parsed_result;
14848         int ret = -ENOTSUP;
14849
14850         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14851
14852         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14853                 return;
14854
14855 #ifdef RTE_LIBRTE_I40E_PMD
14856         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14857                                             res->vf_id, is_on);
14858 #endif
14859
14860         switch (ret) {
14861         case 0:
14862                 break;
14863         case -EINVAL:
14864                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14865                 break;
14866         case -ENODEV:
14867                 printf("invalid port_id %d\n", res->port_id);
14868                 break;
14869         case -ENOTSUP:
14870                 printf("function not implemented\n");
14871                 break;
14872         default:
14873                 printf("programming error: (%s)\n", strerror(-ret));
14874         }
14875 }
14876
14877 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14878         .f = cmd_set_vf_broadcast_parsed,
14879         .data = NULL,
14880         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14881         .tokens = {
14882                 (void *)&cmd_set_vf_broadcast_set,
14883                 (void *)&cmd_set_vf_broadcast_vf,
14884                 (void *)&cmd_set_vf_broadcast_broadcast,
14885                 (void *)&cmd_set_vf_broadcast_port_id,
14886                 (void *)&cmd_set_vf_broadcast_vf_id,
14887                 (void *)&cmd_set_vf_broadcast_on_off,
14888                 NULL,
14889         },
14890 };
14891
14892 /* vf vlan tag configuration */
14893
14894 /* Common result structure for vf vlan tag */
14895 struct cmd_set_vf_vlan_tag_result {
14896         cmdline_fixed_string_t set;
14897         cmdline_fixed_string_t vf;
14898         cmdline_fixed_string_t vlan;
14899         cmdline_fixed_string_t tag;
14900         portid_t port_id;
14901         uint16_t vf_id;
14902         cmdline_fixed_string_t on_off;
14903 };
14904
14905 /* Common CLI fields for vf vlan tag enable disable */
14906 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14907         TOKEN_STRING_INITIALIZER
14908                 (struct cmd_set_vf_vlan_tag_result,
14909                  set, "set");
14910 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14911         TOKEN_STRING_INITIALIZER
14912                 (struct cmd_set_vf_vlan_tag_result,
14913                  vf, "vf");
14914 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14915         TOKEN_STRING_INITIALIZER
14916                 (struct cmd_set_vf_vlan_tag_result,
14917                  vlan, "vlan");
14918 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14919         TOKEN_STRING_INITIALIZER
14920                 (struct cmd_set_vf_vlan_tag_result,
14921                  tag, "tag");
14922 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14923         TOKEN_NUM_INITIALIZER
14924                 (struct cmd_set_vf_vlan_tag_result,
14925                  port_id, UINT16);
14926 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14927         TOKEN_NUM_INITIALIZER
14928                 (struct cmd_set_vf_vlan_tag_result,
14929                  vf_id, UINT16);
14930 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14931         TOKEN_STRING_INITIALIZER
14932                 (struct cmd_set_vf_vlan_tag_result,
14933                  on_off, "on#off");
14934
14935 static void
14936 cmd_set_vf_vlan_tag_parsed(
14937         void *parsed_result,
14938         __rte_unused struct cmdline *cl,
14939         __rte_unused void *data)
14940 {
14941         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14942         int ret = -ENOTSUP;
14943
14944         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14945
14946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14947                 return;
14948
14949 #ifdef RTE_LIBRTE_I40E_PMD
14950         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14951                                            res->vf_id, is_on);
14952 #endif
14953
14954         switch (ret) {
14955         case 0:
14956                 break;
14957         case -EINVAL:
14958                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14959                 break;
14960         case -ENODEV:
14961                 printf("invalid port_id %d\n", res->port_id);
14962                 break;
14963         case -ENOTSUP:
14964                 printf("function not implemented\n");
14965                 break;
14966         default:
14967                 printf("programming error: (%s)\n", strerror(-ret));
14968         }
14969 }
14970
14971 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14972         .f = cmd_set_vf_vlan_tag_parsed,
14973         .data = NULL,
14974         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14975         .tokens = {
14976                 (void *)&cmd_set_vf_vlan_tag_set,
14977                 (void *)&cmd_set_vf_vlan_tag_vf,
14978                 (void *)&cmd_set_vf_vlan_tag_vlan,
14979                 (void *)&cmd_set_vf_vlan_tag_tag,
14980                 (void *)&cmd_set_vf_vlan_tag_port_id,
14981                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14982                 (void *)&cmd_set_vf_vlan_tag_on_off,
14983                 NULL,
14984         },
14985 };
14986
14987 /* Common definition of VF and TC TX bandwidth configuration */
14988 struct cmd_vf_tc_bw_result {
14989         cmdline_fixed_string_t set;
14990         cmdline_fixed_string_t vf;
14991         cmdline_fixed_string_t tc;
14992         cmdline_fixed_string_t tx;
14993         cmdline_fixed_string_t min_bw;
14994         cmdline_fixed_string_t max_bw;
14995         cmdline_fixed_string_t strict_link_prio;
14996         portid_t port_id;
14997         uint16_t vf_id;
14998         uint8_t tc_no;
14999         uint32_t bw;
15000         cmdline_fixed_string_t bw_list;
15001         uint8_t tc_map;
15002 };
15003
15004 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_vf_tc_bw_result,
15007                  set, "set");
15008 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_vf_tc_bw_result,
15011                  vf, "vf");
15012 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_vf_tc_bw_result,
15015                  tc, "tc");
15016 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15017         TOKEN_STRING_INITIALIZER
15018                 (struct cmd_vf_tc_bw_result,
15019                  tx, "tx");
15020 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15021         TOKEN_STRING_INITIALIZER
15022                 (struct cmd_vf_tc_bw_result,
15023                  strict_link_prio, "strict-link-priority");
15024 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15025         TOKEN_STRING_INITIALIZER
15026                 (struct cmd_vf_tc_bw_result,
15027                  min_bw, "min-bandwidth");
15028 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15029         TOKEN_STRING_INITIALIZER
15030                 (struct cmd_vf_tc_bw_result,
15031                  max_bw, "max-bandwidth");
15032 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15033         TOKEN_NUM_INITIALIZER
15034                 (struct cmd_vf_tc_bw_result,
15035                  port_id, UINT16);
15036 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15037         TOKEN_NUM_INITIALIZER
15038                 (struct cmd_vf_tc_bw_result,
15039                  vf_id, UINT16);
15040 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15041         TOKEN_NUM_INITIALIZER
15042                 (struct cmd_vf_tc_bw_result,
15043                  tc_no, UINT8);
15044 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15045         TOKEN_NUM_INITIALIZER
15046                 (struct cmd_vf_tc_bw_result,
15047                  bw, UINT32);
15048 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15049         TOKEN_STRING_INITIALIZER
15050                 (struct cmd_vf_tc_bw_result,
15051                  bw_list, NULL);
15052 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15053         TOKEN_NUM_INITIALIZER
15054                 (struct cmd_vf_tc_bw_result,
15055                  tc_map, UINT8);
15056
15057 /* VF max bandwidth setting */
15058 static void
15059 cmd_vf_max_bw_parsed(
15060         void *parsed_result,
15061         __rte_unused struct cmdline *cl,
15062         __rte_unused void *data)
15063 {
15064         struct cmd_vf_tc_bw_result *res = parsed_result;
15065         int ret = -ENOTSUP;
15066
15067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15068                 return;
15069
15070 #ifdef RTE_LIBRTE_I40E_PMD
15071         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15072                                          res->vf_id, res->bw);
15073 #endif
15074
15075         switch (ret) {
15076         case 0:
15077                 break;
15078         case -EINVAL:
15079                 printf("invalid vf_id %d or bandwidth %d\n",
15080                        res->vf_id, res->bw);
15081                 break;
15082         case -ENODEV:
15083                 printf("invalid port_id %d\n", res->port_id);
15084                 break;
15085         case -ENOTSUP:
15086                 printf("function not implemented\n");
15087                 break;
15088         default:
15089                 printf("programming error: (%s)\n", strerror(-ret));
15090         }
15091 }
15092
15093 cmdline_parse_inst_t cmd_vf_max_bw = {
15094         .f = cmd_vf_max_bw_parsed,
15095         .data = NULL,
15096         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15097         .tokens = {
15098                 (void *)&cmd_vf_tc_bw_set,
15099                 (void *)&cmd_vf_tc_bw_vf,
15100                 (void *)&cmd_vf_tc_bw_tx,
15101                 (void *)&cmd_vf_tc_bw_max_bw,
15102                 (void *)&cmd_vf_tc_bw_port_id,
15103                 (void *)&cmd_vf_tc_bw_vf_id,
15104                 (void *)&cmd_vf_tc_bw_bw,
15105                 NULL,
15106         },
15107 };
15108
15109 static int
15110 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15111                            uint8_t *tc_num,
15112                            char *str)
15113 {
15114         uint32_t size;
15115         const char *p, *p0 = str;
15116         char s[256];
15117         char *end;
15118         char *str_fld[16];
15119         uint16_t i;
15120         int ret;
15121
15122         p = strchr(p0, '(');
15123         if (p == NULL) {
15124                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15125                 return -1;
15126         }
15127         p++;
15128         p0 = strchr(p, ')');
15129         if (p0 == NULL) {
15130                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15131                 return -1;
15132         }
15133         size = p0 - p;
15134         if (size >= sizeof(s)) {
15135                 printf("The string size exceeds the internal buffer size\n");
15136                 return -1;
15137         }
15138         snprintf(s, sizeof(s), "%.*s", size, p);
15139         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15140         if (ret <= 0) {
15141                 printf("Failed to get the bandwidth list. ");
15142                 return -1;
15143         }
15144         *tc_num = ret;
15145         for (i = 0; i < ret; i++)
15146                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15147
15148         return 0;
15149 }
15150
15151 /* TC min bandwidth setting */
15152 static void
15153 cmd_vf_tc_min_bw_parsed(
15154         void *parsed_result,
15155         __rte_unused struct cmdline *cl,
15156         __rte_unused void *data)
15157 {
15158         struct cmd_vf_tc_bw_result *res = parsed_result;
15159         uint8_t tc_num;
15160         uint8_t bw[16];
15161         int ret = -ENOTSUP;
15162
15163         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15164                 return;
15165
15166         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15167         if (ret)
15168                 return;
15169
15170 #ifdef RTE_LIBRTE_I40E_PMD
15171         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15172                                               tc_num, bw);
15173 #endif
15174
15175         switch (ret) {
15176         case 0:
15177                 break;
15178         case -EINVAL:
15179                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15180                 break;
15181         case -ENODEV:
15182                 printf("invalid port_id %d\n", res->port_id);
15183                 break;
15184         case -ENOTSUP:
15185                 printf("function not implemented\n");
15186                 break;
15187         default:
15188                 printf("programming error: (%s)\n", strerror(-ret));
15189         }
15190 }
15191
15192 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15193         .f = cmd_vf_tc_min_bw_parsed,
15194         .data = NULL,
15195         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15196                     " <bw1, bw2, ...>",
15197         .tokens = {
15198                 (void *)&cmd_vf_tc_bw_set,
15199                 (void *)&cmd_vf_tc_bw_vf,
15200                 (void *)&cmd_vf_tc_bw_tc,
15201                 (void *)&cmd_vf_tc_bw_tx,
15202                 (void *)&cmd_vf_tc_bw_min_bw,
15203                 (void *)&cmd_vf_tc_bw_port_id,
15204                 (void *)&cmd_vf_tc_bw_vf_id,
15205                 (void *)&cmd_vf_tc_bw_bw_list,
15206                 NULL,
15207         },
15208 };
15209
15210 static void
15211 cmd_tc_min_bw_parsed(
15212         void *parsed_result,
15213         __rte_unused struct cmdline *cl,
15214         __rte_unused void *data)
15215 {
15216         struct cmd_vf_tc_bw_result *res = parsed_result;
15217         struct rte_port *port;
15218         uint8_t tc_num;
15219         uint8_t bw[16];
15220         int ret = -ENOTSUP;
15221
15222         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15223                 return;
15224
15225         port = &ports[res->port_id];
15226         /** Check if the port is not started **/
15227         if (port->port_status != RTE_PORT_STOPPED) {
15228                 printf("Please stop port %d first\n", res->port_id);
15229                 return;
15230         }
15231
15232         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15233         if (ret)
15234                 return;
15235
15236 #ifdef RTE_LIBRTE_IXGBE_PMD
15237         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15238 #endif
15239
15240         switch (ret) {
15241         case 0:
15242                 break;
15243         case -EINVAL:
15244                 printf("invalid bandwidth\n");
15245                 break;
15246         case -ENODEV:
15247                 printf("invalid port_id %d\n", res->port_id);
15248                 break;
15249         case -ENOTSUP:
15250                 printf("function not implemented\n");
15251                 break;
15252         default:
15253                 printf("programming error: (%s)\n", strerror(-ret));
15254         }
15255 }
15256
15257 cmdline_parse_inst_t cmd_tc_min_bw = {
15258         .f = cmd_tc_min_bw_parsed,
15259         .data = NULL,
15260         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15261         .tokens = {
15262                 (void *)&cmd_vf_tc_bw_set,
15263                 (void *)&cmd_vf_tc_bw_tc,
15264                 (void *)&cmd_vf_tc_bw_tx,
15265                 (void *)&cmd_vf_tc_bw_min_bw,
15266                 (void *)&cmd_vf_tc_bw_port_id,
15267                 (void *)&cmd_vf_tc_bw_bw_list,
15268                 NULL,
15269         },
15270 };
15271
15272 /* TC max bandwidth setting */
15273 static void
15274 cmd_vf_tc_max_bw_parsed(
15275         void *parsed_result,
15276         __rte_unused struct cmdline *cl,
15277         __rte_unused void *data)
15278 {
15279         struct cmd_vf_tc_bw_result *res = parsed_result;
15280         int ret = -ENOTSUP;
15281
15282         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15283                 return;
15284
15285 #ifdef RTE_LIBRTE_I40E_PMD
15286         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15287                                             res->tc_no, res->bw);
15288 #endif
15289
15290         switch (ret) {
15291         case 0:
15292                 break;
15293         case -EINVAL:
15294                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15295                        res->vf_id, res->tc_no, res->bw);
15296                 break;
15297         case -ENODEV:
15298                 printf("invalid port_id %d\n", res->port_id);
15299                 break;
15300         case -ENOTSUP:
15301                 printf("function not implemented\n");
15302                 break;
15303         default:
15304                 printf("programming error: (%s)\n", strerror(-ret));
15305         }
15306 }
15307
15308 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15309         .f = cmd_vf_tc_max_bw_parsed,
15310         .data = NULL,
15311         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15312                     " <bandwidth>",
15313         .tokens = {
15314                 (void *)&cmd_vf_tc_bw_set,
15315                 (void *)&cmd_vf_tc_bw_vf,
15316                 (void *)&cmd_vf_tc_bw_tc,
15317                 (void *)&cmd_vf_tc_bw_tx,
15318                 (void *)&cmd_vf_tc_bw_max_bw,
15319                 (void *)&cmd_vf_tc_bw_port_id,
15320                 (void *)&cmd_vf_tc_bw_vf_id,
15321                 (void *)&cmd_vf_tc_bw_tc_no,
15322                 (void *)&cmd_vf_tc_bw_bw,
15323                 NULL,
15324         },
15325 };
15326
15327
15328 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15329
15330 /* *** Set Port default Traffic Management Hierarchy *** */
15331 struct cmd_set_port_tm_hierarchy_default_result {
15332         cmdline_fixed_string_t set;
15333         cmdline_fixed_string_t port;
15334         cmdline_fixed_string_t tm;
15335         cmdline_fixed_string_t hierarchy;
15336         cmdline_fixed_string_t def;
15337         portid_t port_id;
15338 };
15339
15340 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15341         TOKEN_STRING_INITIALIZER(
15342                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15343 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15344         TOKEN_STRING_INITIALIZER(
15345                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15346 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15347         TOKEN_STRING_INITIALIZER(
15348                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15349 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15350         TOKEN_STRING_INITIALIZER(
15351                 struct cmd_set_port_tm_hierarchy_default_result,
15352                         hierarchy, "hierarchy");
15353 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15354         TOKEN_STRING_INITIALIZER(
15355                 struct cmd_set_port_tm_hierarchy_default_result,
15356                         def, "default");
15357 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15358         TOKEN_NUM_INITIALIZER(
15359                 struct cmd_set_port_tm_hierarchy_default_result,
15360                         port_id, UINT16);
15361
15362 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15363         __rte_unused struct cmdline *cl,
15364         __rte_unused void *data)
15365 {
15366         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15367         struct rte_port *p;
15368         portid_t port_id = res->port_id;
15369
15370         if (port_id_is_invalid(port_id, ENABLED_WARN))
15371                 return;
15372
15373         p = &ports[port_id];
15374
15375         /* Forward mode: tm */
15376         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15377                 printf("  softnicfwd mode not enabled(error)\n");
15378                 return;
15379         }
15380
15381         /* Set the default tm hierarchy */
15382         p->softport.default_tm_hierarchy_enable = 1;
15383 }
15384
15385 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15386         .f = cmd_set_port_tm_hierarchy_default_parsed,
15387         .data = NULL,
15388         .help_str = "set port tm hierarchy default <port_id>",
15389         .tokens = {
15390                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15391                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15392                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15393                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15394                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15395                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15396                 NULL,
15397         },
15398 };
15399 #endif
15400
15401 /** Set VXLAN encapsulation details */
15402 struct cmd_set_vxlan_result {
15403         cmdline_fixed_string_t set;
15404         cmdline_fixed_string_t vxlan;
15405         cmdline_fixed_string_t pos_token;
15406         cmdline_fixed_string_t ip_version;
15407         uint32_t vlan_present:1;
15408         uint32_t vni;
15409         uint16_t udp_src;
15410         uint16_t udp_dst;
15411         cmdline_ipaddr_t ip_src;
15412         cmdline_ipaddr_t ip_dst;
15413         uint16_t tci;
15414         uint8_t tos;
15415         uint8_t ttl;
15416         struct rte_ether_addr eth_src;
15417         struct rte_ether_addr eth_dst;
15418 };
15419
15420 cmdline_parse_token_string_t cmd_set_vxlan_set =
15421         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15422 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15423         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15424 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15425         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15426                                  "vxlan-tos-ttl");
15427 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15428         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15429                                  "vxlan-with-vlan");
15430 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15431         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15432                                  "ip-version");
15433 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15434         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15435                                  "ipv4#ipv6");
15436 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15437         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15438                                  "vni");
15439 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15440         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15441 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15442         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15443                                  "udp-src");
15444 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15445         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15446 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15447         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15448                                  "udp-dst");
15449 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15450         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15451 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15453                                  "ip-tos");
15454 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15455         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15456 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15457         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15458                                  "ip-ttl");
15459 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15460         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15461 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15462         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15463                                  "ip-src");
15464 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15465         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15466 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15467         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15468                                  "ip-dst");
15469 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15470         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15471 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15472         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15473                                  "vlan-tci");
15474 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15475         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15476 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15477         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15478                                  "eth-src");
15479 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15480         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15481 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15482         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15483                                  "eth-dst");
15484 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15485         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15486
15487 static void cmd_set_vxlan_parsed(void *parsed_result,
15488         __rte_unused struct cmdline *cl,
15489         __rte_unused void *data)
15490 {
15491         struct cmd_set_vxlan_result *res = parsed_result;
15492         union {
15493                 uint32_t vxlan_id;
15494                 uint8_t vni[4];
15495         } id = {
15496                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15497         };
15498
15499         vxlan_encap_conf.select_tos_ttl = 0;
15500         if (strcmp(res->vxlan, "vxlan") == 0)
15501                 vxlan_encap_conf.select_vlan = 0;
15502         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15503                 vxlan_encap_conf.select_vlan = 1;
15504         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15505                 vxlan_encap_conf.select_vlan = 0;
15506                 vxlan_encap_conf.select_tos_ttl = 1;
15507         }
15508         if (strcmp(res->ip_version, "ipv4") == 0)
15509                 vxlan_encap_conf.select_ipv4 = 1;
15510         else if (strcmp(res->ip_version, "ipv6") == 0)
15511                 vxlan_encap_conf.select_ipv4 = 0;
15512         else
15513                 return;
15514         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15515         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15516         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15517         vxlan_encap_conf.ip_tos = res->tos;
15518         vxlan_encap_conf.ip_ttl = res->ttl;
15519         if (vxlan_encap_conf.select_ipv4) {
15520                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15521                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15522         } else {
15523                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15524                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15525         }
15526         if (vxlan_encap_conf.select_vlan)
15527                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15528         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15529                    RTE_ETHER_ADDR_LEN);
15530         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15531                    RTE_ETHER_ADDR_LEN);
15532 }
15533
15534 cmdline_parse_inst_t cmd_set_vxlan = {
15535         .f = cmd_set_vxlan_parsed,
15536         .data = NULL,
15537         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15538                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15539                 " eth-src <eth-src> eth-dst <eth-dst>",
15540         .tokens = {
15541                 (void *)&cmd_set_vxlan_set,
15542                 (void *)&cmd_set_vxlan_vxlan,
15543                 (void *)&cmd_set_vxlan_ip_version,
15544                 (void *)&cmd_set_vxlan_ip_version_value,
15545                 (void *)&cmd_set_vxlan_vni,
15546                 (void *)&cmd_set_vxlan_vni_value,
15547                 (void *)&cmd_set_vxlan_udp_src,
15548                 (void *)&cmd_set_vxlan_udp_src_value,
15549                 (void *)&cmd_set_vxlan_udp_dst,
15550                 (void *)&cmd_set_vxlan_udp_dst_value,
15551                 (void *)&cmd_set_vxlan_ip_src,
15552                 (void *)&cmd_set_vxlan_ip_src_value,
15553                 (void *)&cmd_set_vxlan_ip_dst,
15554                 (void *)&cmd_set_vxlan_ip_dst_value,
15555                 (void *)&cmd_set_vxlan_eth_src,
15556                 (void *)&cmd_set_vxlan_eth_src_value,
15557                 (void *)&cmd_set_vxlan_eth_dst,
15558                 (void *)&cmd_set_vxlan_eth_dst_value,
15559                 NULL,
15560         },
15561 };
15562
15563 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15564         .f = cmd_set_vxlan_parsed,
15565         .data = NULL,
15566         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15567                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15568                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15569                 " eth-dst <eth-dst>",
15570         .tokens = {
15571                 (void *)&cmd_set_vxlan_set,
15572                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15573                 (void *)&cmd_set_vxlan_ip_version,
15574                 (void *)&cmd_set_vxlan_ip_version_value,
15575                 (void *)&cmd_set_vxlan_vni,
15576                 (void *)&cmd_set_vxlan_vni_value,
15577                 (void *)&cmd_set_vxlan_udp_src,
15578                 (void *)&cmd_set_vxlan_udp_src_value,
15579                 (void *)&cmd_set_vxlan_udp_dst,
15580                 (void *)&cmd_set_vxlan_udp_dst_value,
15581                 (void *)&cmd_set_vxlan_ip_tos,
15582                 (void *)&cmd_set_vxlan_ip_tos_value,
15583                 (void *)&cmd_set_vxlan_ip_ttl,
15584                 (void *)&cmd_set_vxlan_ip_ttl_value,
15585                 (void *)&cmd_set_vxlan_ip_src,
15586                 (void *)&cmd_set_vxlan_ip_src_value,
15587                 (void *)&cmd_set_vxlan_ip_dst,
15588                 (void *)&cmd_set_vxlan_ip_dst_value,
15589                 (void *)&cmd_set_vxlan_eth_src,
15590                 (void *)&cmd_set_vxlan_eth_src_value,
15591                 (void *)&cmd_set_vxlan_eth_dst,
15592                 (void *)&cmd_set_vxlan_eth_dst_value,
15593                 NULL,
15594         },
15595 };
15596
15597 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15598         .f = cmd_set_vxlan_parsed,
15599         .data = NULL,
15600         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15601                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15602                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15603                 " <eth-dst>",
15604         .tokens = {
15605                 (void *)&cmd_set_vxlan_set,
15606                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15607                 (void *)&cmd_set_vxlan_ip_version,
15608                 (void *)&cmd_set_vxlan_ip_version_value,
15609                 (void *)&cmd_set_vxlan_vni,
15610                 (void *)&cmd_set_vxlan_vni_value,
15611                 (void *)&cmd_set_vxlan_udp_src,
15612                 (void *)&cmd_set_vxlan_udp_src_value,
15613                 (void *)&cmd_set_vxlan_udp_dst,
15614                 (void *)&cmd_set_vxlan_udp_dst_value,
15615                 (void *)&cmd_set_vxlan_ip_src,
15616                 (void *)&cmd_set_vxlan_ip_src_value,
15617                 (void *)&cmd_set_vxlan_ip_dst,
15618                 (void *)&cmd_set_vxlan_ip_dst_value,
15619                 (void *)&cmd_set_vxlan_vlan,
15620                 (void *)&cmd_set_vxlan_vlan_value,
15621                 (void *)&cmd_set_vxlan_eth_src,
15622                 (void *)&cmd_set_vxlan_eth_src_value,
15623                 (void *)&cmd_set_vxlan_eth_dst,
15624                 (void *)&cmd_set_vxlan_eth_dst_value,
15625                 NULL,
15626         },
15627 };
15628
15629 /** Set NVGRE encapsulation details */
15630 struct cmd_set_nvgre_result {
15631         cmdline_fixed_string_t set;
15632         cmdline_fixed_string_t nvgre;
15633         cmdline_fixed_string_t pos_token;
15634         cmdline_fixed_string_t ip_version;
15635         uint32_t tni;
15636         cmdline_ipaddr_t ip_src;
15637         cmdline_ipaddr_t ip_dst;
15638         uint16_t tci;
15639         struct rte_ether_addr eth_src;
15640         struct rte_ether_addr eth_dst;
15641 };
15642
15643 cmdline_parse_token_string_t cmd_set_nvgre_set =
15644         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15645 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15647 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15648         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15649                                  "nvgre-with-vlan");
15650 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15651         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15652                                  "ip-version");
15653 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15654         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15655                                  "ipv4#ipv6");
15656 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15657         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15658                                  "tni");
15659 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15660         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15661 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15662         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15663                                  "ip-src");
15664 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15665         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15666 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15667         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15668                                  "ip-dst");
15669 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15670         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15671 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15672         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15673                                  "vlan-tci");
15674 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15675         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15676 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15677         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15678                                  "eth-src");
15679 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15680         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15681 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15682         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15683                                  "eth-dst");
15684 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15685         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15686
15687 static void cmd_set_nvgre_parsed(void *parsed_result,
15688         __rte_unused struct cmdline *cl,
15689         __rte_unused void *data)
15690 {
15691         struct cmd_set_nvgre_result *res = parsed_result;
15692         union {
15693                 uint32_t nvgre_tni;
15694                 uint8_t tni[4];
15695         } id = {
15696                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15697         };
15698
15699         if (strcmp(res->nvgre, "nvgre") == 0)
15700                 nvgre_encap_conf.select_vlan = 0;
15701         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15702                 nvgre_encap_conf.select_vlan = 1;
15703         if (strcmp(res->ip_version, "ipv4") == 0)
15704                 nvgre_encap_conf.select_ipv4 = 1;
15705         else if (strcmp(res->ip_version, "ipv6") == 0)
15706                 nvgre_encap_conf.select_ipv4 = 0;
15707         else
15708                 return;
15709         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15710         if (nvgre_encap_conf.select_ipv4) {
15711                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15712                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15713         } else {
15714                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15715                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15716         }
15717         if (nvgre_encap_conf.select_vlan)
15718                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15719         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15720                    RTE_ETHER_ADDR_LEN);
15721         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15722                    RTE_ETHER_ADDR_LEN);
15723 }
15724
15725 cmdline_parse_inst_t cmd_set_nvgre = {
15726         .f = cmd_set_nvgre_parsed,
15727         .data = NULL,
15728         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15729                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15730                 " eth-dst <eth-dst>",
15731         .tokens = {
15732                 (void *)&cmd_set_nvgre_set,
15733                 (void *)&cmd_set_nvgre_nvgre,
15734                 (void *)&cmd_set_nvgre_ip_version,
15735                 (void *)&cmd_set_nvgre_ip_version_value,
15736                 (void *)&cmd_set_nvgre_tni,
15737                 (void *)&cmd_set_nvgre_tni_value,
15738                 (void *)&cmd_set_nvgre_ip_src,
15739                 (void *)&cmd_set_nvgre_ip_src_value,
15740                 (void *)&cmd_set_nvgre_ip_dst,
15741                 (void *)&cmd_set_nvgre_ip_dst_value,
15742                 (void *)&cmd_set_nvgre_eth_src,
15743                 (void *)&cmd_set_nvgre_eth_src_value,
15744                 (void *)&cmd_set_nvgre_eth_dst,
15745                 (void *)&cmd_set_nvgre_eth_dst_value,
15746                 NULL,
15747         },
15748 };
15749
15750 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15751         .f = cmd_set_nvgre_parsed,
15752         .data = NULL,
15753         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15754                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15755                 " eth-src <eth-src> eth-dst <eth-dst>",
15756         .tokens = {
15757                 (void *)&cmd_set_nvgre_set,
15758                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15759                 (void *)&cmd_set_nvgre_ip_version,
15760                 (void *)&cmd_set_nvgre_ip_version_value,
15761                 (void *)&cmd_set_nvgre_tni,
15762                 (void *)&cmd_set_nvgre_tni_value,
15763                 (void *)&cmd_set_nvgre_ip_src,
15764                 (void *)&cmd_set_nvgre_ip_src_value,
15765                 (void *)&cmd_set_nvgre_ip_dst,
15766                 (void *)&cmd_set_nvgre_ip_dst_value,
15767                 (void *)&cmd_set_nvgre_vlan,
15768                 (void *)&cmd_set_nvgre_vlan_value,
15769                 (void *)&cmd_set_nvgre_eth_src,
15770                 (void *)&cmd_set_nvgre_eth_src_value,
15771                 (void *)&cmd_set_nvgre_eth_dst,
15772                 (void *)&cmd_set_nvgre_eth_dst_value,
15773                 NULL,
15774         },
15775 };
15776
15777 /** Set L2 encapsulation details */
15778 struct cmd_set_l2_encap_result {
15779         cmdline_fixed_string_t set;
15780         cmdline_fixed_string_t l2_encap;
15781         cmdline_fixed_string_t pos_token;
15782         cmdline_fixed_string_t ip_version;
15783         uint32_t vlan_present:1;
15784         uint16_t tci;
15785         struct rte_ether_addr eth_src;
15786         struct rte_ether_addr eth_dst;
15787 };
15788
15789 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15791 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15792         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15793 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15795                                  "l2_encap-with-vlan");
15796 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15797         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15798                                  "ip-version");
15799 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15800         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15801                                  "ipv4#ipv6");
15802 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15803         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15804                                  "vlan-tci");
15805 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15806         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15807 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15808         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15809                                  "eth-src");
15810 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15811         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15812 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15813         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15814                                  "eth-dst");
15815 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15816         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15817
15818 static void cmd_set_l2_encap_parsed(void *parsed_result,
15819         __rte_unused struct cmdline *cl,
15820         __rte_unused void *data)
15821 {
15822         struct cmd_set_l2_encap_result *res = parsed_result;
15823
15824         if (strcmp(res->l2_encap, "l2_encap") == 0)
15825                 l2_encap_conf.select_vlan = 0;
15826         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15827                 l2_encap_conf.select_vlan = 1;
15828         if (strcmp(res->ip_version, "ipv4") == 0)
15829                 l2_encap_conf.select_ipv4 = 1;
15830         else if (strcmp(res->ip_version, "ipv6") == 0)
15831                 l2_encap_conf.select_ipv4 = 0;
15832         else
15833                 return;
15834         if (l2_encap_conf.select_vlan)
15835                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15836         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15837                    RTE_ETHER_ADDR_LEN);
15838         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15839                    RTE_ETHER_ADDR_LEN);
15840 }
15841
15842 cmdline_parse_inst_t cmd_set_l2_encap = {
15843         .f = cmd_set_l2_encap_parsed,
15844         .data = NULL,
15845         .help_str = "set l2_encap ip-version ipv4|ipv6"
15846                 " eth-src <eth-src> eth-dst <eth-dst>",
15847         .tokens = {
15848                 (void *)&cmd_set_l2_encap_set,
15849                 (void *)&cmd_set_l2_encap_l2_encap,
15850                 (void *)&cmd_set_l2_encap_ip_version,
15851                 (void *)&cmd_set_l2_encap_ip_version_value,
15852                 (void *)&cmd_set_l2_encap_eth_src,
15853                 (void *)&cmd_set_l2_encap_eth_src_value,
15854                 (void *)&cmd_set_l2_encap_eth_dst,
15855                 (void *)&cmd_set_l2_encap_eth_dst_value,
15856                 NULL,
15857         },
15858 };
15859
15860 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15861         .f = cmd_set_l2_encap_parsed,
15862         .data = NULL,
15863         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15864                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15865         .tokens = {
15866                 (void *)&cmd_set_l2_encap_set,
15867                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15868                 (void *)&cmd_set_l2_encap_ip_version,
15869                 (void *)&cmd_set_l2_encap_ip_version_value,
15870                 (void *)&cmd_set_l2_encap_vlan,
15871                 (void *)&cmd_set_l2_encap_vlan_value,
15872                 (void *)&cmd_set_l2_encap_eth_src,
15873                 (void *)&cmd_set_l2_encap_eth_src_value,
15874                 (void *)&cmd_set_l2_encap_eth_dst,
15875                 (void *)&cmd_set_l2_encap_eth_dst_value,
15876                 NULL,
15877         },
15878 };
15879
15880 /** Set L2 decapsulation details */
15881 struct cmd_set_l2_decap_result {
15882         cmdline_fixed_string_t set;
15883         cmdline_fixed_string_t l2_decap;
15884         cmdline_fixed_string_t pos_token;
15885         uint32_t vlan_present:1;
15886 };
15887
15888 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15889         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15890 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15892                                  "l2_decap");
15893 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15894         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15895                                  "l2_decap-with-vlan");
15896
15897 static void cmd_set_l2_decap_parsed(void *parsed_result,
15898         __rte_unused struct cmdline *cl,
15899         __rte_unused void *data)
15900 {
15901         struct cmd_set_l2_decap_result *res = parsed_result;
15902
15903         if (strcmp(res->l2_decap, "l2_decap") == 0)
15904                 l2_decap_conf.select_vlan = 0;
15905         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15906                 l2_decap_conf.select_vlan = 1;
15907 }
15908
15909 cmdline_parse_inst_t cmd_set_l2_decap = {
15910         .f = cmd_set_l2_decap_parsed,
15911         .data = NULL,
15912         .help_str = "set l2_decap",
15913         .tokens = {
15914                 (void *)&cmd_set_l2_decap_set,
15915                 (void *)&cmd_set_l2_decap_l2_decap,
15916                 NULL,
15917         },
15918 };
15919
15920 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15921         .f = cmd_set_l2_decap_parsed,
15922         .data = NULL,
15923         .help_str = "set l2_decap-with-vlan",
15924         .tokens = {
15925                 (void *)&cmd_set_l2_decap_set,
15926                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15927                 NULL,
15928         },
15929 };
15930
15931 /** Set MPLSoGRE encapsulation details */
15932 struct cmd_set_mplsogre_encap_result {
15933         cmdline_fixed_string_t set;
15934         cmdline_fixed_string_t mplsogre;
15935         cmdline_fixed_string_t pos_token;
15936         cmdline_fixed_string_t ip_version;
15937         uint32_t vlan_present:1;
15938         uint32_t label;
15939         cmdline_ipaddr_t ip_src;
15940         cmdline_ipaddr_t ip_dst;
15941         uint16_t tci;
15942         struct rte_ether_addr eth_src;
15943         struct rte_ether_addr eth_dst;
15944 };
15945
15946 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15947         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15948                                  "set");
15949 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15950         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15951                                  "mplsogre_encap");
15952 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15953         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15954                                  mplsogre, "mplsogre_encap-with-vlan");
15955 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15956         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15957                                  pos_token, "ip-version");
15958 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15959         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15960                                  ip_version, "ipv4#ipv6");
15961 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15962         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15963                                  pos_token, "label");
15964 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15965         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15966                               UINT32);
15967 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15968         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15969                                  pos_token, "ip-src");
15970 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15971         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15972 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15973         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15974                                  pos_token, "ip-dst");
15975 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15976         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15977 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15979                                  pos_token, "vlan-tci");
15980 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15981         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15982                               UINT16);
15983 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15985                                  pos_token, "eth-src");
15986 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15987         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15988                                     eth_src);
15989 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15990         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15991                                  pos_token, "eth-dst");
15992 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15993         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15994                                     eth_dst);
15995
15996 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15997         __rte_unused struct cmdline *cl,
15998         __rte_unused void *data)
15999 {
16000         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16001         union {
16002                 uint32_t mplsogre_label;
16003                 uint8_t label[4];
16004         } id = {
16005                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16006         };
16007
16008         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16009                 mplsogre_encap_conf.select_vlan = 0;
16010         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16011                 mplsogre_encap_conf.select_vlan = 1;
16012         if (strcmp(res->ip_version, "ipv4") == 0)
16013                 mplsogre_encap_conf.select_ipv4 = 1;
16014         else if (strcmp(res->ip_version, "ipv6") == 0)
16015                 mplsogre_encap_conf.select_ipv4 = 0;
16016         else
16017                 return;
16018         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16019         if (mplsogre_encap_conf.select_ipv4) {
16020                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16021                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16022         } else {
16023                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16024                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16025         }
16026         if (mplsogre_encap_conf.select_vlan)
16027                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16028         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16029                    RTE_ETHER_ADDR_LEN);
16030         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16031                    RTE_ETHER_ADDR_LEN);
16032 }
16033
16034 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16035         .f = cmd_set_mplsogre_encap_parsed,
16036         .data = NULL,
16037         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16038                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16039                 " eth-dst <eth-dst>",
16040         .tokens = {
16041                 (void *)&cmd_set_mplsogre_encap_set,
16042                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16043                 (void *)&cmd_set_mplsogre_encap_ip_version,
16044                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16045                 (void *)&cmd_set_mplsogre_encap_label,
16046                 (void *)&cmd_set_mplsogre_encap_label_value,
16047                 (void *)&cmd_set_mplsogre_encap_ip_src,
16048                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16049                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16050                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16051                 (void *)&cmd_set_mplsogre_encap_eth_src,
16052                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16053                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16054                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16055                 NULL,
16056         },
16057 };
16058
16059 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16060         .f = cmd_set_mplsogre_encap_parsed,
16061         .data = NULL,
16062         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16063                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16064                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16065         .tokens = {
16066                 (void *)&cmd_set_mplsogre_encap_set,
16067                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16068                 (void *)&cmd_set_mplsogre_encap_ip_version,
16069                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16070                 (void *)&cmd_set_mplsogre_encap_label,
16071                 (void *)&cmd_set_mplsogre_encap_label_value,
16072                 (void *)&cmd_set_mplsogre_encap_ip_src,
16073                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16074                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16075                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16076                 (void *)&cmd_set_mplsogre_encap_vlan,
16077                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16078                 (void *)&cmd_set_mplsogre_encap_eth_src,
16079                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16080                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16081                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16082                 NULL,
16083         },
16084 };
16085
16086 /** Set MPLSoGRE decapsulation details */
16087 struct cmd_set_mplsogre_decap_result {
16088         cmdline_fixed_string_t set;
16089         cmdline_fixed_string_t mplsogre;
16090         cmdline_fixed_string_t pos_token;
16091         cmdline_fixed_string_t ip_version;
16092         uint32_t vlan_present:1;
16093 };
16094
16095 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16096         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16097                                  "set");
16098 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16099         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16100                                  "mplsogre_decap");
16101 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16102         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16103                                  mplsogre, "mplsogre_decap-with-vlan");
16104 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16105         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16106                                  pos_token, "ip-version");
16107 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16108         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16109                                  ip_version, "ipv4#ipv6");
16110
16111 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16112         __rte_unused struct cmdline *cl,
16113         __rte_unused void *data)
16114 {
16115         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16116
16117         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16118                 mplsogre_decap_conf.select_vlan = 0;
16119         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16120                 mplsogre_decap_conf.select_vlan = 1;
16121         if (strcmp(res->ip_version, "ipv4") == 0)
16122                 mplsogre_decap_conf.select_ipv4 = 1;
16123         else if (strcmp(res->ip_version, "ipv6") == 0)
16124                 mplsogre_decap_conf.select_ipv4 = 0;
16125 }
16126
16127 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16128         .f = cmd_set_mplsogre_decap_parsed,
16129         .data = NULL,
16130         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16131         .tokens = {
16132                 (void *)&cmd_set_mplsogre_decap_set,
16133                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16134                 (void *)&cmd_set_mplsogre_decap_ip_version,
16135                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16136                 NULL,
16137         },
16138 };
16139
16140 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16141         .f = cmd_set_mplsogre_decap_parsed,
16142         .data = NULL,
16143         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16144         .tokens = {
16145                 (void *)&cmd_set_mplsogre_decap_set,
16146                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16147                 (void *)&cmd_set_mplsogre_decap_ip_version,
16148                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16149                 NULL,
16150         },
16151 };
16152
16153 /** Set MPLSoUDP encapsulation details */
16154 struct cmd_set_mplsoudp_encap_result {
16155         cmdline_fixed_string_t set;
16156         cmdline_fixed_string_t mplsoudp;
16157         cmdline_fixed_string_t pos_token;
16158         cmdline_fixed_string_t ip_version;
16159         uint32_t vlan_present:1;
16160         uint32_t label;
16161         uint16_t udp_src;
16162         uint16_t udp_dst;
16163         cmdline_ipaddr_t ip_src;
16164         cmdline_ipaddr_t ip_dst;
16165         uint16_t tci;
16166         struct rte_ether_addr eth_src;
16167         struct rte_ether_addr eth_dst;
16168 };
16169
16170 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16171         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16172                                  "set");
16173 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16174         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16175                                  "mplsoudp_encap");
16176 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16177         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16178                                  mplsoudp, "mplsoudp_encap-with-vlan");
16179 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16180         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16181                                  pos_token, "ip-version");
16182 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16183         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16184                                  ip_version, "ipv4#ipv6");
16185 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16187                                  pos_token, "label");
16188 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16189         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16190                               UINT32);
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16193                                  pos_token, "udp-src");
16194 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16195         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16196                               UINT16);
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16199                                  pos_token, "udp-dst");
16200 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16201         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16202                               UINT16);
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16205                                  pos_token, "ip-src");
16206 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16207         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16208 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16209         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16210                                  pos_token, "ip-dst");
16211 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16212         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16213 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16214         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16215                                  pos_token, "vlan-tci");
16216 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16217         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16218                               UINT16);
16219 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16220         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16221                                  pos_token, "eth-src");
16222 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16223         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16224                                     eth_src);
16225 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16226         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16227                                  pos_token, "eth-dst");
16228 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16229         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16230                                     eth_dst);
16231
16232 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16233         __rte_unused struct cmdline *cl,
16234         __rte_unused void *data)
16235 {
16236         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16237         union {
16238                 uint32_t mplsoudp_label;
16239                 uint8_t label[4];
16240         } id = {
16241                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16242         };
16243
16244         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16245                 mplsoudp_encap_conf.select_vlan = 0;
16246         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16247                 mplsoudp_encap_conf.select_vlan = 1;
16248         if (strcmp(res->ip_version, "ipv4") == 0)
16249                 mplsoudp_encap_conf.select_ipv4 = 1;
16250         else if (strcmp(res->ip_version, "ipv6") == 0)
16251                 mplsoudp_encap_conf.select_ipv4 = 0;
16252         else
16253                 return;
16254         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16255         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16256         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16257         if (mplsoudp_encap_conf.select_ipv4) {
16258                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16259                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16260         } else {
16261                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16262                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16263         }
16264         if (mplsoudp_encap_conf.select_vlan)
16265                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16266         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16267                    RTE_ETHER_ADDR_LEN);
16268         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16269                    RTE_ETHER_ADDR_LEN);
16270 }
16271
16272 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16273         .f = cmd_set_mplsoudp_encap_parsed,
16274         .data = NULL,
16275         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16276                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16277                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16278         .tokens = {
16279                 (void *)&cmd_set_mplsoudp_encap_set,
16280                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16281                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16282                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16283                 (void *)&cmd_set_mplsoudp_encap_label,
16284                 (void *)&cmd_set_mplsoudp_encap_label_value,
16285                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16286                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16287                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16288                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16289                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16290                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16291                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16292                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16293                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16294                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16295                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16296                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16297                 NULL,
16298         },
16299 };
16300
16301 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16302         .f = cmd_set_mplsoudp_encap_parsed,
16303         .data = NULL,
16304         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16305                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16306                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16307                 " eth-src <eth-src> eth-dst <eth-dst>",
16308         .tokens = {
16309                 (void *)&cmd_set_mplsoudp_encap_set,
16310                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16311                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16312                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16313                 (void *)&cmd_set_mplsoudp_encap_label,
16314                 (void *)&cmd_set_mplsoudp_encap_label_value,
16315                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16316                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16317                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16318                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16319                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16320                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16321                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16322                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16323                 (void *)&cmd_set_mplsoudp_encap_vlan,
16324                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16325                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16326                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16327                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16328                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16329                 NULL,
16330         },
16331 };
16332
16333 /** Set MPLSoUDP decapsulation details */
16334 struct cmd_set_mplsoudp_decap_result {
16335         cmdline_fixed_string_t set;
16336         cmdline_fixed_string_t mplsoudp;
16337         cmdline_fixed_string_t pos_token;
16338         cmdline_fixed_string_t ip_version;
16339         uint32_t vlan_present:1;
16340 };
16341
16342 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16343         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16344                                  "set");
16345 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16346         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16347                                  "mplsoudp_decap");
16348 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16349         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16350                                  mplsoudp, "mplsoudp_decap-with-vlan");
16351 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16352         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16353                                  pos_token, "ip-version");
16354 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16355         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16356                                  ip_version, "ipv4#ipv6");
16357
16358 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16359         __rte_unused struct cmdline *cl,
16360         __rte_unused void *data)
16361 {
16362         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16363
16364         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16365                 mplsoudp_decap_conf.select_vlan = 0;
16366         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16367                 mplsoudp_decap_conf.select_vlan = 1;
16368         if (strcmp(res->ip_version, "ipv4") == 0)
16369                 mplsoudp_decap_conf.select_ipv4 = 1;
16370         else if (strcmp(res->ip_version, "ipv6") == 0)
16371                 mplsoudp_decap_conf.select_ipv4 = 0;
16372 }
16373
16374 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16375         .f = cmd_set_mplsoudp_decap_parsed,
16376         .data = NULL,
16377         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16378         .tokens = {
16379                 (void *)&cmd_set_mplsoudp_decap_set,
16380                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16381                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16382                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16383                 NULL,
16384         },
16385 };
16386
16387 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16388         .f = cmd_set_mplsoudp_decap_parsed,
16389         .data = NULL,
16390         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16391         .tokens = {
16392                 (void *)&cmd_set_mplsoudp_decap_set,
16393                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16394                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16395                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16396                 NULL,
16397         },
16398 };
16399
16400 /* Strict link priority scheduling mode setting */
16401 static void
16402 cmd_strict_link_prio_parsed(
16403         void *parsed_result,
16404         __rte_unused struct cmdline *cl,
16405         __rte_unused void *data)
16406 {
16407         struct cmd_vf_tc_bw_result *res = parsed_result;
16408         int ret = -ENOTSUP;
16409
16410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16411                 return;
16412
16413 #ifdef RTE_LIBRTE_I40E_PMD
16414         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16415 #endif
16416
16417         switch (ret) {
16418         case 0:
16419                 break;
16420         case -EINVAL:
16421                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16422                 break;
16423         case -ENODEV:
16424                 printf("invalid port_id %d\n", res->port_id);
16425                 break;
16426         case -ENOTSUP:
16427                 printf("function not implemented\n");
16428                 break;
16429         default:
16430                 printf("programming error: (%s)\n", strerror(-ret));
16431         }
16432 }
16433
16434 cmdline_parse_inst_t cmd_strict_link_prio = {
16435         .f = cmd_strict_link_prio_parsed,
16436         .data = NULL,
16437         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16438         .tokens = {
16439                 (void *)&cmd_vf_tc_bw_set,
16440                 (void *)&cmd_vf_tc_bw_tx,
16441                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16442                 (void *)&cmd_vf_tc_bw_port_id,
16443                 (void *)&cmd_vf_tc_bw_tc_map,
16444                 NULL,
16445         },
16446 };
16447
16448 /* Load dynamic device personalization*/
16449 struct cmd_ddp_add_result {
16450         cmdline_fixed_string_t ddp;
16451         cmdline_fixed_string_t add;
16452         portid_t port_id;
16453         char filepath[];
16454 };
16455
16456 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16457         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16458 cmdline_parse_token_string_t cmd_ddp_add_add =
16459         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16460 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16461         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16462 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16463         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16464
16465 static void
16466 cmd_ddp_add_parsed(
16467         void *parsed_result,
16468         __rte_unused struct cmdline *cl,
16469         __rte_unused void *data)
16470 {
16471         struct cmd_ddp_add_result *res = parsed_result;
16472         uint8_t *buff;
16473         uint32_t size;
16474         char *filepath;
16475         char *file_fld[2];
16476         int file_num;
16477         int ret = -ENOTSUP;
16478
16479         if (!all_ports_stopped()) {
16480                 printf("Please stop all ports first\n");
16481                 return;
16482         }
16483
16484         filepath = strdup(res->filepath);
16485         if (filepath == NULL) {
16486                 printf("Failed to allocate memory\n");
16487                 return;
16488         }
16489         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16490
16491         buff = open_file(file_fld[0], &size);
16492         if (!buff) {
16493                 free((void *)filepath);
16494                 return;
16495         }
16496
16497 #ifdef RTE_LIBRTE_I40E_PMD
16498         if (ret == -ENOTSUP)
16499                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16500                                                buff, size,
16501                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16502 #endif
16503
16504         if (ret == -EEXIST)
16505                 printf("Profile has already existed.\n");
16506         else if (ret < 0)
16507                 printf("Failed to load profile.\n");
16508         else if (file_num == 2)
16509                 save_file(file_fld[1], buff, size);
16510
16511         close_file(buff);
16512         free((void *)filepath);
16513 }
16514
16515 cmdline_parse_inst_t cmd_ddp_add = {
16516         .f = cmd_ddp_add_parsed,
16517         .data = NULL,
16518         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16519         .tokens = {
16520                 (void *)&cmd_ddp_add_ddp,
16521                 (void *)&cmd_ddp_add_add,
16522                 (void *)&cmd_ddp_add_port_id,
16523                 (void *)&cmd_ddp_add_filepath,
16524                 NULL,
16525         },
16526 };
16527
16528 /* Delete dynamic device personalization*/
16529 struct cmd_ddp_del_result {
16530         cmdline_fixed_string_t ddp;
16531         cmdline_fixed_string_t del;
16532         portid_t port_id;
16533         char filepath[];
16534 };
16535
16536 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16537         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16538 cmdline_parse_token_string_t cmd_ddp_del_del =
16539         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16540 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16541         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16542 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16543         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16544
16545 static void
16546 cmd_ddp_del_parsed(
16547         void *parsed_result,
16548         __rte_unused struct cmdline *cl,
16549         __rte_unused void *data)
16550 {
16551         struct cmd_ddp_del_result *res = parsed_result;
16552         uint8_t *buff;
16553         uint32_t size;
16554         int ret = -ENOTSUP;
16555
16556         if (!all_ports_stopped()) {
16557                 printf("Please stop all ports first\n");
16558                 return;
16559         }
16560
16561         buff = open_file(res->filepath, &size);
16562         if (!buff)
16563                 return;
16564
16565 #ifdef RTE_LIBRTE_I40E_PMD
16566         if (ret == -ENOTSUP)
16567                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16568                                                buff, size,
16569                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16570 #endif
16571
16572         if (ret == -EACCES)
16573                 printf("Profile does not exist.\n");
16574         else if (ret < 0)
16575                 printf("Failed to delete profile.\n");
16576
16577         close_file(buff);
16578 }
16579
16580 cmdline_parse_inst_t cmd_ddp_del = {
16581         .f = cmd_ddp_del_parsed,
16582         .data = NULL,
16583         .help_str = "ddp del <port_id> <backup_profile_path>",
16584         .tokens = {
16585                 (void *)&cmd_ddp_del_ddp,
16586                 (void *)&cmd_ddp_del_del,
16587                 (void *)&cmd_ddp_del_port_id,
16588                 (void *)&cmd_ddp_del_filepath,
16589                 NULL,
16590         },
16591 };
16592
16593 /* Get dynamic device personalization profile info */
16594 struct cmd_ddp_info_result {
16595         cmdline_fixed_string_t ddp;
16596         cmdline_fixed_string_t get;
16597         cmdline_fixed_string_t info;
16598         char filepath[];
16599 };
16600
16601 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16602         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16603 cmdline_parse_token_string_t cmd_ddp_info_get =
16604         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16605 cmdline_parse_token_string_t cmd_ddp_info_info =
16606         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16607 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16608         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16609
16610 static void
16611 cmd_ddp_info_parsed(
16612         void *parsed_result,
16613         __rte_unused struct cmdline *cl,
16614         __rte_unused void *data)
16615 {
16616         struct cmd_ddp_info_result *res = parsed_result;
16617         uint8_t *pkg;
16618         uint32_t pkg_size;
16619         int ret = -ENOTSUP;
16620 #ifdef RTE_LIBRTE_I40E_PMD
16621         uint32_t i, j, n;
16622         uint8_t *buff;
16623         uint32_t buff_size = 0;
16624         struct rte_pmd_i40e_profile_info info;
16625         uint32_t dev_num = 0;
16626         struct rte_pmd_i40e_ddp_device_id *devs;
16627         uint32_t proto_num = 0;
16628         struct rte_pmd_i40e_proto_info *proto = NULL;
16629         uint32_t pctype_num = 0;
16630         struct rte_pmd_i40e_ptype_info *pctype;
16631         uint32_t ptype_num = 0;
16632         struct rte_pmd_i40e_ptype_info *ptype;
16633         uint8_t proto_id;
16634
16635 #endif
16636
16637         pkg = open_file(res->filepath, &pkg_size);
16638         if (!pkg)
16639                 return;
16640
16641 #ifdef RTE_LIBRTE_I40E_PMD
16642         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16643                                 (uint8_t *)&info, sizeof(info),
16644                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16645         if (!ret) {
16646                 printf("Global Track id:       0x%x\n", info.track_id);
16647                 printf("Global Version:        %d.%d.%d.%d\n",
16648                         info.version.major,
16649                         info.version.minor,
16650                         info.version.update,
16651                         info.version.draft);
16652                 printf("Global Package name:   %s\n\n", info.name);
16653         }
16654
16655         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16656                                 (uint8_t *)&info, sizeof(info),
16657                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16658         if (!ret) {
16659                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16660                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16661                         info.version.major,
16662                         info.version.minor,
16663                         info.version.update,
16664                         info.version.draft);
16665                 printf("i40e Profile name:     %s\n\n", info.name);
16666         }
16667
16668         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16669                                 (uint8_t *)&buff_size, sizeof(buff_size),
16670                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16671         if (!ret && buff_size) {
16672                 buff = (uint8_t *)malloc(buff_size);
16673                 if (buff) {
16674                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16675                                                 buff, buff_size,
16676                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16677                         if (!ret)
16678                                 printf("Package Notes:\n%s\n\n", buff);
16679                         free(buff);
16680                 }
16681         }
16682
16683         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16684                                 (uint8_t *)&dev_num, sizeof(dev_num),
16685                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16686         if (!ret && dev_num) {
16687                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16688                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16689                 if (devs) {
16690                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16691                                                 (uint8_t *)devs, buff_size,
16692                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16693                         if (!ret) {
16694                                 printf("List of supported devices:\n");
16695                                 for (i = 0; i < dev_num; i++) {
16696                                         printf("  %04X:%04X %04X:%04X\n",
16697                                                 devs[i].vendor_dev_id >> 16,
16698                                                 devs[i].vendor_dev_id & 0xFFFF,
16699                                                 devs[i].sub_vendor_dev_id >> 16,
16700                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16701                                 }
16702                                 printf("\n");
16703                         }
16704                         free(devs);
16705                 }
16706         }
16707
16708         /* get information about protocols and packet types */
16709         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16710                 (uint8_t *)&proto_num, sizeof(proto_num),
16711                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16712         if (ret || !proto_num)
16713                 goto no_print_return;
16714
16715         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16716         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16717         if (!proto)
16718                 goto no_print_return;
16719
16720         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16721                                         buff_size,
16722                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16723         if (!ret) {
16724                 printf("List of used protocols:\n");
16725                 for (i = 0; i < proto_num; i++)
16726                         printf("  %2u: %s\n", proto[i].proto_id,
16727                                proto[i].name);
16728                 printf("\n");
16729         }
16730         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16731                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16732                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16733         if (ret || !pctype_num)
16734                 goto no_print_pctypes;
16735
16736         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16737         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16738         if (!pctype)
16739                 goto no_print_pctypes;
16740
16741         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16742                                         buff_size,
16743                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16744         if (ret) {
16745                 free(pctype);
16746                 goto no_print_pctypes;
16747         }
16748
16749         printf("List of defined packet classification types:\n");
16750         for (i = 0; i < pctype_num; i++) {
16751                 printf("  %2u:", pctype[i].ptype_id);
16752                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16753                         proto_id = pctype[i].protocols[j];
16754                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16755                                 for (n = 0; n < proto_num; n++) {
16756                                         if (proto[n].proto_id == proto_id) {
16757                                                 printf(" %s", proto[n].name);
16758                                                 break;
16759                                         }
16760                                 }
16761                         }
16762                 }
16763                 printf("\n");
16764         }
16765         printf("\n");
16766         free(pctype);
16767
16768 no_print_pctypes:
16769
16770         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16771                                         sizeof(ptype_num),
16772                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16773         if (ret || !ptype_num)
16774                 goto no_print_return;
16775
16776         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16777         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16778         if (!ptype)
16779                 goto no_print_return;
16780
16781         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16782                                         buff_size,
16783                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16784         if (ret) {
16785                 free(ptype);
16786                 goto no_print_return;
16787         }
16788         printf("List of defined packet types:\n");
16789         for (i = 0; i < ptype_num; i++) {
16790                 printf("  %2u:", ptype[i].ptype_id);
16791                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16792                         proto_id = ptype[i].protocols[j];
16793                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16794                                 for (n = 0; n < proto_num; n++) {
16795                                         if (proto[n].proto_id == proto_id) {
16796                                                 printf(" %s", proto[n].name);
16797                                                 break;
16798                                         }
16799                                 }
16800                         }
16801                 }
16802                 printf("\n");
16803         }
16804         free(ptype);
16805         printf("\n");
16806
16807         ret = 0;
16808 no_print_return:
16809         if (proto)
16810                 free(proto);
16811 #endif
16812         if (ret == -ENOTSUP)
16813                 printf("Function not supported in PMD driver\n");
16814         close_file(pkg);
16815 }
16816
16817 cmdline_parse_inst_t cmd_ddp_get_info = {
16818         .f = cmd_ddp_info_parsed,
16819         .data = NULL,
16820         .help_str = "ddp get info <profile_path>",
16821         .tokens = {
16822                 (void *)&cmd_ddp_info_ddp,
16823                 (void *)&cmd_ddp_info_get,
16824                 (void *)&cmd_ddp_info_info,
16825                 (void *)&cmd_ddp_info_filepath,
16826                 NULL,
16827         },
16828 };
16829
16830 /* Get dynamic device personalization profile info list*/
16831 #define PROFILE_INFO_SIZE 48
16832 #define MAX_PROFILE_NUM 16
16833
16834 struct cmd_ddp_get_list_result {
16835         cmdline_fixed_string_t ddp;
16836         cmdline_fixed_string_t get;
16837         cmdline_fixed_string_t list;
16838         portid_t port_id;
16839 };
16840
16841 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16842         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16843 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16844         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16845 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16846         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16847 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16848         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16849
16850 static void
16851 cmd_ddp_get_list_parsed(
16852         __rte_unused void *parsed_result,
16853         __rte_unused struct cmdline *cl,
16854         __rte_unused void *data)
16855 {
16856 #ifdef RTE_LIBRTE_I40E_PMD
16857         struct cmd_ddp_get_list_result *res = parsed_result;
16858         struct rte_pmd_i40e_profile_list *p_list;
16859         struct rte_pmd_i40e_profile_info *p_info;
16860         uint32_t p_num;
16861         uint32_t size;
16862         uint32_t i;
16863 #endif
16864         int ret = -ENOTSUP;
16865
16866 #ifdef RTE_LIBRTE_I40E_PMD
16867         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16868         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16869         if (!p_list)
16870                 printf("%s: Failed to malloc buffer\n", __func__);
16871
16872         if (ret == -ENOTSUP)
16873                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16874                                                 (uint8_t *)p_list, size);
16875
16876         if (!ret) {
16877                 p_num = p_list->p_count;
16878                 printf("Profile number is: %d\n\n", p_num);
16879
16880                 for (i = 0; i < p_num; i++) {
16881                         p_info = &p_list->p_info[i];
16882                         printf("Profile %d:\n", i);
16883                         printf("Track id:     0x%x\n", p_info->track_id);
16884                         printf("Version:      %d.%d.%d.%d\n",
16885                                p_info->version.major,
16886                                p_info->version.minor,
16887                                p_info->version.update,
16888                                p_info->version.draft);
16889                         printf("Profile name: %s\n\n", p_info->name);
16890                 }
16891         }
16892
16893         free(p_list);
16894 #endif
16895
16896         if (ret < 0)
16897                 printf("Failed to get ddp list\n");
16898 }
16899
16900 cmdline_parse_inst_t cmd_ddp_get_list = {
16901         .f = cmd_ddp_get_list_parsed,
16902         .data = NULL,
16903         .help_str = "ddp get list <port_id>",
16904         .tokens = {
16905                 (void *)&cmd_ddp_get_list_ddp,
16906                 (void *)&cmd_ddp_get_list_get,
16907                 (void *)&cmd_ddp_get_list_list,
16908                 (void *)&cmd_ddp_get_list_port_id,
16909                 NULL,
16910         },
16911 };
16912
16913 /* Configure input set */
16914 struct cmd_cfg_input_set_result {
16915         cmdline_fixed_string_t port;
16916         cmdline_fixed_string_t cfg;
16917         portid_t port_id;
16918         cmdline_fixed_string_t pctype;
16919         uint8_t pctype_id;
16920         cmdline_fixed_string_t inset_type;
16921         cmdline_fixed_string_t opt;
16922         cmdline_fixed_string_t field;
16923         uint8_t field_idx;
16924 };
16925
16926 static void
16927 cmd_cfg_input_set_parsed(
16928         __rte_unused void *parsed_result,
16929         __rte_unused struct cmdline *cl,
16930         __rte_unused void *data)
16931 {
16932 #ifdef RTE_LIBRTE_I40E_PMD
16933         struct cmd_cfg_input_set_result *res = parsed_result;
16934         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16935         struct rte_pmd_i40e_inset inset;
16936 #endif
16937         int ret = -ENOTSUP;
16938
16939         if (!all_ports_stopped()) {
16940                 printf("Please stop all ports first\n");
16941                 return;
16942         }
16943
16944 #ifdef RTE_LIBRTE_I40E_PMD
16945         if (!strcmp(res->inset_type, "hash_inset"))
16946                 inset_type = INSET_HASH;
16947         else if (!strcmp(res->inset_type, "fdir_inset"))
16948                 inset_type = INSET_FDIR;
16949         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16950                 inset_type = INSET_FDIR_FLX;
16951         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16952                                      &inset, inset_type);
16953         if (ret) {
16954                 printf("Failed to get input set.\n");
16955                 return;
16956         }
16957
16958         if (!strcmp(res->opt, "get")) {
16959                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16960                                                    res->field_idx);
16961                 if (ret)
16962                         printf("Field index %d is enabled.\n", res->field_idx);
16963                 else
16964                         printf("Field index %d is disabled.\n", res->field_idx);
16965                 return;
16966         } else if (!strcmp(res->opt, "set"))
16967                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16968                                                    res->field_idx);
16969         else if (!strcmp(res->opt, "clear"))
16970                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16971                                                      res->field_idx);
16972         if (ret) {
16973                 printf("Failed to configure input set field.\n");
16974                 return;
16975         }
16976
16977         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16978                                      &inset, inset_type);
16979         if (ret) {
16980                 printf("Failed to set input set.\n");
16981                 return;
16982         }
16983 #endif
16984
16985         if (ret == -ENOTSUP)
16986                 printf("Function not supported\n");
16987 }
16988
16989 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16990         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16991                                  port, "port");
16992 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16993         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16994                                  cfg, "config");
16995 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16996         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16997                               port_id, UINT16);
16998 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16999         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17000                                  pctype, "pctype");
17001 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17002         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17003                               pctype_id, UINT8);
17004 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17005         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17006                                  inset_type,
17007                                  "hash_inset#fdir_inset#fdir_flx_inset");
17008 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17009         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17010                                  opt, "get#set#clear");
17011 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17012         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17013                                  field, "field");
17014 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17015         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17016                               field_idx, UINT8);
17017
17018 cmdline_parse_inst_t cmd_cfg_input_set = {
17019         .f = cmd_cfg_input_set_parsed,
17020         .data = NULL,
17021         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17022                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17023         .tokens = {
17024                 (void *)&cmd_cfg_input_set_port,
17025                 (void *)&cmd_cfg_input_set_cfg,
17026                 (void *)&cmd_cfg_input_set_port_id,
17027                 (void *)&cmd_cfg_input_set_pctype,
17028                 (void *)&cmd_cfg_input_set_pctype_id,
17029                 (void *)&cmd_cfg_input_set_inset_type,
17030                 (void *)&cmd_cfg_input_set_opt,
17031                 (void *)&cmd_cfg_input_set_field,
17032                 (void *)&cmd_cfg_input_set_field_idx,
17033                 NULL,
17034         },
17035 };
17036
17037 /* Clear input set */
17038 struct cmd_clear_input_set_result {
17039         cmdline_fixed_string_t port;
17040         cmdline_fixed_string_t cfg;
17041         portid_t port_id;
17042         cmdline_fixed_string_t pctype;
17043         uint8_t pctype_id;
17044         cmdline_fixed_string_t inset_type;
17045         cmdline_fixed_string_t clear;
17046         cmdline_fixed_string_t all;
17047 };
17048
17049 static void
17050 cmd_clear_input_set_parsed(
17051         __rte_unused void *parsed_result,
17052         __rte_unused struct cmdline *cl,
17053         __rte_unused void *data)
17054 {
17055 #ifdef RTE_LIBRTE_I40E_PMD
17056         struct cmd_clear_input_set_result *res = parsed_result;
17057         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17058         struct rte_pmd_i40e_inset inset;
17059 #endif
17060         int ret = -ENOTSUP;
17061
17062         if (!all_ports_stopped()) {
17063                 printf("Please stop all ports first\n");
17064                 return;
17065         }
17066
17067 #ifdef RTE_LIBRTE_I40E_PMD
17068         if (!strcmp(res->inset_type, "hash_inset"))
17069                 inset_type = INSET_HASH;
17070         else if (!strcmp(res->inset_type, "fdir_inset"))
17071                 inset_type = INSET_FDIR;
17072         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17073                 inset_type = INSET_FDIR_FLX;
17074
17075         memset(&inset, 0, sizeof(inset));
17076
17077         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17078                                      &inset, inset_type);
17079         if (ret) {
17080                 printf("Failed to clear input set.\n");
17081                 return;
17082         }
17083
17084 #endif
17085
17086         if (ret == -ENOTSUP)
17087                 printf("Function not supported\n");
17088 }
17089
17090 cmdline_parse_token_string_t cmd_clear_input_set_port =
17091         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17092                                  port, "port");
17093 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17094         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17095                                  cfg, "config");
17096 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17097         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17098                               port_id, UINT16);
17099 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17100         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17101                                  pctype, "pctype");
17102 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17103         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17104                               pctype_id, UINT8);
17105 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17106         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17107                                  inset_type,
17108                                  "hash_inset#fdir_inset#fdir_flx_inset");
17109 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17110         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17111                                  clear, "clear");
17112 cmdline_parse_token_string_t cmd_clear_input_set_all =
17113         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17114                                  all, "all");
17115
17116 cmdline_parse_inst_t cmd_clear_input_set = {
17117         .f = cmd_clear_input_set_parsed,
17118         .data = NULL,
17119         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17120                     "fdir_inset|fdir_flx_inset clear all",
17121         .tokens = {
17122                 (void *)&cmd_clear_input_set_port,
17123                 (void *)&cmd_clear_input_set_cfg,
17124                 (void *)&cmd_clear_input_set_port_id,
17125                 (void *)&cmd_clear_input_set_pctype,
17126                 (void *)&cmd_clear_input_set_pctype_id,
17127                 (void *)&cmd_clear_input_set_inset_type,
17128                 (void *)&cmd_clear_input_set_clear,
17129                 (void *)&cmd_clear_input_set_all,
17130                 NULL,
17131         },
17132 };
17133
17134 /* show vf stats */
17135
17136 /* Common result structure for show vf stats */
17137 struct cmd_show_vf_stats_result {
17138         cmdline_fixed_string_t show;
17139         cmdline_fixed_string_t vf;
17140         cmdline_fixed_string_t stats;
17141         portid_t port_id;
17142         uint16_t vf_id;
17143 };
17144
17145 /* Common CLI fields show vf stats*/
17146 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17147         TOKEN_STRING_INITIALIZER
17148                 (struct cmd_show_vf_stats_result,
17149                  show, "show");
17150 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17151         TOKEN_STRING_INITIALIZER
17152                 (struct cmd_show_vf_stats_result,
17153                  vf, "vf");
17154 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17155         TOKEN_STRING_INITIALIZER
17156                 (struct cmd_show_vf_stats_result,
17157                  stats, "stats");
17158 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17159         TOKEN_NUM_INITIALIZER
17160                 (struct cmd_show_vf_stats_result,
17161                  port_id, UINT16);
17162 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17163         TOKEN_NUM_INITIALIZER
17164                 (struct cmd_show_vf_stats_result,
17165                  vf_id, UINT16);
17166
17167 static void
17168 cmd_show_vf_stats_parsed(
17169         void *parsed_result,
17170         __rte_unused struct cmdline *cl,
17171         __rte_unused void *data)
17172 {
17173         struct cmd_show_vf_stats_result *res = parsed_result;
17174         struct rte_eth_stats stats;
17175         int ret = -ENOTSUP;
17176         static const char *nic_stats_border = "########################";
17177
17178         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17179                 return;
17180
17181         memset(&stats, 0, sizeof(stats));
17182
17183 #ifdef RTE_LIBRTE_I40E_PMD
17184         if (ret == -ENOTSUP)
17185                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17186                                                 res->vf_id,
17187                                                 &stats);
17188 #endif
17189 #ifdef RTE_LIBRTE_BNXT_PMD
17190         if (ret == -ENOTSUP)
17191                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17192                                                 res->vf_id,
17193                                                 &stats);
17194 #endif
17195
17196         switch (ret) {
17197         case 0:
17198                 break;
17199         case -EINVAL:
17200                 printf("invalid vf_id %d\n", res->vf_id);
17201                 break;
17202         case -ENODEV:
17203                 printf("invalid port_id %d\n", res->port_id);
17204                 break;
17205         case -ENOTSUP:
17206                 printf("function not implemented\n");
17207                 break;
17208         default:
17209                 printf("programming error: (%s)\n", strerror(-ret));
17210         }
17211
17212         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17213                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17214
17215         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17216                "%-"PRIu64"\n",
17217                stats.ipackets, stats.imissed, stats.ibytes);
17218         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17219         printf("  RX-nombuf:  %-10"PRIu64"\n",
17220                stats.rx_nombuf);
17221         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17222                "%-"PRIu64"\n",
17223                stats.opackets, stats.oerrors, stats.obytes);
17224
17225         printf("  %s############################%s\n",
17226                                nic_stats_border, nic_stats_border);
17227 }
17228
17229 cmdline_parse_inst_t cmd_show_vf_stats = {
17230         .f = cmd_show_vf_stats_parsed,
17231         .data = NULL,
17232         .help_str = "show vf stats <port_id> <vf_id>",
17233         .tokens = {
17234                 (void *)&cmd_show_vf_stats_show,
17235                 (void *)&cmd_show_vf_stats_vf,
17236                 (void *)&cmd_show_vf_stats_stats,
17237                 (void *)&cmd_show_vf_stats_port_id,
17238                 (void *)&cmd_show_vf_stats_vf_id,
17239                 NULL,
17240         },
17241 };
17242
17243 /* clear vf stats */
17244
17245 /* Common result structure for clear vf stats */
17246 struct cmd_clear_vf_stats_result {
17247         cmdline_fixed_string_t clear;
17248         cmdline_fixed_string_t vf;
17249         cmdline_fixed_string_t stats;
17250         portid_t port_id;
17251         uint16_t vf_id;
17252 };
17253
17254 /* Common CLI fields clear vf stats*/
17255 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17256         TOKEN_STRING_INITIALIZER
17257                 (struct cmd_clear_vf_stats_result,
17258                  clear, "clear");
17259 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17260         TOKEN_STRING_INITIALIZER
17261                 (struct cmd_clear_vf_stats_result,
17262                  vf, "vf");
17263 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17264         TOKEN_STRING_INITIALIZER
17265                 (struct cmd_clear_vf_stats_result,
17266                  stats, "stats");
17267 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17268         TOKEN_NUM_INITIALIZER
17269                 (struct cmd_clear_vf_stats_result,
17270                  port_id, UINT16);
17271 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17272         TOKEN_NUM_INITIALIZER
17273                 (struct cmd_clear_vf_stats_result,
17274                  vf_id, UINT16);
17275
17276 static void
17277 cmd_clear_vf_stats_parsed(
17278         void *parsed_result,
17279         __rte_unused struct cmdline *cl,
17280         __rte_unused void *data)
17281 {
17282         struct cmd_clear_vf_stats_result *res = parsed_result;
17283         int ret = -ENOTSUP;
17284
17285         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17286                 return;
17287
17288 #ifdef RTE_LIBRTE_I40E_PMD
17289         if (ret == -ENOTSUP)
17290                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17291                                                   res->vf_id);
17292 #endif
17293 #ifdef RTE_LIBRTE_BNXT_PMD
17294         if (ret == -ENOTSUP)
17295                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17296                                                   res->vf_id);
17297 #endif
17298
17299         switch (ret) {
17300         case 0:
17301                 break;
17302         case -EINVAL:
17303                 printf("invalid vf_id %d\n", res->vf_id);
17304                 break;
17305         case -ENODEV:
17306                 printf("invalid port_id %d\n", res->port_id);
17307                 break;
17308         case -ENOTSUP:
17309                 printf("function not implemented\n");
17310                 break;
17311         default:
17312                 printf("programming error: (%s)\n", strerror(-ret));
17313         }
17314 }
17315
17316 cmdline_parse_inst_t cmd_clear_vf_stats = {
17317         .f = cmd_clear_vf_stats_parsed,
17318         .data = NULL,
17319         .help_str = "clear vf stats <port_id> <vf_id>",
17320         .tokens = {
17321                 (void *)&cmd_clear_vf_stats_clear,
17322                 (void *)&cmd_clear_vf_stats_vf,
17323                 (void *)&cmd_clear_vf_stats_stats,
17324                 (void *)&cmd_clear_vf_stats_port_id,
17325                 (void *)&cmd_clear_vf_stats_vf_id,
17326                 NULL,
17327         },
17328 };
17329
17330 /* port config pctype mapping reset */
17331
17332 /* Common result structure for port config pctype mapping reset */
17333 struct cmd_pctype_mapping_reset_result {
17334         cmdline_fixed_string_t port;
17335         cmdline_fixed_string_t config;
17336         portid_t port_id;
17337         cmdline_fixed_string_t pctype;
17338         cmdline_fixed_string_t mapping;
17339         cmdline_fixed_string_t reset;
17340 };
17341
17342 /* Common CLI fields for port config pctype mapping reset*/
17343 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17344         TOKEN_STRING_INITIALIZER
17345                 (struct cmd_pctype_mapping_reset_result,
17346                  port, "port");
17347 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17348         TOKEN_STRING_INITIALIZER
17349                 (struct cmd_pctype_mapping_reset_result,
17350                  config, "config");
17351 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17352         TOKEN_NUM_INITIALIZER
17353                 (struct cmd_pctype_mapping_reset_result,
17354                  port_id, UINT16);
17355 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17356         TOKEN_STRING_INITIALIZER
17357                 (struct cmd_pctype_mapping_reset_result,
17358                  pctype, "pctype");
17359 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17360         TOKEN_STRING_INITIALIZER
17361                 (struct cmd_pctype_mapping_reset_result,
17362                  mapping, "mapping");
17363 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17364         TOKEN_STRING_INITIALIZER
17365                 (struct cmd_pctype_mapping_reset_result,
17366                  reset, "reset");
17367
17368 static void
17369 cmd_pctype_mapping_reset_parsed(
17370         void *parsed_result,
17371         __rte_unused struct cmdline *cl,
17372         __rte_unused void *data)
17373 {
17374         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17375         int ret = -ENOTSUP;
17376
17377         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17378                 return;
17379
17380 #ifdef RTE_LIBRTE_I40E_PMD
17381         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17382 #endif
17383
17384         switch (ret) {
17385         case 0:
17386                 break;
17387         case -ENODEV:
17388                 printf("invalid port_id %d\n", res->port_id);
17389                 break;
17390         case -ENOTSUP:
17391                 printf("function not implemented\n");
17392                 break;
17393         default:
17394                 printf("programming error: (%s)\n", strerror(-ret));
17395         }
17396 }
17397
17398 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17399         .f = cmd_pctype_mapping_reset_parsed,
17400         .data = NULL,
17401         .help_str = "port config <port_id> pctype mapping reset",
17402         .tokens = {
17403                 (void *)&cmd_pctype_mapping_reset_port,
17404                 (void *)&cmd_pctype_mapping_reset_config,
17405                 (void *)&cmd_pctype_mapping_reset_port_id,
17406                 (void *)&cmd_pctype_mapping_reset_pctype,
17407                 (void *)&cmd_pctype_mapping_reset_mapping,
17408                 (void *)&cmd_pctype_mapping_reset_reset,
17409                 NULL,
17410         },
17411 };
17412
17413 /* show port pctype mapping */
17414
17415 /* Common result structure for show port pctype mapping */
17416 struct cmd_pctype_mapping_get_result {
17417         cmdline_fixed_string_t show;
17418         cmdline_fixed_string_t port;
17419         portid_t port_id;
17420         cmdline_fixed_string_t pctype;
17421         cmdline_fixed_string_t mapping;
17422 };
17423
17424 /* Common CLI fields for pctype mapping get */
17425 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17426         TOKEN_STRING_INITIALIZER
17427                 (struct cmd_pctype_mapping_get_result,
17428                  show, "show");
17429 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17430         TOKEN_STRING_INITIALIZER
17431                 (struct cmd_pctype_mapping_get_result,
17432                  port, "port");
17433 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17434         TOKEN_NUM_INITIALIZER
17435                 (struct cmd_pctype_mapping_get_result,
17436                  port_id, UINT16);
17437 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17438         TOKEN_STRING_INITIALIZER
17439                 (struct cmd_pctype_mapping_get_result,
17440                  pctype, "pctype");
17441 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17442         TOKEN_STRING_INITIALIZER
17443                 (struct cmd_pctype_mapping_get_result,
17444                  mapping, "mapping");
17445
17446 static void
17447 cmd_pctype_mapping_get_parsed(
17448         void *parsed_result,
17449         __rte_unused struct cmdline *cl,
17450         __rte_unused void *data)
17451 {
17452         struct cmd_pctype_mapping_get_result *res = parsed_result;
17453         int ret = -ENOTSUP;
17454 #ifdef RTE_LIBRTE_I40E_PMD
17455         struct rte_pmd_i40e_flow_type_mapping
17456                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17457         int i, j, first_pctype;
17458 #endif
17459
17460         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17461                 return;
17462
17463 #ifdef RTE_LIBRTE_I40E_PMD
17464         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17465 #endif
17466
17467         switch (ret) {
17468         case 0:
17469                 break;
17470         case -ENODEV:
17471                 printf("invalid port_id %d\n", res->port_id);
17472                 return;
17473         case -ENOTSUP:
17474                 printf("function not implemented\n");
17475                 return;
17476         default:
17477                 printf("programming error: (%s)\n", strerror(-ret));
17478                 return;
17479         }
17480
17481 #ifdef RTE_LIBRTE_I40E_PMD
17482         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17483                 if (mapping[i].pctype != 0ULL) {
17484                         first_pctype = 1;
17485
17486                         printf("pctype: ");
17487                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17488                                 if (mapping[i].pctype & (1ULL << j)) {
17489                                         printf(first_pctype ?
17490                                                "%02d" : ",%02d", j);
17491                                         first_pctype = 0;
17492                                 }
17493                         }
17494                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17495                 }
17496         }
17497 #endif
17498 }
17499
17500 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17501         .f = cmd_pctype_mapping_get_parsed,
17502         .data = NULL,
17503         .help_str = "show port <port_id> pctype mapping",
17504         .tokens = {
17505                 (void *)&cmd_pctype_mapping_get_show,
17506                 (void *)&cmd_pctype_mapping_get_port,
17507                 (void *)&cmd_pctype_mapping_get_port_id,
17508                 (void *)&cmd_pctype_mapping_get_pctype,
17509                 (void *)&cmd_pctype_mapping_get_mapping,
17510                 NULL,
17511         },
17512 };
17513
17514 /* port config pctype mapping update */
17515
17516 /* Common result structure for port config pctype mapping update */
17517 struct cmd_pctype_mapping_update_result {
17518         cmdline_fixed_string_t port;
17519         cmdline_fixed_string_t config;
17520         portid_t port_id;
17521         cmdline_fixed_string_t pctype;
17522         cmdline_fixed_string_t mapping;
17523         cmdline_fixed_string_t update;
17524         cmdline_fixed_string_t pctype_list;
17525         uint16_t flow_type;
17526 };
17527
17528 /* Common CLI fields for pctype mapping update*/
17529 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17530         TOKEN_STRING_INITIALIZER
17531                 (struct cmd_pctype_mapping_update_result,
17532                  port, "port");
17533 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17534         TOKEN_STRING_INITIALIZER
17535                 (struct cmd_pctype_mapping_update_result,
17536                  config, "config");
17537 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17538         TOKEN_NUM_INITIALIZER
17539                 (struct cmd_pctype_mapping_update_result,
17540                  port_id, UINT16);
17541 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17542         TOKEN_STRING_INITIALIZER
17543                 (struct cmd_pctype_mapping_update_result,
17544                  pctype, "pctype");
17545 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17546         TOKEN_STRING_INITIALIZER
17547                 (struct cmd_pctype_mapping_update_result,
17548                  mapping, "mapping");
17549 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17550         TOKEN_STRING_INITIALIZER
17551                 (struct cmd_pctype_mapping_update_result,
17552                  update, "update");
17553 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17554         TOKEN_STRING_INITIALIZER
17555                 (struct cmd_pctype_mapping_update_result,
17556                  pctype_list, NULL);
17557 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17558         TOKEN_NUM_INITIALIZER
17559                 (struct cmd_pctype_mapping_update_result,
17560                  flow_type, UINT16);
17561
17562 static void
17563 cmd_pctype_mapping_update_parsed(
17564         void *parsed_result,
17565         __rte_unused struct cmdline *cl,
17566         __rte_unused void *data)
17567 {
17568         struct cmd_pctype_mapping_update_result *res = parsed_result;
17569         int ret = -ENOTSUP;
17570 #ifdef RTE_LIBRTE_I40E_PMD
17571         struct rte_pmd_i40e_flow_type_mapping mapping;
17572         unsigned int i;
17573         unsigned int nb_item;
17574         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17575 #endif
17576
17577         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17578                 return;
17579
17580 #ifdef RTE_LIBRTE_I40E_PMD
17581         nb_item = parse_item_list(res->pctype_list, "pctypes",
17582                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17583         mapping.flow_type = res->flow_type;
17584         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17585                 mapping.pctype |= (1ULL << pctype_list[i]);
17586         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17587                                                 &mapping,
17588                                                 1,
17589                                                 0);
17590 #endif
17591
17592         switch (ret) {
17593         case 0:
17594                 break;
17595         case -EINVAL:
17596                 printf("invalid pctype or flow type\n");
17597                 break;
17598         case -ENODEV:
17599                 printf("invalid port_id %d\n", res->port_id);
17600                 break;
17601         case -ENOTSUP:
17602                 printf("function not implemented\n");
17603                 break;
17604         default:
17605                 printf("programming error: (%s)\n", strerror(-ret));
17606         }
17607 }
17608
17609 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17610         .f = cmd_pctype_mapping_update_parsed,
17611         .data = NULL,
17612         .help_str = "port config <port_id> pctype mapping update"
17613         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17614         .tokens = {
17615                 (void *)&cmd_pctype_mapping_update_port,
17616                 (void *)&cmd_pctype_mapping_update_config,
17617                 (void *)&cmd_pctype_mapping_update_port_id,
17618                 (void *)&cmd_pctype_mapping_update_pctype,
17619                 (void *)&cmd_pctype_mapping_update_mapping,
17620                 (void *)&cmd_pctype_mapping_update_update,
17621                 (void *)&cmd_pctype_mapping_update_pc_type,
17622                 (void *)&cmd_pctype_mapping_update_flow_type,
17623                 NULL,
17624         },
17625 };
17626
17627 /* ptype mapping get */
17628
17629 /* Common result structure for ptype mapping get */
17630 struct cmd_ptype_mapping_get_result {
17631         cmdline_fixed_string_t ptype;
17632         cmdline_fixed_string_t mapping;
17633         cmdline_fixed_string_t get;
17634         portid_t port_id;
17635         uint8_t valid_only;
17636 };
17637
17638 /* Common CLI fields for ptype mapping get */
17639 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17640         TOKEN_STRING_INITIALIZER
17641                 (struct cmd_ptype_mapping_get_result,
17642                  ptype, "ptype");
17643 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17644         TOKEN_STRING_INITIALIZER
17645                 (struct cmd_ptype_mapping_get_result,
17646                  mapping, "mapping");
17647 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17648         TOKEN_STRING_INITIALIZER
17649                 (struct cmd_ptype_mapping_get_result,
17650                  get, "get");
17651 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17652         TOKEN_NUM_INITIALIZER
17653                 (struct cmd_ptype_mapping_get_result,
17654                  port_id, UINT16);
17655 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17656         TOKEN_NUM_INITIALIZER
17657                 (struct cmd_ptype_mapping_get_result,
17658                  valid_only, UINT8);
17659
17660 static void
17661 cmd_ptype_mapping_get_parsed(
17662         void *parsed_result,
17663         __rte_unused struct cmdline *cl,
17664         __rte_unused void *data)
17665 {
17666         struct cmd_ptype_mapping_get_result *res = parsed_result;
17667         int ret = -ENOTSUP;
17668 #ifdef RTE_LIBRTE_I40E_PMD
17669         int max_ptype_num = 256;
17670         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17671         uint16_t count;
17672         int i;
17673 #endif
17674
17675         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17676                 return;
17677
17678 #ifdef RTE_LIBRTE_I40E_PMD
17679         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17680                                         mapping,
17681                                         max_ptype_num,
17682                                         &count,
17683                                         res->valid_only);
17684 #endif
17685
17686         switch (ret) {
17687         case 0:
17688                 break;
17689         case -ENODEV:
17690                 printf("invalid port_id %d\n", res->port_id);
17691                 break;
17692         case -ENOTSUP:
17693                 printf("function not implemented\n");
17694                 break;
17695         default:
17696                 printf("programming error: (%s)\n", strerror(-ret));
17697         }
17698
17699 #ifdef RTE_LIBRTE_I40E_PMD
17700         if (!ret) {
17701                 for (i = 0; i < count; i++)
17702                         printf("%3d\t0x%08x\n",
17703                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17704         }
17705 #endif
17706 }
17707
17708 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17709         .f = cmd_ptype_mapping_get_parsed,
17710         .data = NULL,
17711         .help_str = "ptype mapping get <port_id> <valid_only>",
17712         .tokens = {
17713                 (void *)&cmd_ptype_mapping_get_ptype,
17714                 (void *)&cmd_ptype_mapping_get_mapping,
17715                 (void *)&cmd_ptype_mapping_get_get,
17716                 (void *)&cmd_ptype_mapping_get_port_id,
17717                 (void *)&cmd_ptype_mapping_get_valid_only,
17718                 NULL,
17719         },
17720 };
17721
17722 /* ptype mapping replace */
17723
17724 /* Common result structure for ptype mapping replace */
17725 struct cmd_ptype_mapping_replace_result {
17726         cmdline_fixed_string_t ptype;
17727         cmdline_fixed_string_t mapping;
17728         cmdline_fixed_string_t replace;
17729         portid_t port_id;
17730         uint32_t target;
17731         uint8_t mask;
17732         uint32_t pkt_type;
17733 };
17734
17735 /* Common CLI fields for ptype mapping replace */
17736 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17737         TOKEN_STRING_INITIALIZER
17738                 (struct cmd_ptype_mapping_replace_result,
17739                  ptype, "ptype");
17740 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17741         TOKEN_STRING_INITIALIZER
17742                 (struct cmd_ptype_mapping_replace_result,
17743                  mapping, "mapping");
17744 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17745         TOKEN_STRING_INITIALIZER
17746                 (struct cmd_ptype_mapping_replace_result,
17747                  replace, "replace");
17748 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17749         TOKEN_NUM_INITIALIZER
17750                 (struct cmd_ptype_mapping_replace_result,
17751                  port_id, UINT16);
17752 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17753         TOKEN_NUM_INITIALIZER
17754                 (struct cmd_ptype_mapping_replace_result,
17755                  target, UINT32);
17756 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17757         TOKEN_NUM_INITIALIZER
17758                 (struct cmd_ptype_mapping_replace_result,
17759                  mask, UINT8);
17760 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17761         TOKEN_NUM_INITIALIZER
17762                 (struct cmd_ptype_mapping_replace_result,
17763                  pkt_type, UINT32);
17764
17765 static void
17766 cmd_ptype_mapping_replace_parsed(
17767         void *parsed_result,
17768         __rte_unused struct cmdline *cl,
17769         __rte_unused void *data)
17770 {
17771         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17772         int ret = -ENOTSUP;
17773
17774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17775                 return;
17776
17777 #ifdef RTE_LIBRTE_I40E_PMD
17778         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17779                                         res->target,
17780                                         res->mask,
17781                                         res->pkt_type);
17782 #endif
17783
17784         switch (ret) {
17785         case 0:
17786                 break;
17787         case -EINVAL:
17788                 printf("invalid ptype 0x%8x or 0x%8x\n",
17789                                 res->target, res->pkt_type);
17790                 break;
17791         case -ENODEV:
17792                 printf("invalid port_id %d\n", res->port_id);
17793                 break;
17794         case -ENOTSUP:
17795                 printf("function not implemented\n");
17796                 break;
17797         default:
17798                 printf("programming error: (%s)\n", strerror(-ret));
17799         }
17800 }
17801
17802 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17803         .f = cmd_ptype_mapping_replace_parsed,
17804         .data = NULL,
17805         .help_str =
17806                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17807         .tokens = {
17808                 (void *)&cmd_ptype_mapping_replace_ptype,
17809                 (void *)&cmd_ptype_mapping_replace_mapping,
17810                 (void *)&cmd_ptype_mapping_replace_replace,
17811                 (void *)&cmd_ptype_mapping_replace_port_id,
17812                 (void *)&cmd_ptype_mapping_replace_target,
17813                 (void *)&cmd_ptype_mapping_replace_mask,
17814                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17815                 NULL,
17816         },
17817 };
17818
17819 /* ptype mapping reset */
17820
17821 /* Common result structure for ptype mapping reset */
17822 struct cmd_ptype_mapping_reset_result {
17823         cmdline_fixed_string_t ptype;
17824         cmdline_fixed_string_t mapping;
17825         cmdline_fixed_string_t reset;
17826         portid_t port_id;
17827 };
17828
17829 /* Common CLI fields for ptype mapping reset*/
17830 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17831         TOKEN_STRING_INITIALIZER
17832                 (struct cmd_ptype_mapping_reset_result,
17833                  ptype, "ptype");
17834 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17835         TOKEN_STRING_INITIALIZER
17836                 (struct cmd_ptype_mapping_reset_result,
17837                  mapping, "mapping");
17838 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17839         TOKEN_STRING_INITIALIZER
17840                 (struct cmd_ptype_mapping_reset_result,
17841                  reset, "reset");
17842 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17843         TOKEN_NUM_INITIALIZER
17844                 (struct cmd_ptype_mapping_reset_result,
17845                  port_id, UINT16);
17846
17847 static void
17848 cmd_ptype_mapping_reset_parsed(
17849         void *parsed_result,
17850         __rte_unused struct cmdline *cl,
17851         __rte_unused void *data)
17852 {
17853         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17854         int ret = -ENOTSUP;
17855
17856         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17857                 return;
17858
17859 #ifdef RTE_LIBRTE_I40E_PMD
17860         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17861 #endif
17862
17863         switch (ret) {
17864         case 0:
17865                 break;
17866         case -ENODEV:
17867                 printf("invalid port_id %d\n", res->port_id);
17868                 break;
17869         case -ENOTSUP:
17870                 printf("function not implemented\n");
17871                 break;
17872         default:
17873                 printf("programming error: (%s)\n", strerror(-ret));
17874         }
17875 }
17876
17877 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17878         .f = cmd_ptype_mapping_reset_parsed,
17879         .data = NULL,
17880         .help_str = "ptype mapping reset <port_id>",
17881         .tokens = {
17882                 (void *)&cmd_ptype_mapping_reset_ptype,
17883                 (void *)&cmd_ptype_mapping_reset_mapping,
17884                 (void *)&cmd_ptype_mapping_reset_reset,
17885                 (void *)&cmd_ptype_mapping_reset_port_id,
17886                 NULL,
17887         },
17888 };
17889
17890 /* ptype mapping update */
17891
17892 /* Common result structure for ptype mapping update */
17893 struct cmd_ptype_mapping_update_result {
17894         cmdline_fixed_string_t ptype;
17895         cmdline_fixed_string_t mapping;
17896         cmdline_fixed_string_t reset;
17897         portid_t port_id;
17898         uint8_t hw_ptype;
17899         uint32_t sw_ptype;
17900 };
17901
17902 /* Common CLI fields for ptype mapping update*/
17903 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17904         TOKEN_STRING_INITIALIZER
17905                 (struct cmd_ptype_mapping_update_result,
17906                  ptype, "ptype");
17907 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17908         TOKEN_STRING_INITIALIZER
17909                 (struct cmd_ptype_mapping_update_result,
17910                  mapping, "mapping");
17911 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17912         TOKEN_STRING_INITIALIZER
17913                 (struct cmd_ptype_mapping_update_result,
17914                  reset, "update");
17915 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17916         TOKEN_NUM_INITIALIZER
17917                 (struct cmd_ptype_mapping_update_result,
17918                  port_id, UINT16);
17919 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17920         TOKEN_NUM_INITIALIZER
17921                 (struct cmd_ptype_mapping_update_result,
17922                  hw_ptype, UINT8);
17923 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17924         TOKEN_NUM_INITIALIZER
17925                 (struct cmd_ptype_mapping_update_result,
17926                  sw_ptype, UINT32);
17927
17928 static void
17929 cmd_ptype_mapping_update_parsed(
17930         void *parsed_result,
17931         __rte_unused struct cmdline *cl,
17932         __rte_unused void *data)
17933 {
17934         struct cmd_ptype_mapping_update_result *res = parsed_result;
17935         int ret = -ENOTSUP;
17936 #ifdef RTE_LIBRTE_I40E_PMD
17937         struct rte_pmd_i40e_ptype_mapping mapping;
17938 #endif
17939         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17940                 return;
17941
17942 #ifdef RTE_LIBRTE_I40E_PMD
17943         mapping.hw_ptype = res->hw_ptype;
17944         mapping.sw_ptype = res->sw_ptype;
17945         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17946                                                 &mapping,
17947                                                 1,
17948                                                 0);
17949 #endif
17950
17951         switch (ret) {
17952         case 0:
17953                 break;
17954         case -EINVAL:
17955                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17956                 break;
17957         case -ENODEV:
17958                 printf("invalid port_id %d\n", res->port_id);
17959                 break;
17960         case -ENOTSUP:
17961                 printf("function not implemented\n");
17962                 break;
17963         default:
17964                 printf("programming error: (%s)\n", strerror(-ret));
17965         }
17966 }
17967
17968 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17969         .f = cmd_ptype_mapping_update_parsed,
17970         .data = NULL,
17971         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17972         .tokens = {
17973                 (void *)&cmd_ptype_mapping_update_ptype,
17974                 (void *)&cmd_ptype_mapping_update_mapping,
17975                 (void *)&cmd_ptype_mapping_update_update,
17976                 (void *)&cmd_ptype_mapping_update_port_id,
17977                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17978                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17979                 NULL,
17980         },
17981 };
17982
17983 /* Common result structure for file commands */
17984 struct cmd_cmdfile_result {
17985         cmdline_fixed_string_t load;
17986         cmdline_fixed_string_t filename;
17987 };
17988
17989 /* Common CLI fields for file commands */
17990 cmdline_parse_token_string_t cmd_load_cmdfile =
17991         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17992 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17993         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17994
17995 static void
17996 cmd_load_from_file_parsed(
17997         void *parsed_result,
17998         __rte_unused struct cmdline *cl,
17999         __rte_unused void *data)
18000 {
18001         struct cmd_cmdfile_result *res = parsed_result;
18002
18003         cmdline_read_from_file(res->filename);
18004 }
18005
18006 cmdline_parse_inst_t cmd_load_from_file = {
18007         .f = cmd_load_from_file_parsed,
18008         .data = NULL,
18009         .help_str = "load <filename>",
18010         .tokens = {
18011                 (void *)&cmd_load_cmdfile,
18012                 (void *)&cmd_load_cmdfile_filename,
18013                 NULL,
18014         },
18015 };
18016
18017 /* Get Rx offloads capabilities */
18018 struct cmd_rx_offload_get_capa_result {
18019         cmdline_fixed_string_t show;
18020         cmdline_fixed_string_t port;
18021         portid_t port_id;
18022         cmdline_fixed_string_t rx_offload;
18023         cmdline_fixed_string_t capabilities;
18024 };
18025
18026 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18027         TOKEN_STRING_INITIALIZER
18028                 (struct cmd_rx_offload_get_capa_result,
18029                  show, "show");
18030 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18031         TOKEN_STRING_INITIALIZER
18032                 (struct cmd_rx_offload_get_capa_result,
18033                  port, "port");
18034 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18035         TOKEN_NUM_INITIALIZER
18036                 (struct cmd_rx_offload_get_capa_result,
18037                  port_id, UINT16);
18038 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18039         TOKEN_STRING_INITIALIZER
18040                 (struct cmd_rx_offload_get_capa_result,
18041                  rx_offload, "rx_offload");
18042 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18043         TOKEN_STRING_INITIALIZER
18044                 (struct cmd_rx_offload_get_capa_result,
18045                  capabilities, "capabilities");
18046
18047 static void
18048 print_rx_offloads(uint64_t offloads)
18049 {
18050         uint64_t single_offload;
18051         int begin;
18052         int end;
18053         int bit;
18054
18055         if (offloads == 0)
18056                 return;
18057
18058         begin = __builtin_ctzll(offloads);
18059         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18060
18061         single_offload = 1ULL << begin;
18062         for (bit = begin; bit < end; bit++) {
18063                 if (offloads & single_offload)
18064                         printf(" %s",
18065                                rte_eth_dev_rx_offload_name(single_offload));
18066                 single_offload <<= 1;
18067         }
18068 }
18069
18070 static void
18071 cmd_rx_offload_get_capa_parsed(
18072         void *parsed_result,
18073         __rte_unused struct cmdline *cl,
18074         __rte_unused void *data)
18075 {
18076         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18077         struct rte_eth_dev_info dev_info;
18078         portid_t port_id = res->port_id;
18079         uint64_t queue_offloads;
18080         uint64_t port_offloads;
18081         int ret;
18082
18083         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18084         if (ret != 0)
18085                 return;
18086
18087         queue_offloads = dev_info.rx_queue_offload_capa;
18088         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18089
18090         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18091         printf("  Per Queue :");
18092         print_rx_offloads(queue_offloads);
18093
18094         printf("\n");
18095         printf("  Per Port  :");
18096         print_rx_offloads(port_offloads);
18097         printf("\n\n");
18098 }
18099
18100 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18101         .f = cmd_rx_offload_get_capa_parsed,
18102         .data = NULL,
18103         .help_str = "show port <port_id> rx_offload capabilities",
18104         .tokens = {
18105                 (void *)&cmd_rx_offload_get_capa_show,
18106                 (void *)&cmd_rx_offload_get_capa_port,
18107                 (void *)&cmd_rx_offload_get_capa_port_id,
18108                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18109                 (void *)&cmd_rx_offload_get_capa_capabilities,
18110                 NULL,
18111         }
18112 };
18113
18114 /* Get Rx offloads configuration */
18115 struct cmd_rx_offload_get_configuration_result {
18116         cmdline_fixed_string_t show;
18117         cmdline_fixed_string_t port;
18118         portid_t port_id;
18119         cmdline_fixed_string_t rx_offload;
18120         cmdline_fixed_string_t configuration;
18121 };
18122
18123 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18124         TOKEN_STRING_INITIALIZER
18125                 (struct cmd_rx_offload_get_configuration_result,
18126                  show, "show");
18127 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18128         TOKEN_STRING_INITIALIZER
18129                 (struct cmd_rx_offload_get_configuration_result,
18130                  port, "port");
18131 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18132         TOKEN_NUM_INITIALIZER
18133                 (struct cmd_rx_offload_get_configuration_result,
18134                  port_id, UINT16);
18135 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18136         TOKEN_STRING_INITIALIZER
18137                 (struct cmd_rx_offload_get_configuration_result,
18138                  rx_offload, "rx_offload");
18139 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18140         TOKEN_STRING_INITIALIZER
18141                 (struct cmd_rx_offload_get_configuration_result,
18142                  configuration, "configuration");
18143
18144 static void
18145 cmd_rx_offload_get_configuration_parsed(
18146         void *parsed_result,
18147         __rte_unused struct cmdline *cl,
18148         __rte_unused void *data)
18149 {
18150         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18151         struct rte_eth_dev_info dev_info;
18152         portid_t port_id = res->port_id;
18153         struct rte_port *port = &ports[port_id];
18154         uint64_t port_offloads;
18155         uint64_t queue_offloads;
18156         uint16_t nb_rx_queues;
18157         int q;
18158         int ret;
18159
18160         printf("Rx Offloading Configuration of port %d :\n", port_id);
18161
18162         port_offloads = port->dev_conf.rxmode.offloads;
18163         printf("  Port :");
18164         print_rx_offloads(port_offloads);
18165         printf("\n");
18166
18167         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18168         if (ret != 0)
18169                 return;
18170
18171         nb_rx_queues = dev_info.nb_rx_queues;
18172         for (q = 0; q < nb_rx_queues; q++) {
18173                 queue_offloads = port->rx_conf[q].offloads;
18174                 printf("  Queue[%2d] :", q);
18175                 print_rx_offloads(queue_offloads);
18176                 printf("\n");
18177         }
18178         printf("\n");
18179 }
18180
18181 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18182         .f = cmd_rx_offload_get_configuration_parsed,
18183         .data = NULL,
18184         .help_str = "show port <port_id> rx_offload configuration",
18185         .tokens = {
18186                 (void *)&cmd_rx_offload_get_configuration_show,
18187                 (void *)&cmd_rx_offload_get_configuration_port,
18188                 (void *)&cmd_rx_offload_get_configuration_port_id,
18189                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18190                 (void *)&cmd_rx_offload_get_configuration_configuration,
18191                 NULL,
18192         }
18193 };
18194
18195 /* Enable/Disable a per port offloading */
18196 struct cmd_config_per_port_rx_offload_result {
18197         cmdline_fixed_string_t port;
18198         cmdline_fixed_string_t config;
18199         portid_t port_id;
18200         cmdline_fixed_string_t rx_offload;
18201         cmdline_fixed_string_t offload;
18202         cmdline_fixed_string_t on_off;
18203 };
18204
18205 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18206         TOKEN_STRING_INITIALIZER
18207                 (struct cmd_config_per_port_rx_offload_result,
18208                  port, "port");
18209 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18210         TOKEN_STRING_INITIALIZER
18211                 (struct cmd_config_per_port_rx_offload_result,
18212                  config, "config");
18213 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18214         TOKEN_NUM_INITIALIZER
18215                 (struct cmd_config_per_port_rx_offload_result,
18216                  port_id, UINT16);
18217 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18218         TOKEN_STRING_INITIALIZER
18219                 (struct cmd_config_per_port_rx_offload_result,
18220                  rx_offload, "rx_offload");
18221 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18222         TOKEN_STRING_INITIALIZER
18223                 (struct cmd_config_per_port_rx_offload_result,
18224                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18225                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18226                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18227                            "scatter#timestamp#security#keep_crc#rss_hash");
18228 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18229         TOKEN_STRING_INITIALIZER
18230                 (struct cmd_config_per_port_rx_offload_result,
18231                  on_off, "on#off");
18232
18233 static uint64_t
18234 search_rx_offload(const char *name)
18235 {
18236         uint64_t single_offload;
18237         const char *single_name;
18238         int found = 0;
18239         unsigned int bit;
18240
18241         single_offload = 1;
18242         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18243                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18244                 if (!strcasecmp(single_name, name)) {
18245                         found = 1;
18246                         break;
18247                 }
18248                 single_offload <<= 1;
18249         }
18250
18251         if (found)
18252                 return single_offload;
18253
18254         return 0;
18255 }
18256
18257 static void
18258 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18259                                 __rte_unused struct cmdline *cl,
18260                                 __rte_unused void *data)
18261 {
18262         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18263         portid_t port_id = res->port_id;
18264         struct rte_eth_dev_info dev_info;
18265         struct rte_port *port = &ports[port_id];
18266         uint64_t single_offload;
18267         uint16_t nb_rx_queues;
18268         int q;
18269         int ret;
18270
18271         if (port->port_status != RTE_PORT_STOPPED) {
18272                 printf("Error: Can't config offload when Port %d "
18273                        "is not stopped\n", port_id);
18274                 return;
18275         }
18276
18277         single_offload = search_rx_offload(res->offload);
18278         if (single_offload == 0) {
18279                 printf("Unknown offload name: %s\n", res->offload);
18280                 return;
18281         }
18282
18283         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18284         if (ret != 0)
18285                 return;
18286
18287         nb_rx_queues = dev_info.nb_rx_queues;
18288         if (!strcmp(res->on_off, "on")) {
18289                 port->dev_conf.rxmode.offloads |= single_offload;
18290                 for (q = 0; q < nb_rx_queues; q++)
18291                         port->rx_conf[q].offloads |= single_offload;
18292         } else {
18293                 port->dev_conf.rxmode.offloads &= ~single_offload;
18294                 for (q = 0; q < nb_rx_queues; q++)
18295                         port->rx_conf[q].offloads &= ~single_offload;
18296         }
18297
18298         cmd_reconfig_device_queue(port_id, 1, 1);
18299 }
18300
18301 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18302         .f = cmd_config_per_port_rx_offload_parsed,
18303         .data = NULL,
18304         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18305                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18306                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18307                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18308                     "on|off",
18309         .tokens = {
18310                 (void *)&cmd_config_per_port_rx_offload_result_port,
18311                 (void *)&cmd_config_per_port_rx_offload_result_config,
18312                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18313                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18314                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18315                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18316                 NULL,
18317         }
18318 };
18319
18320 /* Enable/Disable a per queue offloading */
18321 struct cmd_config_per_queue_rx_offload_result {
18322         cmdline_fixed_string_t port;
18323         portid_t port_id;
18324         cmdline_fixed_string_t rxq;
18325         uint16_t queue_id;
18326         cmdline_fixed_string_t rx_offload;
18327         cmdline_fixed_string_t offload;
18328         cmdline_fixed_string_t on_off;
18329 };
18330
18331 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18332         TOKEN_STRING_INITIALIZER
18333                 (struct cmd_config_per_queue_rx_offload_result,
18334                  port, "port");
18335 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18336         TOKEN_NUM_INITIALIZER
18337                 (struct cmd_config_per_queue_rx_offload_result,
18338                  port_id, UINT16);
18339 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18340         TOKEN_STRING_INITIALIZER
18341                 (struct cmd_config_per_queue_rx_offload_result,
18342                  rxq, "rxq");
18343 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18344         TOKEN_NUM_INITIALIZER
18345                 (struct cmd_config_per_queue_rx_offload_result,
18346                  queue_id, UINT16);
18347 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18348         TOKEN_STRING_INITIALIZER
18349                 (struct cmd_config_per_queue_rx_offload_result,
18350                  rx_offload, "rx_offload");
18351 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18352         TOKEN_STRING_INITIALIZER
18353                 (struct cmd_config_per_queue_rx_offload_result,
18354                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18355                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18356                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18357                            "scatter#timestamp#security#keep_crc");
18358 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18359         TOKEN_STRING_INITIALIZER
18360                 (struct cmd_config_per_queue_rx_offload_result,
18361                  on_off, "on#off");
18362
18363 static void
18364 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18365                                 __rte_unused struct cmdline *cl,
18366                                 __rte_unused void *data)
18367 {
18368         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18369         struct rte_eth_dev_info dev_info;
18370         portid_t port_id = res->port_id;
18371         uint16_t queue_id = res->queue_id;
18372         struct rte_port *port = &ports[port_id];
18373         uint64_t single_offload;
18374         int ret;
18375
18376         if (port->port_status != RTE_PORT_STOPPED) {
18377                 printf("Error: Can't config offload when Port %d "
18378                        "is not stopped\n", port_id);
18379                 return;
18380         }
18381
18382         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18383         if (ret != 0)
18384                 return;
18385
18386         if (queue_id >= dev_info.nb_rx_queues) {
18387                 printf("Error: input queue_id should be 0 ... "
18388                        "%d\n", dev_info.nb_rx_queues - 1);
18389                 return;
18390         }
18391
18392         single_offload = search_rx_offload(res->offload);
18393         if (single_offload == 0) {
18394                 printf("Unknown offload name: %s\n", res->offload);
18395                 return;
18396         }
18397
18398         if (!strcmp(res->on_off, "on"))
18399                 port->rx_conf[queue_id].offloads |= single_offload;
18400         else
18401                 port->rx_conf[queue_id].offloads &= ~single_offload;
18402
18403         cmd_reconfig_device_queue(port_id, 1, 1);
18404 }
18405
18406 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18407         .f = cmd_config_per_queue_rx_offload_parsed,
18408         .data = NULL,
18409         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18410                     "vlan_strip|ipv4_cksum|"
18411                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18412                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18413                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18414                     "on|off",
18415         .tokens = {
18416                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18417                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18418                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18419                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18420                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18421                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18422                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18423                 NULL,
18424         }
18425 };
18426
18427 /* Get Tx offloads capabilities */
18428 struct cmd_tx_offload_get_capa_result {
18429         cmdline_fixed_string_t show;
18430         cmdline_fixed_string_t port;
18431         portid_t port_id;
18432         cmdline_fixed_string_t tx_offload;
18433         cmdline_fixed_string_t capabilities;
18434 };
18435
18436 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18437         TOKEN_STRING_INITIALIZER
18438                 (struct cmd_tx_offload_get_capa_result,
18439                  show, "show");
18440 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18441         TOKEN_STRING_INITIALIZER
18442                 (struct cmd_tx_offload_get_capa_result,
18443                  port, "port");
18444 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18445         TOKEN_NUM_INITIALIZER
18446                 (struct cmd_tx_offload_get_capa_result,
18447                  port_id, UINT16);
18448 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18449         TOKEN_STRING_INITIALIZER
18450                 (struct cmd_tx_offload_get_capa_result,
18451                  tx_offload, "tx_offload");
18452 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18453         TOKEN_STRING_INITIALIZER
18454                 (struct cmd_tx_offload_get_capa_result,
18455                  capabilities, "capabilities");
18456
18457 static void
18458 print_tx_offloads(uint64_t offloads)
18459 {
18460         uint64_t single_offload;
18461         int begin;
18462         int end;
18463         int bit;
18464
18465         if (offloads == 0)
18466                 return;
18467
18468         begin = __builtin_ctzll(offloads);
18469         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18470
18471         single_offload = 1ULL << begin;
18472         for (bit = begin; bit < end; bit++) {
18473                 if (offloads & single_offload)
18474                         printf(" %s",
18475                                rte_eth_dev_tx_offload_name(single_offload));
18476                 single_offload <<= 1;
18477         }
18478 }
18479
18480 static void
18481 cmd_tx_offload_get_capa_parsed(
18482         void *parsed_result,
18483         __rte_unused struct cmdline *cl,
18484         __rte_unused void *data)
18485 {
18486         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18487         struct rte_eth_dev_info dev_info;
18488         portid_t port_id = res->port_id;
18489         uint64_t queue_offloads;
18490         uint64_t port_offloads;
18491         int ret;
18492
18493         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18494         if (ret != 0)
18495                 return;
18496
18497         queue_offloads = dev_info.tx_queue_offload_capa;
18498         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18499
18500         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18501         printf("  Per Queue :");
18502         print_tx_offloads(queue_offloads);
18503
18504         printf("\n");
18505         printf("  Per Port  :");
18506         print_tx_offloads(port_offloads);
18507         printf("\n\n");
18508 }
18509
18510 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18511         .f = cmd_tx_offload_get_capa_parsed,
18512         .data = NULL,
18513         .help_str = "show port <port_id> tx_offload capabilities",
18514         .tokens = {
18515                 (void *)&cmd_tx_offload_get_capa_show,
18516                 (void *)&cmd_tx_offload_get_capa_port,
18517                 (void *)&cmd_tx_offload_get_capa_port_id,
18518                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18519                 (void *)&cmd_tx_offload_get_capa_capabilities,
18520                 NULL,
18521         }
18522 };
18523
18524 /* Get Tx offloads configuration */
18525 struct cmd_tx_offload_get_configuration_result {
18526         cmdline_fixed_string_t show;
18527         cmdline_fixed_string_t port;
18528         portid_t port_id;
18529         cmdline_fixed_string_t tx_offload;
18530         cmdline_fixed_string_t configuration;
18531 };
18532
18533 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18534         TOKEN_STRING_INITIALIZER
18535                 (struct cmd_tx_offload_get_configuration_result,
18536                  show, "show");
18537 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18538         TOKEN_STRING_INITIALIZER
18539                 (struct cmd_tx_offload_get_configuration_result,
18540                  port, "port");
18541 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18542         TOKEN_NUM_INITIALIZER
18543                 (struct cmd_tx_offload_get_configuration_result,
18544                  port_id, UINT16);
18545 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18546         TOKEN_STRING_INITIALIZER
18547                 (struct cmd_tx_offload_get_configuration_result,
18548                  tx_offload, "tx_offload");
18549 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18550         TOKEN_STRING_INITIALIZER
18551                 (struct cmd_tx_offload_get_configuration_result,
18552                  configuration, "configuration");
18553
18554 static void
18555 cmd_tx_offload_get_configuration_parsed(
18556         void *parsed_result,
18557         __rte_unused struct cmdline *cl,
18558         __rte_unused void *data)
18559 {
18560         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18561         struct rte_eth_dev_info dev_info;
18562         portid_t port_id = res->port_id;
18563         struct rte_port *port = &ports[port_id];
18564         uint64_t port_offloads;
18565         uint64_t queue_offloads;
18566         uint16_t nb_tx_queues;
18567         int q;
18568         int ret;
18569
18570         printf("Tx Offloading Configuration of port %d :\n", port_id);
18571
18572         port_offloads = port->dev_conf.txmode.offloads;
18573         printf("  Port :");
18574         print_tx_offloads(port_offloads);
18575         printf("\n");
18576
18577         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18578         if (ret != 0)
18579                 return;
18580
18581         nb_tx_queues = dev_info.nb_tx_queues;
18582         for (q = 0; q < nb_tx_queues; q++) {
18583                 queue_offloads = port->tx_conf[q].offloads;
18584                 printf("  Queue[%2d] :", q);
18585                 print_tx_offloads(queue_offloads);
18586                 printf("\n");
18587         }
18588         printf("\n");
18589 }
18590
18591 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18592         .f = cmd_tx_offload_get_configuration_parsed,
18593         .data = NULL,
18594         .help_str = "show port <port_id> tx_offload configuration",
18595         .tokens = {
18596                 (void *)&cmd_tx_offload_get_configuration_show,
18597                 (void *)&cmd_tx_offload_get_configuration_port,
18598                 (void *)&cmd_tx_offload_get_configuration_port_id,
18599                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18600                 (void *)&cmd_tx_offload_get_configuration_configuration,
18601                 NULL,
18602         }
18603 };
18604
18605 /* Enable/Disable a per port offloading */
18606 struct cmd_config_per_port_tx_offload_result {
18607         cmdline_fixed_string_t port;
18608         cmdline_fixed_string_t config;
18609         portid_t port_id;
18610         cmdline_fixed_string_t tx_offload;
18611         cmdline_fixed_string_t offload;
18612         cmdline_fixed_string_t on_off;
18613 };
18614
18615 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18616         TOKEN_STRING_INITIALIZER
18617                 (struct cmd_config_per_port_tx_offload_result,
18618                  port, "port");
18619 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18620         TOKEN_STRING_INITIALIZER
18621                 (struct cmd_config_per_port_tx_offload_result,
18622                  config, "config");
18623 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18624         TOKEN_NUM_INITIALIZER
18625                 (struct cmd_config_per_port_tx_offload_result,
18626                  port_id, UINT16);
18627 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18628         TOKEN_STRING_INITIALIZER
18629                 (struct cmd_config_per_port_tx_offload_result,
18630                  tx_offload, "tx_offload");
18631 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18632         TOKEN_STRING_INITIALIZER
18633                 (struct cmd_config_per_port_tx_offload_result,
18634                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18635                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18636                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18637                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18638                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18639 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18640         TOKEN_STRING_INITIALIZER
18641                 (struct cmd_config_per_port_tx_offload_result,
18642                  on_off, "on#off");
18643
18644 static uint64_t
18645 search_tx_offload(const char *name)
18646 {
18647         uint64_t single_offload;
18648         const char *single_name;
18649         int found = 0;
18650         unsigned int bit;
18651
18652         single_offload = 1;
18653         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18654                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18655                 if (single_name == NULL)
18656                         break;
18657                 if (!strcasecmp(single_name, name)) {
18658                         found = 1;
18659                         break;
18660                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18661                         break;
18662                 single_offload <<= 1;
18663         }
18664
18665         if (found)
18666                 return single_offload;
18667
18668         return 0;
18669 }
18670
18671 static void
18672 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18673                                 __rte_unused struct cmdline *cl,
18674                                 __rte_unused void *data)
18675 {
18676         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18677         portid_t port_id = res->port_id;
18678         struct rte_eth_dev_info dev_info;
18679         struct rte_port *port = &ports[port_id];
18680         uint64_t single_offload;
18681         uint16_t nb_tx_queues;
18682         int q;
18683         int ret;
18684
18685         if (port->port_status != RTE_PORT_STOPPED) {
18686                 printf("Error: Can't config offload when Port %d "
18687                        "is not stopped\n", port_id);
18688                 return;
18689         }
18690
18691         single_offload = search_tx_offload(res->offload);
18692         if (single_offload == 0) {
18693                 printf("Unknown offload name: %s\n", res->offload);
18694                 return;
18695         }
18696
18697         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18698         if (ret != 0)
18699                 return;
18700
18701         nb_tx_queues = dev_info.nb_tx_queues;
18702         if (!strcmp(res->on_off, "on")) {
18703                 port->dev_conf.txmode.offloads |= single_offload;
18704                 for (q = 0; q < nb_tx_queues; q++)
18705                         port->tx_conf[q].offloads |= single_offload;
18706         } else {
18707                 port->dev_conf.txmode.offloads &= ~single_offload;
18708                 for (q = 0; q < nb_tx_queues; q++)
18709                         port->tx_conf[q].offloads &= ~single_offload;
18710         }
18711
18712         cmd_reconfig_device_queue(port_id, 1, 1);
18713 }
18714
18715 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18716         .f = cmd_config_per_port_tx_offload_parsed,
18717         .data = NULL,
18718         .help_str = "port config <port_id> tx_offload "
18719                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18720                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18721                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18722                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18723                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18724         .tokens = {
18725                 (void *)&cmd_config_per_port_tx_offload_result_port,
18726                 (void *)&cmd_config_per_port_tx_offload_result_config,
18727                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18728                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18729                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18730                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18731                 NULL,
18732         }
18733 };
18734
18735 /* Enable/Disable a per queue offloading */
18736 struct cmd_config_per_queue_tx_offload_result {
18737         cmdline_fixed_string_t port;
18738         portid_t port_id;
18739         cmdline_fixed_string_t txq;
18740         uint16_t queue_id;
18741         cmdline_fixed_string_t tx_offload;
18742         cmdline_fixed_string_t offload;
18743         cmdline_fixed_string_t on_off;
18744 };
18745
18746 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18747         TOKEN_STRING_INITIALIZER
18748                 (struct cmd_config_per_queue_tx_offload_result,
18749                  port, "port");
18750 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18751         TOKEN_NUM_INITIALIZER
18752                 (struct cmd_config_per_queue_tx_offload_result,
18753                  port_id, UINT16);
18754 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18755         TOKEN_STRING_INITIALIZER
18756                 (struct cmd_config_per_queue_tx_offload_result,
18757                  txq, "txq");
18758 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18759         TOKEN_NUM_INITIALIZER
18760                 (struct cmd_config_per_queue_tx_offload_result,
18761                  queue_id, UINT16);
18762 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18763         TOKEN_STRING_INITIALIZER
18764                 (struct cmd_config_per_queue_tx_offload_result,
18765                  tx_offload, "tx_offload");
18766 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18767         TOKEN_STRING_INITIALIZER
18768                 (struct cmd_config_per_queue_tx_offload_result,
18769                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18770                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18771                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18772                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18773                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18774 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18775         TOKEN_STRING_INITIALIZER
18776                 (struct cmd_config_per_queue_tx_offload_result,
18777                  on_off, "on#off");
18778
18779 static void
18780 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18781                                 __rte_unused struct cmdline *cl,
18782                                 __rte_unused void *data)
18783 {
18784         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18785         struct rte_eth_dev_info dev_info;
18786         portid_t port_id = res->port_id;
18787         uint16_t queue_id = res->queue_id;
18788         struct rte_port *port = &ports[port_id];
18789         uint64_t single_offload;
18790         int ret;
18791
18792         if (port->port_status != RTE_PORT_STOPPED) {
18793                 printf("Error: Can't config offload when Port %d "
18794                        "is not stopped\n", port_id);
18795                 return;
18796         }
18797
18798         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18799         if (ret != 0)
18800                 return;
18801
18802         if (queue_id >= dev_info.nb_tx_queues) {
18803                 printf("Error: input queue_id should be 0 ... "
18804                        "%d\n", dev_info.nb_tx_queues - 1);
18805                 return;
18806         }
18807
18808         single_offload = search_tx_offload(res->offload);
18809         if (single_offload == 0) {
18810                 printf("Unknown offload name: %s\n", res->offload);
18811                 return;
18812         }
18813
18814         if (!strcmp(res->on_off, "on"))
18815                 port->tx_conf[queue_id].offloads |= single_offload;
18816         else
18817                 port->tx_conf[queue_id].offloads &= ~single_offload;
18818
18819         cmd_reconfig_device_queue(port_id, 1, 1);
18820 }
18821
18822 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18823         .f = cmd_config_per_queue_tx_offload_parsed,
18824         .data = NULL,
18825         .help_str = "port <port_id> txq <queue_id> tx_offload "
18826                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18827                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18828                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18829                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18830                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18831                     "on|off",
18832         .tokens = {
18833                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18834                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18835                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18836                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18837                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18838                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18839                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18840                 NULL,
18841         }
18842 };
18843
18844 /* *** configure tx_metadata for specific port *** */
18845 struct cmd_config_tx_metadata_specific_result {
18846         cmdline_fixed_string_t port;
18847         cmdline_fixed_string_t keyword;
18848         uint16_t port_id;
18849         cmdline_fixed_string_t item;
18850         uint32_t value;
18851 };
18852
18853 static void
18854 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18855                                 __rte_unused struct cmdline *cl,
18856                                 __rte_unused void *data)
18857 {
18858         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18859
18860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18861                 return;
18862         ports[res->port_id].tx_metadata = res->value;
18863         /* Add/remove callback to insert valid metadata in every Tx packet. */
18864         if (ports[res->port_id].tx_metadata)
18865                 add_tx_md_callback(res->port_id);
18866         else
18867                 remove_tx_md_callback(res->port_id);
18868         rte_flow_dynf_metadata_register();
18869 }
18870
18871 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18872         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18873                         port, "port");
18874 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18875         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18876                         keyword, "config");
18877 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18878         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18879                         port_id, UINT16);
18880 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18881         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18882                         item, "tx_metadata");
18883 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18884         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18885                         value, UINT32);
18886
18887 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18888         .f = cmd_config_tx_metadata_specific_parsed,
18889         .data = NULL,
18890         .help_str = "port config <port_id> tx_metadata <value>",
18891         .tokens = {
18892                 (void *)&cmd_config_tx_metadata_specific_port,
18893                 (void *)&cmd_config_tx_metadata_specific_keyword,
18894                 (void *)&cmd_config_tx_metadata_specific_id,
18895                 (void *)&cmd_config_tx_metadata_specific_item,
18896                 (void *)&cmd_config_tx_metadata_specific_value,
18897                 NULL,
18898         },
18899 };
18900
18901 /* *** set dynf *** */
18902 struct cmd_config_tx_dynf_specific_result {
18903         cmdline_fixed_string_t port;
18904         cmdline_fixed_string_t keyword;
18905         uint16_t port_id;
18906         cmdline_fixed_string_t item;
18907         cmdline_fixed_string_t name;
18908         cmdline_fixed_string_t value;
18909 };
18910
18911 static void
18912 cmd_config_dynf_specific_parsed(void *parsed_result,
18913                                 __rte_unused struct cmdline *cl,
18914                                 __rte_unused void *data)
18915 {
18916         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18917         struct rte_mbuf_dynflag desc_flag;
18918         int flag;
18919         uint64_t old_port_flags;
18920
18921         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18922                 return;
18923         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18924         if (flag <= 0) {
18925                 if (strlcpy(desc_flag.name, res->name,
18926                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18927                         printf("Flag name too long\n");
18928                         return;
18929                 }
18930                 desc_flag.flags = 0;
18931                 flag = rte_mbuf_dynflag_register(&desc_flag);
18932                 if (flag < 0) {
18933                         printf("Can't register flag\n");
18934                         return;
18935                 }
18936                 strcpy(dynf_names[flag], desc_flag.name);
18937         }
18938         old_port_flags = ports[res->port_id].mbuf_dynf;
18939         if (!strcmp(res->value, "set")) {
18940                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18941                 if (old_port_flags == 0)
18942                         add_tx_dynf_callback(res->port_id);
18943         } else {
18944                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18945                 if (ports[res->port_id].mbuf_dynf == 0)
18946                         remove_tx_dynf_callback(res->port_id);
18947         }
18948 }
18949
18950 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18951         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18952                         keyword, "port");
18953 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18954         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18955                         keyword, "config");
18956 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18957         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18958                         port_id, UINT16);
18959 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18960         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18961                         item, "dynf");
18962 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18963         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18964                         name, NULL);
18965 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18966         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18967                         value, "set#clear");
18968
18969 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18970         .f = cmd_config_dynf_specific_parsed,
18971         .data = NULL,
18972         .help_str = "port config <port id> dynf <name> set|clear",
18973         .tokens = {
18974                 (void *)&cmd_config_tx_dynf_specific_port,
18975                 (void *)&cmd_config_tx_dynf_specific_keyword,
18976                 (void *)&cmd_config_tx_dynf_specific_port_id,
18977                 (void *)&cmd_config_tx_dynf_specific_item,
18978                 (void *)&cmd_config_tx_dynf_specific_name,
18979                 (void *)&cmd_config_tx_dynf_specific_value,
18980                 NULL,
18981         },
18982 };
18983
18984 /* *** display tx_metadata per port configuration *** */
18985 struct cmd_show_tx_metadata_result {
18986         cmdline_fixed_string_t cmd_show;
18987         cmdline_fixed_string_t cmd_port;
18988         cmdline_fixed_string_t cmd_keyword;
18989         portid_t cmd_pid;
18990 };
18991
18992 static void
18993 cmd_show_tx_metadata_parsed(void *parsed_result,
18994                 __rte_unused struct cmdline *cl,
18995                 __rte_unused void *data)
18996 {
18997         struct cmd_show_tx_metadata_result *res = parsed_result;
18998
18999         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19000                 printf("invalid port id %u\n", res->cmd_pid);
19001                 return;
19002         }
19003         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19004                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19005                        ports[res->cmd_pid].tx_metadata);
19006         }
19007 }
19008
19009 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19010         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19011                         cmd_show, "show");
19012 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19013         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19014                         cmd_port, "port");
19015 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19016         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19017                         cmd_pid, UINT16);
19018 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19019         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19020                         cmd_keyword, "tx_metadata");
19021
19022 cmdline_parse_inst_t cmd_show_tx_metadata = {
19023         .f = cmd_show_tx_metadata_parsed,
19024         .data = NULL,
19025         .help_str = "show port <port_id> tx_metadata",
19026         .tokens = {
19027                 (void *)&cmd_show_tx_metadata_show,
19028                 (void *)&cmd_show_tx_metadata_port,
19029                 (void *)&cmd_show_tx_metadata_pid,
19030                 (void *)&cmd_show_tx_metadata_keyword,
19031                 NULL,
19032         },
19033 };
19034
19035 /* show port supported ptypes */
19036
19037 /* Common result structure for show port ptypes */
19038 struct cmd_show_port_supported_ptypes_result {
19039         cmdline_fixed_string_t show;
19040         cmdline_fixed_string_t port;
19041         portid_t port_id;
19042         cmdline_fixed_string_t ptypes;
19043 };
19044
19045 /* Common CLI fields for show port ptypes */
19046 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19047         TOKEN_STRING_INITIALIZER
19048                 (struct cmd_show_port_supported_ptypes_result,
19049                  show, "show");
19050 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19051         TOKEN_STRING_INITIALIZER
19052                 (struct cmd_show_port_supported_ptypes_result,
19053                  port, "port");
19054 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19055         TOKEN_NUM_INITIALIZER
19056                 (struct cmd_show_port_supported_ptypes_result,
19057                  port_id, UINT16);
19058 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19059         TOKEN_STRING_INITIALIZER
19060                 (struct cmd_show_port_supported_ptypes_result,
19061                  ptypes, "ptypes");
19062
19063 static void
19064 cmd_show_port_supported_ptypes_parsed(
19065         void *parsed_result,
19066         __rte_unused struct cmdline *cl,
19067         __rte_unused void *data)
19068 {
19069 #define RSVD_PTYPE_MASK       0xf0000000
19070 #define MAX_PTYPES_PER_LAYER  16
19071 #define LTYPE_NAMESIZE        32
19072 #define PTYPE_NAMESIZE        256
19073         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19074         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19075         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19076         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19077         uint16_t port_id = res->port_id;
19078         int ret, i;
19079
19080         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19081         if (ret < 0)
19082                 return;
19083
19084         while (ptype_mask != RSVD_PTYPE_MASK) {
19085
19086                 switch (ptype_mask) {
19087                 case RTE_PTYPE_L2_MASK:
19088                         strlcpy(ltype, "L2", sizeof(ltype));
19089                         break;
19090                 case RTE_PTYPE_L3_MASK:
19091                         strlcpy(ltype, "L3", sizeof(ltype));
19092                         break;
19093                 case RTE_PTYPE_L4_MASK:
19094                         strlcpy(ltype, "L4", sizeof(ltype));
19095                         break;
19096                 case RTE_PTYPE_TUNNEL_MASK:
19097                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19098                         break;
19099                 case RTE_PTYPE_INNER_L2_MASK:
19100                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19101                         break;
19102                 case RTE_PTYPE_INNER_L3_MASK:
19103                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19104                         break;
19105                 case RTE_PTYPE_INNER_L4_MASK:
19106                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19107                         break;
19108                 default:
19109                         return;
19110                 }
19111
19112                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19113                                                        ptype_mask, ptypes,
19114                                                        MAX_PTYPES_PER_LAYER);
19115
19116                 if (ret > 0)
19117                         printf("Supported %s ptypes:\n", ltype);
19118                 else
19119                         printf("%s ptypes unsupported\n", ltype);
19120
19121                 for (i = 0; i < ret; ++i) {
19122                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19123                         printf("%s\n", buf);
19124                 }
19125
19126                 ptype_mask <<= 4;
19127         }
19128 }
19129
19130 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19131         .f = cmd_show_port_supported_ptypes_parsed,
19132         .data = NULL,
19133         .help_str = "show port <port_id> ptypes",
19134         .tokens = {
19135                 (void *)&cmd_show_port_supported_ptypes_show,
19136                 (void *)&cmd_show_port_supported_ptypes_port,
19137                 (void *)&cmd_show_port_supported_ptypes_port_id,
19138                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19139                 NULL,
19140         },
19141 };
19142
19143 /* *** display rx/tx descriptor status *** */
19144 struct cmd_show_rx_tx_desc_status_result {
19145         cmdline_fixed_string_t cmd_show;
19146         cmdline_fixed_string_t cmd_port;
19147         cmdline_fixed_string_t cmd_keyword;
19148         cmdline_fixed_string_t cmd_desc;
19149         cmdline_fixed_string_t cmd_status;
19150         portid_t cmd_pid;
19151         portid_t cmd_qid;
19152         portid_t cmd_did;
19153 };
19154
19155 static void
19156 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19157                 __rte_unused struct cmdline *cl,
19158                 __rte_unused void *data)
19159 {
19160         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19161         int rc;
19162
19163         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19164                 printf("invalid port id %u\n", res->cmd_pid);
19165                 return;
19166         }
19167
19168         if (!strcmp(res->cmd_keyword, "rxq")) {
19169                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19170                                              res->cmd_did);
19171                 if (rc < 0) {
19172                         printf("Invalid queueid = %d\n", res->cmd_qid);
19173                         return;
19174                 }
19175                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19176                         printf("Desc status = AVAILABLE\n");
19177                 else if (rc == RTE_ETH_RX_DESC_DONE)
19178                         printf("Desc status = DONE\n");
19179                 else
19180                         printf("Desc status = UNAVAILABLE\n");
19181         } else if (!strcmp(res->cmd_keyword, "txq")) {
19182                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19183                                              res->cmd_did);
19184                 if (rc < 0) {
19185                         printf("Invalid queueid = %d\n", res->cmd_qid);
19186                         return;
19187                 }
19188                 if (rc == RTE_ETH_TX_DESC_FULL)
19189                         printf("Desc status = FULL\n");
19190                 else if (rc == RTE_ETH_TX_DESC_DONE)
19191                         printf("Desc status = DONE\n");
19192                 else
19193                         printf("Desc status = UNAVAILABLE\n");
19194         }
19195 }
19196
19197 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19198         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19199                         cmd_show, "show");
19200 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19201         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19202                         cmd_port, "port");
19203 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19204         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19205                         cmd_pid, UINT16);
19206 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19207         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19208                         cmd_keyword, "rxq#txq");
19209 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19210         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19211                         cmd_qid, UINT16);
19212 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19213         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19214                         cmd_desc, "desc");
19215 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19216         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19217                         cmd_did, UINT16);
19218 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19219         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19220                         cmd_status, "status");
19221 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19222         .f = cmd_show_rx_tx_desc_status_parsed,
19223         .data = NULL,
19224         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19225                 "status",
19226         .tokens = {
19227                 (void *)&cmd_show_rx_tx_desc_status_show,
19228                 (void *)&cmd_show_rx_tx_desc_status_port,
19229                 (void *)&cmd_show_rx_tx_desc_status_pid,
19230                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19231                 (void *)&cmd_show_rx_tx_desc_status_qid,
19232                 (void *)&cmd_show_rx_tx_desc_status_desc,
19233                 (void *)&cmd_show_rx_tx_desc_status_did,
19234                 (void *)&cmd_show_rx_tx_desc_status_status,
19235                 NULL,
19236         },
19237 };
19238
19239 /* Common result structure for set port ptypes */
19240 struct cmd_set_port_ptypes_result {
19241         cmdline_fixed_string_t set;
19242         cmdline_fixed_string_t port;
19243         portid_t port_id;
19244         cmdline_fixed_string_t ptype_mask;
19245         uint32_t mask;
19246 };
19247
19248 /* Common CLI fields for set port ptypes */
19249 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19250         TOKEN_STRING_INITIALIZER
19251                 (struct cmd_set_port_ptypes_result,
19252                  set, "set");
19253 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19254         TOKEN_STRING_INITIALIZER
19255                 (struct cmd_set_port_ptypes_result,
19256                  port, "port");
19257 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19258         TOKEN_NUM_INITIALIZER
19259                 (struct cmd_set_port_ptypes_result,
19260                  port_id, UINT16);
19261 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19262         TOKEN_STRING_INITIALIZER
19263                 (struct cmd_set_port_ptypes_result,
19264                  ptype_mask, "ptype_mask");
19265 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19266         TOKEN_NUM_INITIALIZER
19267                 (struct cmd_set_port_ptypes_result,
19268                  mask, UINT32);
19269
19270 static void
19271 cmd_set_port_ptypes_parsed(
19272         void *parsed_result,
19273         __rte_unused struct cmdline *cl,
19274         __rte_unused void *data)
19275 {
19276         struct cmd_set_port_ptypes_result *res = parsed_result;
19277 #define PTYPE_NAMESIZE        256
19278         char ptype_name[PTYPE_NAMESIZE];
19279         uint16_t port_id = res->port_id;
19280         uint32_t ptype_mask = res->mask;
19281         int ret, i;
19282
19283         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19284                                                NULL, 0);
19285         if (ret <= 0) {
19286                 printf("Port %d doesn't support any ptypes.\n", port_id);
19287                 return;
19288         }
19289
19290         uint32_t ptypes[ret];
19291
19292         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19293         if (ret < 0) {
19294                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19295                 return;
19296         }
19297
19298         printf("Successfully set following ptypes for Port %d\n", port_id);
19299         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19300                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19301                 printf("%s\n", ptype_name);
19302         }
19303
19304         clear_ptypes = false;
19305 }
19306
19307 cmdline_parse_inst_t cmd_set_port_ptypes = {
19308         .f = cmd_set_port_ptypes_parsed,
19309         .data = NULL,
19310         .help_str = "set port <port_id> ptype_mask <mask>",
19311         .tokens = {
19312                 (void *)&cmd_set_port_ptypes_set,
19313                 (void *)&cmd_set_port_ptypes_port,
19314                 (void *)&cmd_set_port_ptypes_port_id,
19315                 (void *)&cmd_set_port_ptypes_mask_str,
19316                 (void *)&cmd_set_port_ptypes_mask_u32,
19317                 NULL,
19318         },
19319 };
19320
19321 /* *** display mac addresses added to a port *** */
19322 struct cmd_showport_macs_result {
19323         cmdline_fixed_string_t cmd_show;
19324         cmdline_fixed_string_t cmd_port;
19325         cmdline_fixed_string_t cmd_keyword;
19326         portid_t cmd_pid;
19327 };
19328
19329 static void
19330 cmd_showport_macs_parsed(void *parsed_result,
19331                 __rte_unused struct cmdline *cl,
19332                 __rte_unused void *data)
19333 {
19334         struct cmd_showport_macs_result *res = parsed_result;
19335
19336         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19337                 return;
19338
19339         if (!strcmp(res->cmd_keyword, "macs"))
19340                 show_macs(res->cmd_pid);
19341         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19342                 show_mcast_macs(res->cmd_pid);
19343 }
19344
19345 cmdline_parse_token_string_t cmd_showport_macs_show =
19346         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19347                         cmd_show, "show");
19348 cmdline_parse_token_string_t cmd_showport_macs_port =
19349         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19350                         cmd_port, "port");
19351 cmdline_parse_token_num_t cmd_showport_macs_pid =
19352         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19353                         cmd_pid, UINT16);
19354 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19355         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19356                         cmd_keyword, "macs#mcast_macs");
19357
19358 cmdline_parse_inst_t cmd_showport_macs = {
19359         .f = cmd_showport_macs_parsed,
19360         .data = NULL,
19361         .help_str = "show port <port_id> macs|mcast_macs",
19362         .tokens = {
19363                 (void *)&cmd_showport_macs_show,
19364                 (void *)&cmd_showport_macs_port,
19365                 (void *)&cmd_showport_macs_pid,
19366                 (void *)&cmd_showport_macs_keyword,
19367                 NULL,
19368         },
19369 };
19370
19371 /* ******************************************************************************** */
19372
19373 /* list of instructions */
19374 cmdline_parse_ctx_t main_ctx[] = {
19375         (cmdline_parse_inst_t *)&cmd_help_brief,
19376         (cmdline_parse_inst_t *)&cmd_help_long,
19377         (cmdline_parse_inst_t *)&cmd_quit,
19378         (cmdline_parse_inst_t *)&cmd_load_from_file,
19379         (cmdline_parse_inst_t *)&cmd_showport,
19380         (cmdline_parse_inst_t *)&cmd_showqueue,
19381         (cmdline_parse_inst_t *)&cmd_showportall,
19382         (cmdline_parse_inst_t *)&cmd_showdevice,
19383         (cmdline_parse_inst_t *)&cmd_showcfg,
19384         (cmdline_parse_inst_t *)&cmd_showfwdall,
19385         (cmdline_parse_inst_t *)&cmd_start,
19386         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19387         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19388         (cmdline_parse_inst_t *)&cmd_set_link_up,
19389         (cmdline_parse_inst_t *)&cmd_set_link_down,
19390         (cmdline_parse_inst_t *)&cmd_reset,
19391         (cmdline_parse_inst_t *)&cmd_set_numbers,
19392         (cmdline_parse_inst_t *)&cmd_set_log,
19393         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19394         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19395         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19396         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19397         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19398         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19399         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19400         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19401         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19402         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19403         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19404         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19405         (cmdline_parse_inst_t *)&cmd_set_link_check,
19406         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19407         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19408         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19409         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19410 #ifdef RTE_LIBRTE_PMD_BOND
19411         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19412         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19413         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19414         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19415         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19416         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19417         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19418         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19419         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19420         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19421         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19422 #endif
19423         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19424         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19425         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19426         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19427         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19428         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19429         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19430         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19431         (cmdline_parse_inst_t *)&cmd_csum_set,
19432         (cmdline_parse_inst_t *)&cmd_csum_show,
19433         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19434         (cmdline_parse_inst_t *)&cmd_tso_set,
19435         (cmdline_parse_inst_t *)&cmd_tso_show,
19436         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19437         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19438         (cmdline_parse_inst_t *)&cmd_gro_enable,
19439         (cmdline_parse_inst_t *)&cmd_gro_flush,
19440         (cmdline_parse_inst_t *)&cmd_gro_show,
19441         (cmdline_parse_inst_t *)&cmd_gso_enable,
19442         (cmdline_parse_inst_t *)&cmd_gso_size,
19443         (cmdline_parse_inst_t *)&cmd_gso_show,
19444         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19445         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19446         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19447         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19448         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19449         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19450         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19451         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19452         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19453         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19454         (cmdline_parse_inst_t *)&cmd_config_dcb,
19455         (cmdline_parse_inst_t *)&cmd_read_reg,
19456         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19457         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19458         (cmdline_parse_inst_t *)&cmd_write_reg,
19459         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19460         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19461         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19462         (cmdline_parse_inst_t *)&cmd_stop,
19463         (cmdline_parse_inst_t *)&cmd_mac_addr,
19464         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19465         (cmdline_parse_inst_t *)&cmd_set_qmap,
19466         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19467         (cmdline_parse_inst_t *)&cmd_operate_port,
19468         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19469         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19470         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19471         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19472         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19473         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19474         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19475         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19476         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19477         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19478         (cmdline_parse_inst_t *)&cmd_config_mtu,
19479         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19480         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19481         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19482         (cmdline_parse_inst_t *)&cmd_config_rss,
19483         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19484         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19485         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19486         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19487         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19488         (cmdline_parse_inst_t *)&cmd_showport_reta,
19489         (cmdline_parse_inst_t *)&cmd_showport_macs,
19490         (cmdline_parse_inst_t *)&cmd_config_burst,
19491         (cmdline_parse_inst_t *)&cmd_config_thresh,
19492         (cmdline_parse_inst_t *)&cmd_config_threshold,
19493         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19494         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19495         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19496         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19497         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19498         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19499         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19500         (cmdline_parse_inst_t *)&cmd_global_config,
19501         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19502         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19503         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19504         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19505         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19506         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19507         (cmdline_parse_inst_t *)&cmd_dump,
19508         (cmdline_parse_inst_t *)&cmd_dump_one,
19509         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19510         (cmdline_parse_inst_t *)&cmd_syn_filter,
19511         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19512         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19513         (cmdline_parse_inst_t *)&cmd_flex_filter,
19514         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19515         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19516         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19517         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19518         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19519         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19520         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19521         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19522         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19523         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19524         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19525         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19526         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19527         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19528         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19529         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19530         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19531         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19532         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19533         (cmdline_parse_inst_t *)&cmd_flow,
19534         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19535         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19536         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19537         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19538         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19539         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19540         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19541         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19542         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19543         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19544         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19545         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19546         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19547         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19548         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19549         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19550         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19551         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19552         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19553         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19554         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19555         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19556         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19557         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19558         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19559         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19560         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19561         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19562         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19563         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19564         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19565         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19566         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19567         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19568         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19569         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19570         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19571         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19572         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19573         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19574         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19575         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19576         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19577         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19578         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19579         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19580         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19581         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19582         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19583 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19584         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19585 #endif
19586         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19587         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19588         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19589         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19590         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19591         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19592         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19593         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19594         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19595         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19596         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19597         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19598         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19599         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19600         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19601         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19602         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19603         (cmdline_parse_inst_t *)&cmd_ddp_add,
19604         (cmdline_parse_inst_t *)&cmd_ddp_del,
19605         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19606         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19607         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19608         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19609         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19610         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19611         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19612         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19613         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19614         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19615         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19616         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19617
19618         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19619         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19620         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19621         (cmdline_parse_inst_t *)&cmd_queue_region,
19622         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19623         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19624         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19625         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19626         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19627         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19628         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19629         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19630         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19631         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19632         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19633         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19634         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19635         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19636         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19637         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19638         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19639         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19640         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19641         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19642         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19643         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19644         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19645         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19646         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19647         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19648         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19649         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19650         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19651         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19652         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19653         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19654         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19655         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19656         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19657 #ifdef RTE_LIBRTE_BPF
19658         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19659         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19660 #endif
19661         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19662         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19663         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19664         (cmdline_parse_inst_t *)&cmd_set_raw,
19665         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19666         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19667         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19668         NULL,
19669 };
19670
19671 /* read cmdline commands from file */
19672 void
19673 cmdline_read_from_file(const char *filename)
19674 {
19675         struct cmdline *cl;
19676
19677         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19678         if (cl == NULL) {
19679                 printf("Failed to create file based cmdline context: %s\n",
19680                        filename);
19681                 return;
19682         }
19683
19684         cmdline_interact(cl);
19685         cmdline_quit(cl);
19686
19687         cmdline_free(cl);
19688
19689         printf("Read CLI commands from %s\n", filename);
19690 }
19691
19692 /* prompt function, called from main on MASTER lcore */
19693 void
19694 prompt(void)
19695 {
19696         /* initialize non-constant commands */
19697         cmd_set_fwd_mode_init();
19698         cmd_set_fwd_retry_mode_init();
19699
19700         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19701         if (testpmd_cl == NULL)
19702                 return;
19703         cmdline_interact(testpmd_cl);
19704         cmdline_stdin_exit(testpmd_cl);
19705 }
19706
19707 void
19708 prompt_exit(void)
19709 {
19710         if (testpmd_cl != NULL)
19711                 cmdline_quit(testpmd_cl);
19712 }
19713
19714 static void
19715 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19716 {
19717         if (id == (portid_t)RTE_PORT_ALL) {
19718                 portid_t pid;
19719
19720                 RTE_ETH_FOREACH_DEV(pid) {
19721                         /* check if need_reconfig has been set to 1 */
19722                         if (ports[pid].need_reconfig == 0)
19723                                 ports[pid].need_reconfig = dev;
19724                         /* check if need_reconfig_queues has been set to 1 */
19725                         if (ports[pid].need_reconfig_queues == 0)
19726                                 ports[pid].need_reconfig_queues = queue;
19727                 }
19728         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19729                 /* check if need_reconfig has been set to 1 */
19730                 if (ports[id].need_reconfig == 0)
19731                         ports[id].need_reconfig = dev;
19732                 /* check if need_reconfig_queues has been set to 1 */
19733                 if (ports[id].need_reconfig_queues == 0)
19734                         ports[id].need_reconfig_queues = queue;
19735         }
19736 }